Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
January 2011
- 5 participants
- 66 discussions
r2011 - in trunk/nuiton-validator/src/main: java/org/nuiton/validator java/org/nuiton/validator/xwork2 resources resources/META-INF resources/META-INF/services
by tchemit@users.nuiton.org 17 Jan '11
by tchemit@users.nuiton.org 17 Jan '11
17 Jan '11
Author: tchemit
Date: 2011-01-17 19:00:50 +0100 (Mon, 17 Jan 2011)
New Revision: 2011
Url: http://nuiton.org/repositories/revision/nuiton-utils/2011
Log:
new validation api
Added:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/AbstractNuitonValidatorProvider.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorFactory.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorModel.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorProvider.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorScope.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/legacy/
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidatorProvider.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ScopeValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ValidatorUtil.java
trunk/nuiton-validator/src/main/resources/META-INF/
trunk/nuiton-validator/src/main/resources/META-INF/services/
trunk/nuiton-validator/src/main/resources/META-INF/services/org.nuiton.validator.NuitonValidatorProvider
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/AbstractNuitonValidatorProvider.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/AbstractNuitonValidatorProvider.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/AbstractNuitonValidatorProvider.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,120 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Abstract provider of validator.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public abstract class AbstractNuitonValidatorProvider implements NuitonValidatorProvider {
+
+ protected Map<ModelEntry<?>, NuitonValidatorModel<?>> models;
+
+ protected final String name;
+
+ public AbstractNuitonValidatorProvider(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public <O> NuitonValidatorModel<O> getModel(Class<O> type, String context, NuitonValidatorScope... scopes) {
+ ModelEntry<O> key = ModelEntry.createModelEntry(type, context, scopes);
+
+ @SuppressWarnings({"unchecked"})
+ NuitonValidatorModel<O> model = (NuitonValidatorModel<O>) getModels().get(key);
+
+ if (model == null) {
+ model = newModel(type, context, scopes);
+ }
+ return model;
+ }
+
+ protected Map<ModelEntry<?>, NuitonValidatorModel<?>> getModels() {
+ if (models == null) {
+ models = new HashMap<ModelEntry<?>, NuitonValidatorModel<?>>();
+ }
+ return models;
+ }
+
+ protected static class ModelEntry<O> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final Class<O> type;
+
+ protected final String context;
+
+ protected final NuitonValidatorScope[] scopes;
+
+ public static <O> ModelEntry<O> createModelEntry(Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes) {
+ return new ModelEntry<O>(type, context, scopes);
+ }
+
+ protected ModelEntry(Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes) {
+ this.type = type;
+ this.context = context;
+ this.scopes = scopes == null ? NuitonValidatorScope.values() : scopes;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ModelEntry)) return false;
+
+ ModelEntry<?> that = (ModelEntry<?>) o;
+
+ if (context != null ? !context.equals(that.context) : that.context != null)
+ return false;
+ if (!Arrays.equals(scopes, that.scopes)) return false;
+ return type.equals(that.type);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type.hashCode();
+ result = 31 * result + (context != null ? context.hashCode() : 0);
+ result = 31 * result + Arrays.hashCode(scopes);
+ return result;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/AbstractNuitonValidatorProvider.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidator.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+/**
+ * Contract of a validator.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public interface NuitonValidator<O> {
+
+ /**
+ * Obtain the model of a validator.
+ *
+ * @return the model of this validator
+ * @see NuitonValidatorModel
+ */
+ NuitonValidatorModel<O> getModel();
+
+ /**
+ * Validates the given object and returns the result of validation.
+ *
+ * @param object the object to validate
+ * @return the result of validation for the given object
+ * @throws NullPointerException if object is {@code null}.
+ */
+ NuitonValidatorResult validate(O object) throws NullPointerException;
+
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorFactory.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorFactory.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorFactory.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,171 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.TreeMap;
+
+/**
+ * Factory to obtain new validators.
+ * <p/>
+ * The factory contains a cache of {@link NuitonValidatorModel}.
+ * <p/>
+ * To obtain a new validator with no context, use this code :
+ * <pre>
+ * NuitonValidator<O> validator = NuitonValidatorFactory.newValidator(O.class);
+ * </pre>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class NuitonValidatorFactory {
+
+ /** Logger. */
+ static private final Log log =
+ LogFactory.getLog(NuitonValidatorFactory.class);
+
+ protected static String defaultProviderName;
+
+ protected static Map<String, NuitonValidatorProvider> providers;
+
+ public static <O> NuitonValidator<O> newValidator(Class<O> type,
+ NuitonValidatorScope... scopes) {
+ NuitonValidator<O> result = newValidator(type, null, scopes);
+ return result;
+ }
+
+ public static <O> NuitonValidator<O> newValidator(Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes) {
+
+ String providerName = getDefaultProviderName();
+
+ NuitonValidator<O> result = newValidator(providerName,
+ type,
+ context,
+ scopes);
+ return result;
+ }
+
+ public static <O> NuitonValidator<O> newValidator(String providerName,
+ Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes) throws NullPointerException {
+
+ if (type == null) {
+ throw new NullPointerException(
+ "type parameter can not be null.");
+ }
+
+ // get the provider
+ NuitonValidatorProvider provider = getProvider(providerName);
+
+
+ // obtain validator model form the provider
+ NuitonValidatorModel<O> model =
+ provider.getModel(type, context, scopes);
+
+ // obtain validator from the the provider
+ NuitonValidator<O> result = provider.newValidator(model);
+ return result;
+ }
+
+ public static Map<String, NuitonValidatorProvider> getProviders() {
+ if (providers == null) {
+ providers = new TreeMap<String, NuitonValidatorProvider>();
+ ServiceLoader<NuitonValidatorProvider> serviceLoader =
+ ServiceLoader.load(NuitonValidatorProvider.class);
+
+ for (NuitonValidatorProvider provider : serviceLoader) {
+ if (log.isInfoEnabled()) {
+ log.info("obtain validator provider " + provider.getName());
+ }
+ providers.put(provider.getName(), provider);
+ }
+ }
+ return providers;
+ }
+
+ public static String getDefaultProviderName() throws IllegalStateException {
+
+ if (defaultProviderName == null) {
+
+ // takes the first provider from existing provider
+
+ Map<String, NuitonValidatorProvider> providers = getProviders();
+ if (providers.isEmpty()) {
+ throw new IllegalStateException(
+ "Could not find any provider of validator.");
+ }
+ defaultProviderName = providers.keySet().iterator().next();
+
+ if (log.isInfoEnabled()) {
+ log.info("Set the default provider name to " + defaultProviderName);
+ }
+ }
+
+ return defaultProviderName;
+ }
+
+ public static void setDefaultProviderName(String defaultProviderName) throws IllegalArgumentException, NullPointerException {
+
+ if (defaultProviderName == null) {
+ throw new NullPointerException("defaultProviderName can not be null.");
+ }
+ // check provider exists
+ getProvider(defaultProviderName);
+
+ NuitonValidatorFactory.defaultProviderName = defaultProviderName;
+ }
+
+ protected static NuitonValidatorProvider getProvider(String providerName) throws IllegalArgumentException, NullPointerException {
+
+ if (providerName == null) {
+
+ // take the default validator provider name
+ throw new NullPointerException(
+ "providerName parameter can not be null.");
+ }
+
+ NuitonValidatorProvider provider = getProviders().get(providerName);
+ if (provider == null) {
+ throw new IllegalArgumentException(
+ "Could not find provider named '" +
+ defaultProviderName + "', existing providers are : " +
+ getProviders().keySet());
+ }
+ return provider;
+ }
+
+ protected NuitonValidatorFactory() {
+ // avoid instanciation of this factory
+ }
+
+
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorModel.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorModel.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorModel.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,87 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Represents the model of a {@link NuitonValidator}.
+ * <p/>
+ * This model describing properties of a validator :
+ * <ul>
+ * <li>{@link #type} : the type of object which can be validated by the validator</li>
+ * <li>{@link #context} : the context of validation, if no context is required then the context is {@code null}.
+ * <li>{@link #scopes} : the scopes of validation (see {@link NuitonValidatorScope})</li>
+ * <li>{@link #fields} : the fields that can be validated by the validator</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class NuitonValidatorModel<O> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Type of object to validate */
+ protected Class<O> type;
+
+ /** Context of validation (can be {@code null}, for no context). */
+ protected String context;
+
+ /** Set of scopes that can be validated for the type and context */
+ protected Set<NuitonValidatorScope> scopes;
+
+ /** Set of fields that can be validated for the type and context */
+ protected Map<NuitonValidatorScope, String[]> fields;
+
+ public NuitonValidatorModel(Class<O> type,
+ String context,
+ Set<NuitonValidatorScope> scopes,
+ Map<NuitonValidatorScope, String[]> fields) {
+ this.type = type;
+ this.context = context;
+ this.scopes = Collections.unmodifiableSet(scopes);
+ this.fields = Collections.unmodifiableMap(fields);
+ }
+
+ public Class<O> getType() {
+ return type;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ public Set<NuitonValidatorScope> getScopes() {
+ return scopes;
+ }
+
+ public Map<NuitonValidatorScope, String[]> getFields() {
+ return fields;
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorProvider.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorProvider.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorProvider.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+import java.util.ServiceLoader;
+
+/**
+ * Provider of {@link NuitonValidator}.
+ * <p/>
+ * An implementation of a such class provides a implementation of a validator models
+ * and also of validator.
+ * <p/>
+ * <b>Note:</b> Providers are used in the {@link NuitonValidatorFactory} and
+ * should be registered via the {@link ServiceLoader} api.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @see NuitonValidatorModel
+ * @see NuitonValidator
+ * @see ServiceLoader
+ * @since 2.0
+ */
+public interface NuitonValidatorProvider {
+
+ String getName();
+
+ <O> NuitonValidatorModel<O> getModel(Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes);
+
+ <O> NuitonValidatorModel<O> newModel(Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes);
+
+ <O> NuitonValidator<O> newValidator(NuitonValidatorModel<O> model);
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorProvider.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,222 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Default implementation of the {@link NuitonValidatorResult} contract.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class NuitonValidatorResult {
+
+ public static class FieldMap<V> extends TreeMap<String, V> {
+
+ private static final long serialVersionUID = 1L;
+ }
+
+ protected EnumMap<NuitonValidatorScope, FieldMap<List<String>>> messages;
+
+ protected Map<String, FieldMap<Object>> tagValues;
+
+ public boolean isValid() {
+ return !hasFatalMessages() && !hasErrorMessagess();
+ }
+
+ public boolean hasMessagesForScope(NuitonValidatorScope scope) {
+ boolean result = false;
+ if (messages != null) {
+ result = messages.containsKey(scope);
+ }
+ return result;
+ }
+
+ public boolean hasMessagesForScope(String field, NuitonValidatorScope scope) {
+ boolean result = false;
+ if (messages != null) {
+ result = messages.containsKey(scope);
+
+ if (result) {
+ FieldMap<List<String>> fieldMap = messages.get(scope);
+ result = fieldMap != null && fieldMap.containsKey(field);
+ }
+ }
+ return result;
+ }
+
+ public boolean hasFatalMessages() {
+ boolean result = hasMessagesForScope(NuitonValidatorScope.FATAL);
+ return result;
+ }
+
+ public boolean hasErrorMessagess() {
+ boolean result = hasMessagesForScope(NuitonValidatorScope.ERROR);
+ return result;
+ }
+
+ public boolean hasInfoMessages() {
+ boolean result = hasMessagesForScope(NuitonValidatorScope.INFO);
+ return result;
+ }
+
+ public boolean hasWarningMessages() {
+ boolean result = hasMessagesForScope(NuitonValidatorScope.WARNING);
+ return result;
+ }
+
+ public void addMessagesForScope(NuitonValidatorScope scope, Map<String, List<String>> newMessages) {
+ if (messages == null) {
+ messages = new EnumMap<NuitonValidatorScope, FieldMap<List<String>>>(NuitonValidatorScope.class);
+ }
+
+ FieldMap<List<String>> fieldMap = messages.get(scope);
+
+ if (fieldMap == null) {
+ fieldMap = new FieldMap<List<String>>();
+ messages.put(scope, fieldMap);
+ }
+
+ for (Map.Entry<String, List<String>> entry : newMessages.entrySet()) {
+ String fieldName = entry.getKey();
+ List<String> messages = entry.getValue();
+ List<String> oldMessages = fieldMap.get(fieldName);
+ if (oldMessages == null) {
+ oldMessages = messages;
+ fieldMap.put(fieldName, oldMessages);
+ } else {
+ oldMessages.addAll(messages);
+ }
+ }
+ }
+
+ public List<String> getMessagesForScope(NuitonValidatorScope scope) {
+
+ List<String> result = new ArrayList<String>();
+ if (messages != null) {
+ FieldMap<List<String>> fieldMap = messages.get(scope);
+ for (List<String> messages : fieldMap.values()) {
+ result.addAll(messages);
+ }
+ }
+ return result;
+ }
+
+ public List<String> getMessagesForScope(String field,
+ NuitonValidatorScope scope) {
+
+ List<String> result = null;
+ if (messages != null) {
+ FieldMap<List<String>> fieldMap = messages.get(scope);
+ result = fieldMap.get(field);
+ }
+ if (result == null) {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
+
+ public List<String> getFatalMessages(String field) {
+ List<String> result =
+ getMessagesForScope(field, NuitonValidatorScope.FATAL);
+ return result;
+ }
+
+ public List<String> getErrorMessages(String field) {
+ List<String> result =
+ getMessagesForScope(field, NuitonValidatorScope.ERROR);
+ return result;
+ }
+
+ public List<String> getInfoMessages(String field) {
+ List<String> result =
+ getMessagesForScope(field, NuitonValidatorScope.INFO);
+ return result;
+ }
+
+ public List<String> getWarningMessages(String field) {
+ List<String> result =
+ getMessagesForScope(field, NuitonValidatorScope.WARNING);
+ return result;
+ }
+
+ public Map<String, Object> getTagValues(String field) {
+ Map<String, Object> result = null;
+ if (tagValues != null) {
+ result = tagValues.get(field);
+ }
+ if (result == null) {
+ result = Collections.emptyMap();
+ }
+ return result;
+ }
+
+ public List<String> getFieldsForScope(NuitonValidatorScope scope) {
+
+ List<String> result = null;
+ if (messages != null) {
+ FieldMap<List<String>> fieldMap = messages.get(scope);
+ result = new ArrayList<String>(fieldMap.keySet());
+ }
+ if (result == null) {
+ result = Collections.emptyList();
+ }
+ return result;
+ }
+
+ public List<String> getFieldsForFatal() {
+ List<String> result = getFieldsForScope(NuitonValidatorScope.FATAL);
+ return result;
+ }
+
+ public List<String> getFieldsForError() {
+ List<String> result = getFieldsForScope(NuitonValidatorScope.ERROR);
+ return result;
+ }
+
+ public List<String> getFieldsForInfo() {
+ List<String> result = getFieldsForScope(NuitonValidatorScope.INFO);
+ return result;
+ }
+
+ public List<String> getFieldsForWarning() {
+ List<String> result = getFieldsForScope(NuitonValidatorScope.WARNING);
+ return result;
+ }
+
+ protected EnumMap<NuitonValidatorScope, FieldMap<List<String>>> getMessages() {
+ return messages;
+ }
+
+ protected Map<String, FieldMap<Object>> getTagValues() {
+ return tagValues;
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorScope.java (from rev 2010, trunk/nuiton-validator/src/main/java/org/nuiton/validator/BeanValidatorScope.java)
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorScope.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/NuitonValidatorScope.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,79 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator;
+
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * The differents levels of messages in validation process.
+ * <p/>
+ * The order of the enum defines the severity of validation.
+ * <p/>
+ * Always begin with fatal, then error, then if no error found, try warning, then info...
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public enum NuitonValidatorScope {
+
+ /**
+ * the fatal error scope level.
+ * <p/>
+ * When a message of a such scope is found on a validator, then the
+ * validator is invalid and modified.
+ */
+ FATAL(n_("validator.scope.fatal.label")),
+ /**
+ * the error scope level.
+ * <p/>
+ * When a message of a such scope is found on a validator, then the
+ * validator is invalid and modified.
+ */
+ ERROR(n_("validator.scope.error.label")),
+ /**
+ * the warning scope level.
+ * <p/>
+ * When a message of a such scope is found on a validator, then the
+ * validator is still valid but modified.
+ */
+ WARNING(n_("validator.scope.warning.label")),
+ /**
+ * the information scope level.
+ * <p/>
+ * When a message of a sucg scope is found on a validator, then the
+ * validator is still valid and not modified.
+ */
+ INFO(n_("validator.scope.info.label"));
+
+ private final String label;
+
+ NuitonValidatorScope(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+}
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidator.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,112 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2;
+
+import org.nuiton.validator.NuitonValidator;
+import org.nuiton.validator.NuitonValidatorModel;
+import org.nuiton.validator.NuitonValidatorResult;
+import org.nuiton.validator.NuitonValidatorScope;
+
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Implementation of {@link NuitonValidator} using {@code XWorks2} validators.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class XWork2NuitonValidator<O> implements NuitonValidator<O> {
+
+ protected NuitonValidatorModel<O> model;
+
+ /** xworks scope validators * */
+ protected Map<NuitonValidatorScope, XWork2ScopeValidator<O>> validators;
+
+ public XWork2NuitonValidator(NuitonValidatorModel<O> model) {
+
+ this.model = model;
+
+ // init validators
+ validators = new EnumMap<NuitonValidatorScope, XWork2ScopeValidator<O>>(NuitonValidatorScope.class);
+
+ Class<O> type = model.getType();
+ String context = model.getContext();
+
+ Map<NuitonValidatorScope, String[]> fieldsMap = model.getFields();
+
+ for (Map.Entry<NuitonValidatorScope, String[]> entry : fieldsMap.entrySet()) {
+
+ NuitonValidatorScope scope = entry.getKey();
+
+ String scopeContext =
+ XWork2ValidatorUtil.getContextForScope(
+ context,
+ scope
+ );
+
+ Set<String> fields = new HashSet<String>(
+ Arrays.asList(entry.getValue()));
+
+ XWork2ScopeValidator<O> newValidator =
+ XWork2ValidatorUtil.newXWorkScopeValidator(
+ type,
+ scopeContext,
+ fields
+ );
+
+ validators.put(scope, newValidator);
+ }
+ }
+
+ @Override
+ public NuitonValidatorModel<O> getModel() {
+ return model;
+ }
+
+ @Override
+ public NuitonValidatorResult validate(O object) throws NullPointerException {
+
+ if (object == null) {
+ throw new NullPointerException("object parameter can not be null.");
+ }
+
+ NuitonValidatorResult result = new NuitonValidatorResult();
+
+ for (NuitonValidatorScope scope : validators.keySet()) {
+
+ XWork2ScopeValidator<O> validator = validators.get(scope);
+
+ Map<String, List<String>> newMessages = validator.validate(object);
+
+ result.addMessagesForScope(scope, newMessages);
+ }
+ return result;
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidatorProvider.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidatorProvider.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidatorProvider.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,76 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2;
+
+import org.nuiton.validator.AbstractNuitonValidatorProvider;
+import org.nuiton.validator.NuitonValidator;
+import org.nuiton.validator.NuitonValidatorModel;
+import org.nuiton.validator.NuitonValidatorScope;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Provider of validator for the xworks nuiton validator.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class XWork2NuitonValidatorProvider extends AbstractNuitonValidatorProvider {
+
+ public static final String PROVIDER_NAME = "xwork2";
+
+ public XWork2NuitonValidatorProvider() {
+ super(PROVIDER_NAME);
+ }
+
+ @Override
+ public <O> NuitonValidatorModel<O> newModel(Class<O> type,
+ String context,
+ NuitonValidatorScope... scopes) {
+
+ if (scopes.length == 0) {
+ // use all scopes
+ scopes = NuitonValidatorScope.values();
+ }
+
+ Map<NuitonValidatorScope, String[]> fields =
+ XWork2ValidatorUtil.detectFields(type, context, scopes);
+
+ Set<NuitonValidatorScope> scopeSet =
+ EnumSet.noneOf(NuitonValidatorScope.class);
+ scopeSet.addAll(Arrays.asList(scopes));
+
+ return new NuitonValidatorModel<O>(type, context, scopeSet, fields);
+ }
+
+ @Override
+ public <O> NuitonValidator<O> newValidator(NuitonValidatorModel<O> model) {
+ return new XWork2NuitonValidator<O>(model);
+ }
+
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2NuitonValidatorProvider.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ScopeValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ScopeValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ScopeValidator.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,225 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ValidationAwareSupport;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.validator.ActionValidatorManager;
+import com.opensymphony.xwork2.validator.DelegatingValidatorContext;
+import com.opensymphony.xwork2.validator.ValidationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A customized validator for a given bean.
+ * <p/>
+ * Use the method {@link #validate(Object)} to obtain the messages detected by
+ * the validator for the given bean.
+ *
+ * @param <O> type of the bean to validate.
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class XWork2ScopeValidator<O> {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(XWork2ScopeValidator.class);
+
+ protected final static Map<String, List<String>> EMPTY_RESULT =
+ Collections.unmodifiableMap(new HashMap<String, List<String>>());
+
+ /** the type of bean to validate */
+ protected final Class<O> type;
+
+ /** the validation named context (can be null) */
+ protected String context;
+
+ /** the list of field names detected for this validator */
+ protected Set<String> fieldNames;
+
+ // --
+ // XWorks fields
+ // --
+
+ protected ValidationAwareSupport validationSupport;
+
+ protected DelegatingValidatorContext validationContext;
+
+ protected ActionValidatorManager validator;
+
+ protected ValueStack vs;
+
+ protected XWork2ScopeValidator(Class<O> type,
+ String context,
+ Set<String> fieldNames,
+ ValueStack vs) {
+
+ this.type = type;
+ this.context = context;
+ this.fieldNames = fieldNames;
+
+ validationSupport = new ValidationAwareSupport();
+ validationContext = new DelegatingValidatorContext(validationSupport);
+
+ if (vs == null) {
+
+ // create a standalone value stack
+ vs = XWork2ValidatorUtil.createValuestack();
+ if (log.isDebugEnabled()) {
+ log.debug("create a standalone value stack " + vs);
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("use given value stack " + vs);
+ }
+ }
+
+ this.vs = vs;
+
+ validator = XWork2ValidatorUtil.newValidationManager(vs);
+ }
+
+ public Class<O> getType() {
+ return type;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ public Set<String> getFieldNames() {
+ return fieldNames;
+ }
+
+ public ActionValidatorManager getValidator() {
+ return validator;
+ }
+
+ /**
+ * Test if the validator contains the field given his name
+ *
+ * @param fieldName the name of the searched field
+ * @return <code>true</code> if validator contaisn this field,
+ * <code>false</code> otherwise
+ */
+ public boolean containsField(String fieldName) {
+ return fieldNames.contains(fieldName);
+ }
+
+ /**
+ * Valide le bean donné et retourne les messages produits.
+ *
+ * @param bean le bean a valider (il doit etre non null)
+ * @return le dictionnaire des messages produits par la validation indexées
+ * par le nom du champs du bean impacté.
+ */
+ public Map<String, List<String>> validate(O bean) {
+
+ if (bean == null) {
+ throw new NullPointerException(
+ "bean parameter can not be null in method validate");
+ }
+
+ Map<String, List<String>> result = EMPTY_RESULT;
+
+
+ if (fieldNames.isEmpty()) {
+ return result;
+ }
+
+ // on lance la validation uniquement si des champs sont a valider
+ try {
+
+ //TC - 20081024 : since context is in a ThreadLocal variable,
+ // we must do the check
+ if (ActionContext.getContext() == null) {
+ ActionContext.setContext(new ActionContext(vs.getContext()));
+ }
+
+ validator.validate(bean, context, validationContext);
+
+ if (log.isTraceEnabled()) {
+ log.trace("Action errors: " +
+ validationContext.getActionErrors());
+ log.trace("Action messages: " +
+ validationContext.getActionMessages());
+ log.trace("Field errors: " +
+ validationContext.getFieldErrors());
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(this + " : " +
+ validationContext.getFieldErrors());
+ }
+
+ // retreave errors by field
+ if (validationContext.hasFieldErrors()) {
+ Map<?, ?> messages = validationContext.getFieldErrors();
+ result = new HashMap<String, List<String>>(messages.size());
+ for (Object fieldName : messages.keySet()) {
+ Collection<?> c =
+ (Collection<?>) messages.get(fieldName);
+ List<String> mm = new ArrayList<String>(c.size());
+ for (Object message : c) {
+ // tchemit 2010-08-28 : trim the incoming message
+ // (I18n will not translate it otherwise)
+ String messageStr = message == null ? "" : message + "";
+ mm.add(messageStr.trim());
+ }
+ result.put(fieldName + "", mm);
+ }
+ }
+
+ } catch (ValidationException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Error during validation on " + type +
+ " for reason : " + eee.getMessage(), eee);
+ }
+
+ } finally {
+
+ // on nettoye toujours le validateur apres operation
+ validationSupport.clearErrorsAndMessages();
+ }
+
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<beanClass:" + type +
+ ", contextName:" + context + ">";
+ }
+
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ScopeValidator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ValidatorUtil.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ValidatorUtil.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ValidatorUtil.java 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1,218 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import com.opensymphony.xwork2.validator.ActionValidatorManager;
+import com.opensymphony.xwork2.validator.FieldValidator;
+import com.opensymphony.xwork2.validator.Validator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.validator.NuitonValidatorScope;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Usefull methods to works with work2 validator api.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class XWork2ValidatorUtil {
+
+ /** Logger. */
+ static private final Log log = LogFactory.getLog(XWork2ValidatorUtil.class);
+
+ /**
+ * a shared value stack to allow external operations on it (for example add
+ * some datas in stack to be usedby validators
+ */
+ static private ValueStack sharedValueStack;
+
+ public static ValueStack getSharedValueStack() {
+ if (sharedValueStack == null) {
+
+ // init context
+ sharedValueStack = createValuestack();
+ if (log.isDebugEnabled()) {
+ log.debug("init shared value stack " + sharedValueStack);
+ }
+ }
+ return sharedValueStack;
+ }
+
+ public static ValueStack createValuestack() {
+
+ ConfigurationManager confManager = new ConfigurationManager();
+ Configuration conf = confManager.getConfiguration();
+ Container container = conf.getContainer();
+ ValueStackFactory stackFactory =
+ container.getInstance(ValueStackFactory.class);
+ ValueStack vs = stackFactory.createValueStack();
+ return vs;
+ }
+
+ public static <O> XWork2ScopeValidator<O> newXWorkScopeValidator(Class<O> beanClass,
+ String contextName,
+ Set<String> fields
+ ) {
+ return newXWorkScopeValidator(beanClass,
+ contextName,
+ fields,
+ getSharedValueStack()
+ );
+ }
+
+ public static <O> XWork2ScopeValidator<O> newXWorkScopeValidator(Class<O> beanClass,
+ String contextName,
+ Set<String> fields,
+ ValueStack vs) {
+
+ return new XWork2ScopeValidator<O>(beanClass,
+ contextName,
+ fields,
+ vs
+ );
+ }
+
+
+ public static String getContextForScope(String context,
+ NuitonValidatorScope scope) {
+ return (context == null ? "" : context + "-") +
+ scope.name().toLowerCase();
+ }
+
+ protected static ActionValidatorManager newValidationManager(ValueStack vs) {
+
+ if (vs == null) {
+ vs = createValuestack();
+
+ if (log.isDebugEnabled()) {
+ log.debug("create a standalone value stack " + vs);
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("use given value stack " + vs);
+ }
+ }
+
+ ActionContext context = new ActionContext(vs.getContext());
+
+ // must set the action context otherwise can't obtain after validators
+ // with the method validator.getValidators(XXX)
+ // Later in the code, we could not having reference to the ValueStack
+ // before using a validator... Must be cleaned...
+ ActionContext.setContext(context);
+
+ // init validator
+ Container container = context.getContainer();
+ ActionValidatorManager validatorManager =
+ container.getInstance(ActionValidatorManager.class,
+ "no-annotations");
+
+ return validatorManager;
+ }
+
+ public static <O> Map<NuitonValidatorScope, String[]> detectFields(Class<O> type,
+ String context,
+ NuitonValidatorScope[] scopeUniverse) {
+
+
+ ActionValidatorManager validatorManager = newValidationManager(null);
+
+ Map<NuitonValidatorScope, String[]> fields = new TreeMap<NuitonValidatorScope, String[]>();
+
+ for (NuitonValidatorScope scope : scopeUniverse) {
+
+ Set<String> fieldNames = detectFieldsForScope(validatorManager, type, scope, context, false);
+
+ if (log.isDebugEnabled()) {
+ log.debug("detected validator fields for scope " + scope + ":" + context +
+ " : " + fieldNames);
+ }
+
+ if (!fieldNames.isEmpty()) {
+
+ // fields detected in this validator, keep it
+
+ fields.put(scope, fieldNames.toArray(new String[fieldNames.size()]));
+ }
+ }
+
+ return fields;
+
+ }
+
+ protected static Set<String> detectFieldsForScope(ActionValidatorManager validator,
+ Class<?> type,
+ NuitonValidatorScope scope,
+ String context,
+ boolean includeDefaultContext) {
+
+
+ String scopeContext = getContextForScope(context, scope);
+
+
+ Set<String> fields = new HashSet<String>();
+
+ int skip = 0;
+ if (scopeContext != null && !includeDefaultContext) {
+ // count the number of validator to skip
+ for (Validator<?> v : validator.getValidators(type, null)) {
+ // we only work on FieldValidator at the moment
+ if (v instanceof FieldValidator) {
+ skip++;
+ }
+ }
+ }
+
+ for (Validator<?> v : validator.getValidators(type, scopeContext)) {
+ // we only work on FieldValidator at the moment
+ if (v instanceof FieldValidator) {
+ if (skip > 0) {
+ skip--;
+ continue;
+ }
+ FieldValidator fieldValidator = (FieldValidator) v;
+ if (log.isDebugEnabled()) {
+ log.debug("context " + context + " - field " +
+ fieldValidator.getFieldName());
+ }
+ String fName = fieldValidator.getFieldName();
+ fields.add(fName);
+ }
+ }
+
+ return fields;
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/XWork2ValidatorUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-validator/src/main/resources/META-INF/services/org.nuiton.validator.NuitonValidatorProvider
===================================================================
--- trunk/nuiton-validator/src/main/resources/META-INF/services/org.nuiton.validator.NuitonValidatorProvider (rev 0)
+++ trunk/nuiton-validator/src/main/resources/META-INF/services/org.nuiton.validator.NuitonValidatorProvider 2011-01-17 18:00:50 UTC (rev 2011)
@@ -0,0 +1 @@
+org.nuiton.validator.xwork2.XWork2NuitonValidatorProvider
\ No newline at end of file
Property changes on: trunk/nuiton-validator/src/main/resources/META-INF/services/org.nuiton.validator.NuitonValidatorProvider
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r2010 - in trunk: . nuiton-utils nuiton-utils/src/main/java/org/nuiton/util nuiton-utils/src/main/java/org/nuiton/util/rmi
by athimel@users.nuiton.org 12 Jan '11
by athimel@users.nuiton.org 12 Jan '11
12 Jan '11
Author: athimel
Date: 2011-01-12 15:31:01 +0100 (Wed, 12 Jan 2011)
New Revision: 2010
Url: http://nuiton.org/repositories/revision/nuiton-utils/2010
Log:
[FEATURE] Add classes to easily export and reuse services to a RMI registry
Added:
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutor.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutorImpl.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/package-info.java
Modified:
trunk/
trunk/nuiton-utils/changelog.txt
Property changes on: trunk
___________________________________________________________________
Modified: svn:ignore
- target
velocity.log
maven.log
.eclipse
.classpath
*.iml
*.ipr
*.iws
.settings
.project
+ target
velocity.log
maven.log
.eclipse
.classpath
*.iml
*.ipr
*.iws
.settings
.project
testdir
Modified: trunk/nuiton-utils/changelog.txt
===================================================================
--- trunk/nuiton-utils/changelog.txt 2011-01-07 13:05:05 UTC (rev 2009)
+++ trunk/nuiton-utils/changelog.txt 2011-01-12 14:31:01 UTC (rev 2010)
@@ -1,13 +1,17 @@
-1.1.3 xxx 201001xx
+ver 2.0 xxx 201101xx
+
+ * [FEATURE] Add classes to easily export and reuse services to a RMI registry
+
+ver 1.1.3 xxx 201001xx
* Use display-name from web.xml file as server name
-1.1.2 desbois 20091223
+ver 1.1.2 desbois 20091223
* Add generic war launcher (winstone & jetty based)
* Add new uncompress method with exclusion filters
* [FEATURE] Force application configuration properties to be written sorted
* [FEATURE] Add sed and grep method on FileUtil
-1.1.1 chemit 20090903
+ver 1.1.1 chemit 20090903
* [FEATURE] #39 add a filterVersions method in VersionUtil
Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutor.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutor.java (rev 0)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutor.java 2011-01-12 14:31:01 UTC (rev 2010)
@@ -0,0 +1,50 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * This class will act as an InvocationHandler except that it is distributed.
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public interface RemoteMethodExecutor extends Remote {
+
+ /**
+ * Acts like an InvocationHandler.
+ *
+ * @param methodName name of the method to invoke
+ * @param parametersType parameters type to reliably identify the method
+ * @param args method arguments to process the effective call
+ * @return the result of the delegate method
+ * @throws RemoteException for any error. Business exceptions will be
+ * wrapped.
+ */
+ Object execute(String methodName, Class<?>[] parametersType, Object[] args)
+ throws RemoteException;
+
+}
Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutor.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutorImpl.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutorImpl.java (rev 0)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutorImpl.java 2011-01-12 14:31:01 UTC (rev 2010)
@@ -0,0 +1,86 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+
+/**
+ * RMI implementation of an invocation handler. This object will be exported to
+ * a RMI registry and will delegate method calls to some business service. The
+ * service is provided in the constructor.
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class RemoteMethodExecutorImpl<T> implements RemoteMethodExecutor {
+
+ /**
+ * The target service on which calls will be made
+ */
+ protected T service;
+
+ /**
+ * This is the only available constructor. It is mandatory to specify a
+ * target service on which call will be
+ * delegated.
+ *
+ * @param service the mandatory service which calls will be delegated on
+ */
+ public RemoteMethodExecutorImpl(T service) {
+ if (service == null) {
+ throw new NullPointerException("Service cannot be null");
+ }
+ this.service = service;
+ }
+
+ @Override
+ public Object execute(
+ String methodName, Class<?>[] parametersType, Object[] args)
+ throws RemoteException {
+
+ Object result;
+ try {
+
+ // Get the method on the target service then invoke it
+ Method method = service.getClass().getMethod(
+ methodName, parametersType);
+ result = method.invoke(service, args);
+
+ } catch (InvocationTargetException ite) {
+ // This is the normal behaviour if a business exception is thrown
+ Throwable targetException = ite.getTargetException();
+ throw new RemoteException(
+ "Business exception occurred", targetException);
+ } catch (NoSuchMethodException nsme) {
+ throw new RemoteException("Delegate method not found", nsme);
+ } catch (IllegalAccessException iae) {
+ throw new RemoteException("Delegate method not accessible", iae);
+ }
+
+ return result;
+ }
+
+}
Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteMethodExecutorImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java (rev 0)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java 2011-01-12 14:31:01 UTC (rev 2010)
@@ -0,0 +1,132 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.rmi.ServerException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+/**
+ * Factory to create RMI proxies to some given services.
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class RemoteProxyFactory {
+
+ private final static Log log = LogFactory.getLog(RemoteProxyFactory.class);
+
+ // TODO AThimel 12/01/2011 This settings has to be externalized
+ protected final static int PORT = 12345;
+ protected final static String REGISTRY_IP = "10.1.1.85";
+
+ /**
+ * Create a RMI proxy on the wanted service interface. The default RMI name
+ * will be used to find this service in the Registry.
+ *
+ * @param serviceInterface The class of the service proxy to create
+ * @param <T> some interface class
+ * @return A newly created proxy which interface is <T>
+ * @throws RemoteException in case the registry is not reachable
+ * @throws NotBoundException if the default RMI name cannot be found in the
+ * registry
+ */
+ public static <T> T createProxy(final Class<T> serviceInterface)
+ throws RemoteException, NotBoundException {
+
+ // The default RMI name will be the FQN of the service interface
+ String rmiName = serviceInterface.getName();
+ T result = createProxy(rmiName, serviceInterface);
+
+ return result;
+ }
+
+ /**
+ * Create a RMI proxy on the wanted service interface. The specific given
+ * RMI name will be used to find this service in the Registry.
+ *
+ * @param rmiName The specific RMI name to use to find the service
+ * in the registry
+ * @param serviceInterface The class of the service proxy to create
+ * @param <T> some interface class
+ * @return A newly created proxy which interface is <T>
+ * @throws RemoteException in case the registry is not reachable
+ * @throws NotBoundException if the default RMI name cannot be found in the
+ * registry
+ */
+ public static <T> T createProxy(String rmiName, Class<T> serviceInterface)
+ throws RemoteException, NotBoundException {
+
+ // Lookup the registry and the remote executor from the registry
+ Registry registry = LocateRegistry.getRegistry(REGISTRY_IP, PORT);
+ final RemoteMethodExecutor stub =
+ (RemoteMethodExecutor) registry.lookup(rmiName);
+
+ InvocationHandler handler = new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ // Get parameters types and values to prepare delegate call
+ String methodName = method.getName();
+ Class<?>[] parametersType = method.getParameterTypes();
+
+ // Delegate the execution and manage business exception cases
+ Object result;
+ try {
+ result = stub.execute(methodName, parametersType, args);
+ } catch (ServerException se) {
+ if (log.isInfoEnabled()) {
+ log.info("Server exception: " + se.getMessage());
+ }
+ Throwable cause = se.getCause();
+ if (cause instanceof RemoteException) {
+ RemoteException re = (RemoteException) cause;
+ cause = re.getCause();
+ }
+ throw cause;
+ }
+
+ return result;
+ }
+ };
+
+ // Invocation handler is ready, now create the proxy
+ T proxy = (T) Proxy.newProxyInstance(
+ ServiceExporter.class.getClassLoader(),
+ new Class<?>[]{serviceInterface},
+ handler);
+
+ return proxy;
+ }
+
+}
Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java (rev 0)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java 2011-01-12 14:31:01 UTC (rev 2010)
@@ -0,0 +1,124 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.util.rmi;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.rmi.ConnectException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+
+/**
+ * This class allows to make some service available throw RMI. For each service,
+ * a wrapper will be created which will be put in the RMI registry. This wrapper
+ * will intercept calls to the service and delegate them to it.
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+public class ServiceExporter {
+
+ private final static Log log = LogFactory.getLog(ServiceExporter.class);
+
+ // TODO AThimel 12/01/2011 This settings has to be externalized
+ private static final int PORT = 12345;
+
+ /**
+ * Does some checks on RMI configuration
+ */
+ protected void testRmiConfig() {
+ String rmiHost = System.getProperty("java.rmi.server.hostname");
+ if ((rmiHost == null || "".equals(rmiHost.trim()))
+ && log.isWarnEnabled()) {
+ log.warn("Server might not have been initialized properly, " +
+ "please specify '-Djava.rmi.server.hostname=<IP-address>'");
+ }
+ }
+
+ /**
+ * Will look for the RMI registry. It an external registry cannot be found,
+ * a new one will be created.
+ *
+ * @return the registry found or created
+ * @throws RemoteException in case it is not possible to get the registry
+ */
+ protected Registry getRegistry() throws RemoteException {
+ Registry result;
+ try {
+ result = LocateRegistry.getRegistry(PORT);
+ // To test that registry has been created. An exception will be
+ // thrown if registry cannot be called
+ result.list();
+ } catch (ConnectException ce) {
+ if (log.isWarnEnabled()) {
+ log.warn("Registry not found, creating a new one");
+ }
+ result = LocateRegistry.createRegistry(PORT);
+ }
+ return result;
+ }
+
+ /**
+ * Will register a service using the default name.
+ *
+ * @param serviceInterface the interface used to bind the service. The RMI
+ * name will be generated from this class name
+ * @param instance the service instance to bind
+ * @param <E> some interface class
+ * @throws RemoteException in case the registry is not reachable
+ */
+ public <E> void registerService(Class<E> serviceInterface, E instance)
+ throws RemoteException {
+ String rmiName = serviceInterface.getName();
+ registerService(rmiName, instance);
+ }
+
+ /**
+ * Will register a service using the given RMI name.
+ *
+ * @param rmiName the RMI name used to bind the service in the registry
+ * @param instance the service instance to bind
+ * @param <E> some interface class
+ * @throws RemoteException in case the registry is not reachable
+ */
+ public <E> void registerService(String rmiName, E instance)
+ throws RemoteException {
+
+ testRmiConfig();
+
+ // Create the proxy and let him be a stub
+ RemoteMethodExecutorImpl<E> executor =
+ new RemoteMethodExecutorImpl<E>(instance);
+ Remote stub = UnicastRemoteObject.exportObject(executor, 0);
+
+ // Bind into the registry
+ Registry registry = getRegistry();
+ registry.rebind(rmiName, stub);
+ }
+
+}
Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/ServiceExporter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/package-info.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/package-info.java (rev 0)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/package-info.java 2011-01-12 14:31:01 UTC (rev 2010)
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+/**
+ * This package contains classes to easily export services to a RMI registry
+ * then get a proxy to access them. The provided classes will hide RMI
+ * complexity.
+ * <p/>
+ * Use the {@link ServiceExporter} to register an service to the RMI registry.
+ * <p/>
+ * Use the {@link RemoteProxyFactory} to get a proxy an call the RMI exported
+ * service.
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ */
+package org.nuiton.util.rmi;
\ No newline at end of file
Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/rmi/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
2
1
Author: fdesbois
Date: 2011-01-07 14:05:05 +0100 (Fri, 07 Jan 2011)
New Revision: 2009
Url: http://nuiton.org/repositories/revision/nuiton-utils/2009
Log:
- Removed modules nuiton-rss and nuiton-tapestry-extra, moved in nuiton-web
- Remove useless dependencies
Removed:
trunk/nuiton-rss/
trunk/nuiton-tapestry-extra/
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-07 13:01:15 UTC (rev 2008)
+++ trunk/pom.xml 2011-01-07 13:05:05 UTC (rev 2009)
@@ -45,8 +45,6 @@
<module>nuiton-utils</module>
<module>nuiton-validator</module>
<module>nuiton-profiling</module>
- <!--<module>nuiton-tapestry-extra</module>-->
- <!--<module>nuiton-rss</module>-->
</modules>
<dependencyManagement>
@@ -107,73 +105,6 @@
<version>${aspectwerkzVersion}</version>
</dependency>
- <!-- tapestry dependencies -->
-
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-core</artifactId>
- <version>${tapestryVersion}</version>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>jboss</groupId>
- <artifactId>javassist</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-ioc</artifactId>
- <version>${tapestryVersion}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry5-annotations</artifactId>
- <version>${tapestryVersion}</version>
- </dependency>
-
- <!-- sl4j dependencies -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4jVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4jVersion}</version>
- </dependency>
-
- <dependency>
- <groupId>org.jdom</groupId>
- <artifactId>jdom</artifactId>
- <version>1.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>rome</groupId>
- <artifactId>rome</artifactId>
- <version>0.9</version>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>jdom</groupId>
- <artifactId>jdom</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!--Provided-->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
-
</dependencies>
</dependencyManagement>
1
0
r2008 - trunk/nuiton-utils/src/main/java/org/nuiton/util/war
by fdesbois@users.nuiton.org 07 Jan '11
by fdesbois@users.nuiton.org 07 Jan '11
07 Jan '11
Author: fdesbois
Date: 2011-01-07 14:01:15 +0100 (Fri, 07 Jan 2011)
New Revision: 2008
Url: http://nuiton.org/repositories/revision/nuiton-utils/2008
Log:
@Deprecated not supported on package-info
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java 2011-01-07 12:42:48 UTC (rev 2007)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java 2011-01-07 13:01:15 UTC (rev 2008)
@@ -30,10 +30,5 @@
* <li>Winstone : {@link org.nuiton.util.war.WinstoneLauncher}</li>
* <li>Jetty : {@link org.nuiton.util.war.JettyLauncher}</li>
* </ul>
- *
- * @deprecated since 2.0, moved to
- * <a href="http://nuiton.org/projects/show/nuiton-web">nuiton-web</a> 1.0, will
- * be removed in 2.1
*/
-@Deprecated
package org.nuiton.util.war;
1
0
r2007 - in trunk: . nuiton-utils nuiton-utils/src/main/java/org/nuiton/util/war
by fdesbois@users.nuiton.org 07 Jan '11
by fdesbois@users.nuiton.org 07 Jan '11
07 Jan '11
Author: fdesbois
Date: 2011-01-07 13:42:48 +0100 (Fri, 07 Jan 2011)
New Revision: 2007
Url: http://nuiton.org/repositories/revision/nuiton-utils/2007
Log:
#1202 : deprecate war package, need to be moved to nuiton-web (#1201)
Modified:
trunk/nuiton-utils/pom.xml
trunk/nuiton-utils/src/main/java/org/nuiton/util/war/JettyLauncher.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java
trunk/pom.xml
Modified: trunk/nuiton-utils/pom.xml
===================================================================
--- trunk/nuiton-utils/pom.xml 2011-01-04 10:28:12 UTC (rev 2006)
+++ trunk/nuiton-utils/pom.xml 2011-01-07 12:42:48 UTC (rev 2007)
@@ -73,12 +73,14 @@
<scope>test</scope>
</dependency>
+ <!-- Dependency for WarLauncher deprecated since 2.0, will be removed in 2.1 -->
<dependency>
<groupId>org.jvnet.hudson.winstone</groupId>
<artifactId>winstone</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- Dependency for WarLauncher deprecated since 2.0, will be removed in 2.1 -->
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-webapp</artifactId>
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/war/JettyLauncher.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/war/JettyLauncher.java 2011-01-04 10:28:12 UTC (rev 2006)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/war/JettyLauncher.java 2011-01-07 12:42:48 UTC (rev 2007)
@@ -63,11 +63,13 @@
* java -jar app-xxx.war
*
* @author chatellier
- * @version $Revision$
+ * @version $Id$
* @since 1.1.2
- *
- * Last update : $Date$
- * By : */
+ * @deprecated since 2.0, moved to
+ * <a href="http://nuiton.org/projects/show/nuiton-web">nuiton-web</a> 1.0, will
+ * be removed in 2.1
+ */
+@Deprecated
public class JettyLauncher implements ActionListener, MouseListener {
/** Jetty server instance. */
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/war/WinstoneLauncher.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2011-01-04 10:28:12 UTC (rev 2006)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/war/WinstoneLauncher.java 2011-01-07 12:42:48 UTC (rev 2007)
@@ -60,11 +60,13 @@
* java -jar app-xxx.war
*
* @author chatellier
- * @version $Revision$
+ * @version $Id$
* @since 1.1.2
- *
- * Last update : $Date$
- * By : */
+ * @deprecated since 2.0, moved to
+ * <a href="http://nuiton.org/projects/show/nuiton-web">nuiton-web</a> 1.0, will
+ * be removed in 2.1
+ */
+@Deprecated
public class WinstoneLauncher implements ActionListener, MouseListener {
/** Winstone server instance. */
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java 2011-01-04 10:28:12 UTC (rev 2006)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/war/package-info.java 2011-01-07 12:42:48 UTC (rev 2007)
@@ -27,7 +27,13 @@
*
* Currently implemented with :
* <ul>
- * <li>Winstone : {@link org.nuiton.util.war.WinstoneLauncher}
+ * <li>Winstone : {@link org.nuiton.util.war.WinstoneLauncher}</li>
+ * <li>Jetty : {@link org.nuiton.util.war.JettyLauncher}</li>
* </ul>
+ *
+ * @deprecated since 2.0, moved to
+ * <a href="http://nuiton.org/projects/show/nuiton-web">nuiton-web</a> 1.0, will
+ * be removed in 2.1
*/
+@Deprecated
package org.nuiton.util.war;
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-04 10:28:12 UTC (rev 2006)
+++ trunk/pom.xml 2011-01-07 12:42:48 UTC (rev 2007)
@@ -59,12 +59,14 @@
<version>${nuitonI18nVersion}</version>
</dependency>
+ <!-- Dependency for WarLauncher deprecated since 2.0, will be removed in 2.1 -->
<dependency>
<groupId>org.jvnet.hudson.winstone</groupId>
<artifactId>winstone</artifactId>
<version>0.9.10-hudson-24</version>
</dependency>
+ <!-- Dependency for WarLauncher deprecated since 2.0, will be removed in 2.1 -->
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-webapp</artifactId>
1
0
r2006 - in trunk: . nuiton-profiling nuiton-profiling/src/main/java/org/nuiton/profiling nuiton-profiling/src/site nuiton-profiling/src/site/apt
by tchemit@users.nuiton.org 04 Jan '11
by tchemit@users.nuiton.org 04 Jan '11
04 Jan '11
Author: tchemit
Date: 2011-01-04 11:28:12 +0100 (Tue, 04 Jan 2011)
New Revision: 2006
Url: http://nuiton.org/repositories/revision/nuiton-utils/2006
Log:
rename nuiton-utils-extra to nuiton-profiling + desactivate web modules
Added:
trunk/nuiton-profiling/
Removed:
trunk/nuiton-utils-extra/
Modified:
trunk/nuiton-profiling/pom.xml
trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
trunk/nuiton-profiling/src/site/apt/index.apt
trunk/nuiton-profiling/src/site/site_fr.xml
trunk/pom.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-utils-extra/pom.xml 2010-12-30 12:14:03 UTC (rev 2005)
+++ trunk/nuiton-profiling/pom.xml 2011-01-04 10:28:12 UTC (rev 2006)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
- Nuiton Utils :: Nuiton Utils Extra
+ Nuiton Utils :: Nuiton Profiling
$Id$
$HeadURL$
%%
@@ -38,7 +38,7 @@
<version>2.0-SNAPSHOT</version>
</parent>
- <artifactId>nuiton-utils-extra</artifactId>
+ <artifactId>nuiton-profiling</artifactId>
<dependencies>
@@ -77,8 +77,8 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <name>Nuiton Utils :: Nuiton Utils Extra</name>
- <description>Library of usefull class to be used in any project.</description>
+ <name>Nuiton Utils :: Nuiton Profiling</name>
+ <description>Library of perform profiling in any project.</description>
<inceptionYear>2004</inceptionYear>
<!-- ************************************************************* -->
Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
===================================================================
--- trunk/nuiton-utils-extra/src/main/java/org/nuiton/profiling/NuitonTrace.java 2010-12-30 12:14:03 UTC (rev 2005)
+++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-01-04 10:28:12 UTC (rev 2006)
@@ -1,6 +1,6 @@
/*
* #%L
- * Nuiton utilities extra library
+ * Nuiton Utils :: Nuiton Profiling
* %%
* Copyright (C) 2006 - 2010 CodeLutin
* %%
Modified: trunk/nuiton-profiling/src/site/apt/index.apt
===================================================================
--- trunk/nuiton-utils-extra/src/site/apt/index.apt 2010-12-30 12:14:03 UTC (rev 2005)
+++ trunk/nuiton-profiling/src/site/apt/index.apt 2011-01-04 10:28:12 UTC (rev 2006)
@@ -1,6 +1,6 @@
~~~
~~ #%L
-~~ Nuiton Utils :: Nuiton Utils Extra
+~~ Nuiton Utils :: Nuiton Profiling
~~
~~ $Id$
~~ $HeadURL$
Modified: trunk/nuiton-profiling/src/site/site_fr.xml
===================================================================
--- trunk/nuiton-utils-extra/src/site/site_fr.xml 2010-12-30 12:14:03 UTC (rev 2005)
+++ trunk/nuiton-profiling/src/site/site_fr.xml 2011-01-04 10:28:12 UTC (rev 2006)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
- Nuiton Utils
+ Nuiton Utils :: Nuiton Profiling
$Id$
$HeadURL$
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-30 12:14:03 UTC (rev 2005)
+++ trunk/pom.xml 2011-01-04 10:28:12 UTC (rev 2006)
@@ -44,9 +44,9 @@
<modules>
<module>nuiton-utils</module>
<module>nuiton-validator</module>
- <module>nuiton-utils-extra</module>
- <module>nuiton-tapestry-extra</module>
- <module>nuiton-rss</module>
+ <module>nuiton-profiling</module>
+ <!--<module>nuiton-tapestry-extra</module>-->
+ <!--<module>nuiton-rss</module>-->
</modules>
<dependencyManagement>
1
0