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
August 2012
- 2 participants
- 22 discussions
16 Aug '12
Author: tchemit
Date: 2012-08-16 17:16:28 +0200 (Thu, 16 Aug 2012)
New Revision: 2398
Url: http://nuiton.org/repositories/revision/nuiton-utils/2398
Log:
#2263: Be able to change the *safetySwitch* configuration on export
Modified:
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportToMap.java
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportToMap.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportToMap.java 2012-08-16 12:35:36 UTC (rev 2397)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportToMap.java 2012-08-16 15:16:28 UTC (rev 2398)
@@ -53,6 +53,16 @@
return new ImportToMap(model, reader);
}
+ public static ImportToMap newImportToMap(ImportModel<Map<String, Object>> model,
+ InputStream inputStream, boolean safetySwitch) {
+ return new ImportToMap(model, inputStream, safetySwitch);
+ }
+
+ public static ImportToMap newImportToMap(ImportModel<Map<String, Object>> model,
+ Reader reader, boolean safetySwitch) {
+ return new ImportToMap(model, reader, safetySwitch);
+ }
+
@Override
public Iterator<Map<String, Object>> iterator() {
@@ -120,11 +130,23 @@
protected ImportToMap(ImportModel<Map<String, Object>> mapImportModel,
InputStream inputStream) {
+ this(mapImportModel, inputStream, true);
+ }
+
+ protected ImportToMap(ImportModel<Map<String, Object>> mapImportModel,
+ Reader reader) {
+ this(mapImportModel, reader, true);
+ }
+
+ protected ImportToMap(ImportModel<Map<String, Object>> mapImportModel,
+ InputStream inputStream, boolean safetySwitch) {
super(mapImportModel, inputStream);
+ this.reader.setSafetySwitch(safetySwitch);
}
protected ImportToMap(ImportModel<Map<String, Object>> mapImportModel,
- Reader reader) {
+ Reader reader, boolean safetySwitch) {
super(mapImportModel, reader);
+ this.reader.setSafetySwitch(safetySwitch);
}
}
1
0
r2397 - trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext
by tchemit@users.nuiton.org 16 Aug '12
by tchemit@users.nuiton.org 16 Aug '12
16 Aug '12
Author: tchemit
Date: 2012-08-16 14:35:36 +0200 (Thu, 16 Aug 2012)
New Revision: 2397
Url: http://nuiton.org/repositories/revision/nuiton-utils/2397
Log:
add missing license header
Modified:
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java 2012-08-16 12:31:13 UTC (rev 2396)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java 2012-08-16 12:35:36 UTC (rev 2397)
@@ -4,4 +4,27 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.6
*/
-package org.nuiton.util.csv.ext;
\ No newline at end of file
+package org.nuiton.util.csv.ext;
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Csv
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 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%
+ */
1
0
r2396 - in trunk: nuiton-csv nuiton-csv/src/main/java/org/nuiton/util/csv nuiton-csv/src/main/java/org/nuiton/util/csv/ext nuiton-validator/src/main/java/org/nuiton/validator/bean/simple
by tchemit@users.nuiton.org 16 Aug '12
by tchemit@users.nuiton.org 16 Aug '12
16 Aug '12
Author: tchemit
Date: 2012-08-16 14:31:13 +0200 (Thu, 16 Aug 2012)
New Revision: 2396
Url: http://nuiton.org/repositories/revision/nuiton-utils/2396
Log:
refs #2259: Add a csv ext package (for extended stuff)
Added:
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/CsvReaders.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/RepeatableExport.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java
Modified:
trunk/nuiton-csv/pom.xml
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java
Modified: trunk/nuiton-csv/pom.xml
===================================================================
--- trunk/nuiton-csv/pom.xml 2012-08-11 07:54:22 UTC (rev 2395)
+++ trunk/nuiton-csv/pom.xml 2012-08-16 12:31:13 UTC (rev 2396)
@@ -65,6 +65,11 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
</dependency>
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/CsvReaders.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/CsvReaders.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/CsvReaders.java 2012-08-16 12:31:13 UTC (rev 2396)
@@ -0,0 +1,57 @@
+package org.nuiton.util.csv.ext;
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Csv
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 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%
+ */
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+import org.nuiton.util.csv.ImportRuntimeException;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Useful method around csv readers.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class CsvReaders {
+
+ public static String[] getHeader(File file, char charSeprator) {
+
+ try {
+ BufferedReader reader = Files.newReader(file, Charsets.UTF_8);
+ try {
+ String header = reader.readLine();
+ String[] result = header.split(charSeprator + "");
+ return result;
+ } finally {
+ reader.close();
+ }
+ } catch (IOException e) {
+ throw new ImportRuntimeException("Could not obtain header of file " + file, e);
+ }
+ }
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/CsvReaders.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/RepeatableExport.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/RepeatableExport.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/RepeatableExport.java 2012-08-16 12:31:13 UTC (rev 2396)
@@ -0,0 +1,101 @@
+package org.nuiton.util.csv.ext;
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Csv
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 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%
+ */
+
+import org.nuiton.util.csv.Export;
+import org.nuiton.util.csv.ExportModel;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+/**
+ * Extends the {@link Export} classes to be able to generate only once
+ * the header.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class RepeatableExport<E> extends Export<E> {
+
+ public static <E> RepeatableExport<E> newExport(ExportModel<E> model,
+ Iterable<E> data,
+ boolean writeOnceHeader) {
+ return new RepeatableExport<E>(model, data, writeOnceHeader);
+ }
+
+ public static <E> void exportToWriter(ExportModel<E> model,
+ Iterable<E> data,
+ Writer writer,
+ boolean writeOnceHeader) throws Exception {
+ Export<E> exporter = newExport(model, data, writeOnceHeader);
+ exporter.write(writer);
+ }
+
+ public static <E> void exportToFile(ExportModel<E> model,
+ Iterable<E> data,
+ File file,
+ Charset charset,
+ boolean writeOnceHeader) throws Exception {
+ Export<E> exporter = newExport(model, data, writeOnceHeader);
+ exporter.write(file, charset);
+ }
+
+ public static <E> String exportToString(ExportModel<E> model,
+ Iterable<E> data,
+ Charset charset,
+ boolean writeOnceHeader) throws Exception {
+ Export<E> exporter = newExport(model, data, writeOnceHeader);
+ return exporter.toString(charset);
+ }
+
+ protected final boolean writeOnceHeader;
+
+ protected boolean headerWritten;
+
+ public boolean isHeaderWritten() {
+ return headerWritten;
+ }
+
+ protected RepeatableExport(ExportModel<E> model,
+ Iterable<E> data,
+ boolean writeOnceHeader) {
+ super(model, data);
+ this.writeOnceHeader = writeOnceHeader;
+ }
+
+ @Override
+ protected void writeHeader(Writer writer) throws IOException {
+ if (!writeOnceHeader || !headerWritten) {
+
+ // no header generated, let's do it!
+
+ super.writeHeader(writer);
+
+ // mark it as written
+ headerWritten = true;
+ }
+ }
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/RepeatableExport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java 2012-08-16 12:31:13 UTC (rev 2396)
@@ -0,0 +1,7 @@
+/**
+ * Offers some extended api.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+package org.nuiton.util.csv.ext;
\ No newline at end of file
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ext/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java 2012-08-11 07:54:22 UTC (rev 2395)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java 2012-08-16 12:31:13 UTC (rev 2396)
@@ -1,4 +1,27 @@
package org.nuiton.validator.bean.simple;
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 - 2012 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%
+ */
import org.nuiton.validator.NuitonValidatorScope;
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
1
0
r2395 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/bean main/java/org/nuiton/validator/bean/list main/java/org/nuiton/validator/bean/simple test/java/org/nuiton/validator/bean
by tchemit@users.nuiton.org 11 Aug '12
by tchemit@users.nuiton.org 11 Aug '12
11 Aug '12
Author: tchemit
Date: 2012-08-11 09:54:22 +0200 (Sat, 11 Aug 2012)
New Revision: 2395
Url: http://nuiton.org/repositories/revision/nuiton-utils/2395
Log:
fixes #2249: Remove deprecated BeanValidator api
Removed:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorEvent.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorFactory.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorListener.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorMessage.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorUtil.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/bean/BeanValidatorTest.java
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorEvent.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorMessage.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidatorEvent.java
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidator.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidator.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,852 +0,0 @@
-/*
- * #%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.bean;
-
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.Converter;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.beans.BeanUtil;
-import org.nuiton.util.converter.ConverterUtil;
-import org.nuiton.validator.NuitonValidator;
-import org.nuiton.validator.NuitonValidatorModel;
-import org.nuiton.validator.NuitonValidatorProvider;
-import org.nuiton.validator.NuitonValidatorResult;
-import org.nuiton.validator.NuitonValidatorScope;
-import org.nuiton.validator.bean.simple.SimpleBeanValidator;
-
-import javax.swing.event.EventListenerList;
-import java.beans.Introspector;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Validator for a javaBean object.
- * <p/>
- * A such validator is designed to validate to keep the validation of a bean,
- * means the bean is attached to the validator (field {@link #bean}.
- * <p/>
- * A such validator is also a JavaBean and you can listen his states
- * modifications via the classic java bean api.
- * <p/>
- * <strong>Note:</strong> The {@code BeanValidator} should never be used for
- * validation in a service approch since it needs to keep a reference to the
- * bean to validate.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @see BeanValidatorListener
- * @since 2.0
- * @deprecated since 2.5.2, use instead the {@link SimpleBeanValidator}.
- */
-@Deprecated
-public class BeanValidator<O> {
-
- /**
- * Name of the bounded property {@link #bean}.
- *
- * @see #bean
- * @see #getBean()
- * @see #setBean(Object)
- */
- public static final String BEAN_PROPERTY = "bean";
-
- /**
- * Name of the bounded property {@code context}.
- *
- * @see #getContext()
- * @see #setContext(String)
- */
- public static final String CONTEXT_PROPERTY = "context";
-
- /**
- * Name of the bounded property {@code scopes}.
- *
- * @see #getScopes()
- * @see #setScopes(NuitonValidatorScope...)
- */
- public static final String SCOPES_PROPERTY = "scopes";
-
- /**
- * Name of the bounded property {@link #valid}.
- *
- * @see #valid
- * @see #isValid()
- * @see #setValid(boolean)
- */
- public static final String VALID_PROPERTY = "valid";
-
- /**
- * Name of the bounded property {@link #changed}.
- *
- * @see #changed
- * @see #isChanged()
- * @see #setChanged(boolean)
- */
- public static final String CHANGED_PROPERTY = "changed";
-
- /** Logger. */
- protected static final Log log = LogFactory.getLog(BeanValidator.class);
-
- /** The bean to validate. */
- protected O bean;
-
- /** To chain to another validator (acting as parent of this one). */
- protected BeanValidator<?> parentValidator;
-
- /** The delegate validator used to validate the bean. */
- protected NuitonValidator<O> delegate;
-
- /**
- * State of validation (keep all messages of validation for the filled
- * bean).
- */
- protected NuitonValidatorResult messages;
-
- /**
- * State to indicate that validator has changed since the last time bean was
- * setted.
- */
- protected boolean changed;
-
- /** State of the validator (is true if no errors of error scope is found). */
- protected boolean valid = true;
-
- /**
- * State to know if the validator can be used (we keep this state for
- * performance reasons : do not want to compute this value each time a
- * validation is asked...).
- */
- protected boolean canValidate = true;
-
- /** map of conversion errors detected by this validator */
- protected Map<String, String> conversionErrors;
-
- /** Listener that listens on bean modification. */
- protected PropertyChangeListener l;
-
- /** delegate property change support */
- protected PropertyChangeSupport pcs;
-
- /** A list of event listeners for this validators */
- protected EventListenerList listenerList = new EventListenerList();
-
- /**
- * The provider of delegate validators.
- * <p/>
- * It will also produce validator model.
- *
- * @see NuitonValidatorProvider
- */
- protected final NuitonValidatorProvider validatorProvider;
-
- public BeanValidator(NuitonValidatorProvider validatorProvider,
- Class<O> beanClass,
- String context) {
-
- this(validatorProvider, beanClass,
- context,
- NuitonValidatorScope.values()
- );
- }
-
- public BeanValidator(NuitonValidatorProvider validatorProvider,
- Class<O> beanClass,
- String context,
- NuitonValidatorScope... scopes) {
-
- // check if given bean class is Javabean compiliant
- boolean javaBeanCompiliant = BeanUtil.isJavaBeanCompiliant(beanClass);
-
- if (!javaBeanCompiliant) {
-
- throw new IllegalArgumentException(
- beanClass.getName() + " is not JavaBean compiliant (" +
- BeanUtil.ADD_PROPERTY_CHANGE_LISTENER + ", or " +
- BeanUtil.REMOVE_PROPERTY_CHANGE_LISTENER +
- " method not found).");
- }
-
- this.validatorProvider = validatorProvider;
- pcs = new PropertyChangeSupport(this);
- conversionErrors = new TreeMap<String, String>();
-
- // build delegate validator
- rebuildDelegateValidator(
- beanClass,
- context,
- scopes
- );
-
- // context has changed
- firePropertyChange(CONTEXT_PROPERTY,
- null,
- context
- );
-
- // scopes has changed
- firePropertyChange(SCOPES_PROPERTY,
- null,
- scopes
- );
-
- l = new PropertyChangeListener() {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
-
- // the bean has changed, replay validation
- doValidate();
- }
- };
- }
-
- /**
- * Obtain the {@link #changed} property value.
- * <p/>
- * Returns {@code true} if bean was modified since last
- * time a bean was attached.
- *
- * @return {@code true} if bean was modified since last attachement of
- * a bean.
- */
- public boolean isChanged() {
- return changed;
- }
-
- /**
- * To force the value of the property {@link #changed}.
- *
- * @param changed flag to force reset of property {@link #changed}
- */
- public void setChanged(boolean changed) {
- this.changed = changed;
-
- // force the property to be fired (never pass the older value)
- firePropertyChange(CHANGED_PROPERTY, null, changed);
- }
-
- public boolean isCanValidate() {
- return canValidate;
- }
-
- public void setCanValidate(boolean canValidate) {
- this.canValidate = canValidate;
- }
-
- /**
- * Obtain the {@link #valid} property value.
- *
- * @return {@code true} if attached bean is valid (no error or fatal messages)
- */
- public boolean isValid() {
- return valid;
- }
-
- /**
- * Change the value of the {@link #valid} property.
- *
- * @param valid the new value of the property
- */
- public void setValid(boolean valid) {
- this.valid = valid;
-
- // force the property to be fired (never pass the older value)
- firePropertyChange(VALID_PROPERTY, null, valid);
- }
-
- /**
- * Obtain the actual bean attached to the validator.
- *
- * @return the bean attached to the validor or {@code null} if no bean
- * is attached
- */
- public O getBean() {
- return bean;
- }
-
- /**
- * Change the attached bean.
- * <p/>
- * As a side effect, the internal {@link #messages} will be reset.
- *
- * @param bean the bean to attach (can be {@code null} to reset the
- * validator).
- */
- public void setBean(O bean) {
- O oldBean = this.bean;
- if (log.isDebugEnabled()) {
- log.debug(this + " : " + bean);
- }
-
- // clean conversions of previous bean
- conversionErrors.clear();
-
- if (oldBean != null) {
- try {
- BeanUtil.removePropertyChangeListener(l, oldBean);
- } catch (Exception eee) {
- if (log.isInfoEnabled()) {
- log.info("Can't register as listener for bean " + oldBean.getClass() +
- " for reason " + eee.getMessage(), eee);
- }
- }
- }
- this.bean = bean;
-
- setCanValidate(!getDelegate().getEffectiveFields().isEmpty() && bean != null);
-
- if (bean == null) {
-
- // remove all messages for all fields of the validator
-
- mergeMessages(null);
-
- } else {
- try {
-
- BeanUtil.addPropertyChangeListener(l, bean);
- } catch (Exception eee) {
- if (log.isInfoEnabled()) {
- log.info("Can't register as listener for bean " + bean.getClass() +
- " for reason " + eee.getMessage(), eee);
- }
- }
- validate();
- }
- setChanged(false);
- setValid(messages == null || messages.isValid());
- firePropertyChange(BEAN_PROPERTY, oldBean, bean);
- }
-
- public String getContext() {
- return delegate.getModel().getContext();
- }
-
- public void setContext(String context) {
-
- String oldContext = getContext();
-
- if (context == null && oldContext == null || context != null && context.equals(oldContext)) {
-
- // same context do nothing
- return;
- }
- NuitonValidatorModel<O> validatorModel = delegate.getModel();
-
- // compute the new validator model
- NuitonValidatorScope[] scopes = validatorModel.getScopes().toArray(
- new NuitonValidatorScope[validatorModel.getScopes().size()]);
-
- rebuildDelegateValidator(
- validatorModel.getType(),
- context,
- scopes
- );
-
- firePropertyChange(CONTEXT_PROPERTY,
- oldContext,
- context
- );
- }
-
- public Set<NuitonValidatorScope> getScopes() {
- return delegate.getModel().getScopes();
- }
-
- public Set<NuitonValidatorScope> getEffectiveScopes() {
- return delegate.getEffectiveScopes();
- }
-
- public Set<String> getEffectiveFields() {
- return delegate.getEffectiveFields();
- }
-
- public Set<String> getEffectiveFields(NuitonValidatorScope scope) {
- return delegate.getEffectiveFields(scope);
- }
-
- public void setScopes(NuitonValidatorScope... scopes) {
-
- Set<NuitonValidatorScope> oldScopes = getScopes();
-
- NuitonValidatorModel<O> validatorModel = delegate.getModel();
-
- rebuildDelegateValidator(
- validatorModel.getType(),
- validatorModel.getContext(),
- scopes
- );
-
- firePropertyChange(SCOPES_PROPERTY,
- oldScopes,
- scopes
- );
- }
-
- public Class<O> getType() {
- return delegate.getModel().getType();
- }
-
- protected void rebuildDelegateValidator(Class<O> beanType,
- String context,
- NuitonValidatorScope... scopes) {
-
- // changing context could change fields definition
- // so dettach bean, must rebuild the fields
-
- // Dettach the bean before any thing, because with the new delegate
- // validator some old fields could not be used any longer, and then
- // listeners will never have the full reset of their model...
- if (bean != null) {
- setBean(null);
- }
-
- if (scopes == null || scopes.length == 0) {
- scopes = NuitonValidatorScope.values();
- }
-
- // compute the new validator model
- NuitonValidatorModel<O> validatorModel = validatorProvider.getModel(beanType,
- context,
- scopes
- );
-
- // remove old delegate validator
- delegate = validatorProvider.newValidator(validatorModel);
- }
-
- public BeanValidator<?> getParentValidator() {
- return parentValidator;
- }
-
- public void setParentValidator(BeanValidator<?> parentValidator) {
- this.parentValidator = parentValidator;
- }
-
- public boolean hasFatalErrors() {
- boolean result = messages != null && messages.hasFatalMessages();
- return result;
- }
-
- public boolean hasErrors() {
- boolean result = messages != null && messages.hasErrorMessagess();
- return result;
- }
-
- public boolean hasWarnings() {
- boolean result = messages != null && messages.hasWarningMessages();
- return result;
- }
-
- public boolean hasInfos() {
- boolean result = messages != null && messages.hasInfoMessages();
- return result;
- }
-
- /**
- * Test a 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) {
- Set<String> effectiveFields = getDelegate().getEffectiveFields();
- boolean result = effectiveFields.contains(fieldName);
- return result;
- }
-
- public boolean isValid(String fieldName) {
- if (messages == null) {
-
- // no message, so this is valid
- return true;
- }
-
- // field is valid if no fatal messages nor error messages
- boolean result = !(
- messages.hasMessagesForScope(fieldName, NuitonValidatorScope.FATAL) ||
- messages.hasMessagesForScope(fieldName, NuitonValidatorScope.ERROR));
-
- return result;
- }
-
- public NuitonValidatorScope getHighestScope(String field) {
- if (messages == null) {
-
- // no messages
- return null;
- }
-
- NuitonValidatorScope scope = messages.getFieldHighestScope(field);
- return scope;
- }
-
- /**
- * Convert a value.
- * <p/>
- * If an error occurs, then add an error in validator.
- *
- * @param <T> the type of conversion
- * @param fieldName the name of the bean property
- * @param value the value to convert
- * @param valueClass the type of converted value
- * @return the converted value, or null if conversion was not ok
- */
- @SuppressWarnings({"unchecked"})
- public <T> T convert(String fieldName, String value, Class<T> valueClass) {
- if (fieldName == null) {
- throw new IllegalArgumentException("fieldName can not be null");
- }
- if (valueClass == null) {
- throw new IllegalArgumentException("valueClass can not be null");
- }
-
- // on ne convertit pas si il y a un bean et que le resultat de la
- // validation pourra etre affiche quelque part
- if (!isCanValidate() || value == null) {
- return null;
- }
-
- // remove the previous conversion error for the field
- conversionErrors.remove(fieldName);
-
- T result;
- try {
- Converter converter = ConverterUtil.getConverter(valueClass);
- if (converter == null) {
- throw new RuntimeException(
- "could not find converter for the type " + valueClass);
- }
- result = (T) converter.convert(valueClass, value);
- /* Why this test ? if (result != null && !value.equals(result.toString())) {
- conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
- result = null;
- validate();
- }*/
- } catch (ConversionException e) {
- // get
- String s = Introspector.decapitalize(valueClass.getSimpleName());
- conversionErrors.put(fieldName, "error.convertor." + s);
- result = null;
- validate();
- }
- return result;
- }
-
- public void doValidate() {
- validate();
- setValid(messages == null || messages.isValid());
- setChanged(true);
- }
-
- /**
- * il faut eviter le code re-intrant (durant une validation, une autre est
- * demandee). Pour cela on fait la validation dans un thread, et tant que la
- * premiere validation n'est pas fini, on ne repond pas aux solicitations.
- * Cette method est public pour permettre de force une validation par
- * programmation, ce qui est utile par exemple si le bean ne supporte pas
- * les {@link PropertyChangeListener}
- * <p/>
- * <b>Note:</b> la methode est protected et on utilise la methode
- * {@link #doValidate()} car la méthode ne modifie pas les etats
- * internes et cela en rend son utilisation delicate (le validateur entre
- * dans un etat incoherent par rapport aux messages envoyés).
- */
- public void validate() {
-
- // on ne valide que si il y a un bean et que le resultat de la validation
- // pourra etre affiche quelque part
- if (!isCanValidate()) {
- return;
- }
-
- NuitonValidatorResult result = getDelegate().validate(bean);
-
- // treate conversion errors
- // reinject them
- for (Map.Entry<String, String> entry : conversionErrors.entrySet()) {
-
-
- // remove from validation, errors occurs on this field
- String field = entry.getKey();
-
-
- List<String> errors = result.getErrorMessages(field);
-
- String conversionError = entry.getValue();
- if (errors != null) {
- errors.clear();
- errors.add(conversionError);
- } else {
- errors = Collections.singletonList(conversionError);
- }
-
- result.setMessagesForScope(NuitonValidatorScope.ERROR, field, errors);
- }
-
- mergeMessages(result);
-
- if (parentValidator != null) {
- // chained validation
- // the parent validator should not be changed from this validation
- boolean wasModified = parentValidator.isChanged();
- parentValidator.doValidate();
- if (!wasModified) {
- // push back old state
- parentValidator.setChanged(false);
- }
- }
- }
-
- @Override
- public String toString() {
- return super.toString() + "<beanClass:" + delegate.getModel().getType() +
- ", context:" + getContext() + ">";
- }
-
- public void addBeanValidatorListener(BeanValidatorListener listener) {
- listenerList.add(BeanValidatorListener.class, listener);
- }
-
- public void removeBeanValidatorListener(BeanValidatorListener listener) {
- listenerList.remove(BeanValidatorListener.class, listener);
- }
-
- public BeanValidatorListener[] getBeanValidatorListeners() {
- return listenerList.getListeners(BeanValidatorListener.class);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- public void firePropertyChange(String propertyName,
- Object oldValue,
- Object newValue) {
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- protected BeanValidatorEvent createEvent(String field,
- NuitonValidatorScope scope,
- String[] toAdd,
- String[] toDelete) {
- BeanValidatorEvent evt = new BeanValidatorEvent(
- this,
- field,
- scope,
- toAdd,
- toDelete
- );
- return evt;
- }
-
- protected void fireFieldChanged(String field,
- NuitonValidatorScope scope,
- String[] toAdd,
- String[] toDelete) {
-
- BeanValidatorEvent evt = createEvent(
- field,
- scope,
- toAdd,
- toDelete
- );
-
- fireFieldChanged(evt);
- }
-
- protected void fireFieldChanged(BeanValidatorEvent evt) {
-
- for (BeanValidatorListener listener :
- listenerList.getListeners(BeanValidatorListener.class)) {
- listener.onFieldChanged(evt);
- }
- }
-
- protected void mergeMessages(NuitonValidatorResult newMessages) {
-
- if (newMessages == null && messages == null) {
-
- // no messages ever registred and ask to delete them, so nothing
- // to do
- return;
- }
-
- Set<NuitonValidatorScope> scopes = getDelegate().getEffectiveScopes();
-
- // list of events to send after the merge of messages
- List<BeanValidatorEvent> events = new ArrayList<BeanValidatorEvent>();
-
- for (NuitonValidatorScope scope : scopes) {
-
- // do the merge at scope level
- mergeMessages(scope, newMessages, events);
-
- }
-
- if (newMessages != null) {
-
- //TODO tchemit 2011-01-23 Perharps it will necessary to clear the messages for memory performance ?
-
- // finally keep the new messages as the current messages
- messages = newMessages;
- }
-
- if (CollectionUtils.isNotEmpty(events)) {
-
- // send all messages
- for (BeanValidatorEvent event : events) {
- fireFieldChanged(event);
- }
- }
- }
-
- protected void mergeMessages(NuitonValidatorScope scope,
- NuitonValidatorResult newMessages,
- List<BeanValidatorEvent> events) {
-
- if (newMessages == null) {
-
- // special case to empty all messages
-
- List<String> fieldsForScope = messages.getFieldsForScope(scope);
-
- for (String field : fieldsForScope) {
- List<String> messagesForScope = messages.getMessagesForScope(field, scope);
- events.add(createEvent(field, scope, null, messagesForScope.toArray(new String[messagesForScope.size()])));
- }
-
- // suppress all messages for this scope
- messages.clearMessagesForScope(scope);
-
-
- } else {
-
- List<String> newFields = newMessages.getFieldsForScope(scope);
-
- if (messages == null) {
-
- // first time of a merge, just add new messages
-
- for (String field : newFields) {
- List<String> messagesForScope = newMessages.getMessagesForScope(field, scope);
- events.add(createEvent(field, scope, messagesForScope.toArray(new String[messagesForScope.size()]), null));
- }
-
- // nothing else to do
- return;
- }
-
- List<String> oldFields = messages.getFieldsForScope(scope);
-
- Iterator<String> itr;
-
- // detects field with only new messages
- itr = newFields.iterator();
- while (itr.hasNext()) {
- String newField = itr.next();
-
- if (!oldFields.contains(newField)) {
-
- // this fields has now messages but not before : new messages
- List<String> messagesForScope = newMessages.getMessagesForScope(newField, scope);
- events.add(createEvent(newField, scope, messagesForScope.toArray(new String[messagesForScope.size()]), null));
-
- // treated field
- itr.remove();
- }
- }
-
- // detects fields with only obsolete messages
- itr = oldFields.iterator();
- while (itr.hasNext()) {
- String oldField = itr.next();
-
- if (!newFields.contains(oldField)) {
-
- // this fields has no more messages
- List<String> messagesForScope = messages.getMessagesForScope(oldField, scope);
- events.add(createEvent(oldField, scope, null, messagesForScope.toArray(new String[messagesForScope.size()])));
-
- // treated field
- itr.remove();
- }
- }
-
- // now deal with mixte field (toAdd and toDelete)
- for (String field : newFields) {
-
- List<String> newMessagesForScope = newMessages.getMessagesForScope(field, scope);
- List<String> oldMessagesForScope = messages.getMessagesForScope(field, scope);
-
- // get old obsoletes messages to delete
- Set<String> toDelete = new HashSet<String>(oldMessagesForScope);
- toDelete.removeAll(newMessagesForScope);
-
- // get new messages to add
- Set<String> toAdd = new HashSet<String>(newMessagesForScope);
- toAdd.removeAll(oldMessagesForScope);
-
- events.add(createEvent(
- field,
- scope,
- toAdd.isEmpty() ? null : toAdd.toArray(new String[toAdd.size()]),
- toDelete.isEmpty() ? null : toDelete.toArray(new String[toDelete.size()])
- ));
-
- }
- }
- }
-
- protected NuitonValidator<O> getDelegate() {
- return delegate;
- }
-
-}
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorEvent.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorEvent.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorEvent.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,87 +0,0 @@
-/*
- * #%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.bean;
-
-import org.nuiton.validator.NuitonValidatorScope;
-import org.nuiton.validator.bean.simple.SimpleBeanValidatorEvent;
-
-import java.util.EventObject;
-
-/**
- * The definition of an event on {@link BeanValidatorListener}
- * to be fired by a {@link BeanValidator}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- * @deprecated since 2.5.2, use instead the {@link SimpleBeanValidatorEvent}
- */
-@Deprecated
-public class BeanValidatorEvent extends EventObject {
-
- private static final long serialVersionUID = 1L;
-
- /** the field impacted by the validator */
- protected String field;
-
- /** the scope impacted by the event */
- protected NuitonValidatorScope scope;
-
- protected String[] messagestoAdd;
-
- protected String[] messagestoDelete;
-
- public BeanValidatorEvent(BeanValidator<?> source,
- String field,
- NuitonValidatorScope scope,
- String[] messagestoAdd,
- String[] messagestoDelete) {
- super(source);
- this.field = field;
- this.scope = scope;
- this.messagestoAdd = messagestoAdd;
- this.messagestoDelete = messagestoDelete;
- }
-
- @Override
- public BeanValidator<?> getSource() {
- return (BeanValidator<?>) super.getSource();
- }
-
- public String[] getMessagesToAdd() {
- return messagestoAdd;
- }
-
- public String[] getMessagesToDelete() {
- return messagestoDelete;
- }
-
- public NuitonValidatorScope getScope() {
- return scope;
- }
-
- public String getField() {
- return field;
- }
-}
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorFactory.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorFactory.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorFactory.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,230 +0,0 @@
-/*
- * #%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.bean;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.validator.NuitonValidator;
-import org.nuiton.validator.NuitonValidatorFactory;
-import org.nuiton.validator.NuitonValidatorProvider;
-import org.nuiton.validator.NuitonValidatorScope;
-import org.nuiton.validator.bean.simple.SimpleBeanValidator;
-
-/**
- * Factory of {@link BeanValidator}.
- * <p/>
- * To obtain a new {@link BeanValidator}, use one of the method
- * <p/>
- * <pre>
- * BeanValidatorFactory.newBeanValidator(XXX)
- * </pre>
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @see BeanValidator
- * @since 2.0
- * @deprecated since 2.5.2, use instead the {@link SimpleBeanValidator} factory methods.
- */
-@Deprecated
-public class BeanValidatorFactory {
-
-
- /** Logger. */
- static private final Log log =
- LogFactory.getLog(BeanValidatorFactory.class);
-
-
- /**
- * Object to create new validators.
- * <p/>
- * If none is given, it will use the default one, says the
- * {@link DefaultBeanValidatorCreator}.
- */
- protected static BeanValidatorCreator creator;
-
- /**
- * Obtain the bean validator creator.
- * <p/>
- * If none is defined, then will use a default one, says the
- * {@link DefaultBeanValidatorCreator}.
- *
- * @return the bean validator creator
- */
- public static BeanValidatorCreator getCreator() {
- if (creator == null) {
- creator = new DefaultBeanValidatorCreator();
- if (log.isInfoEnabled()) {
- log.info("Will use default beanValidator creator : " + creator);
- }
-
- }
- return creator;
- }
-
- /**
- * Sets an explicit bean validator creator.
- *
- * @param creator the creator to use
- */
- public static void setCreator(BeanValidatorCreator creator) {
- BeanValidatorFactory.creator = creator;
- if (log.isInfoEnabled()) {
- log.info("Will use injected beanValidator creator : " + creator);
- }
- }
-
- public static boolean isDefaultCreator() {
- return creator == null ||
- creator.getClass().equals(DefaultBeanValidatorCreator.class);
- }
-
- /**
- * Obtain a new {@link BeanValidator} for the given parameters.
- * <p/>
- * <b>Note:</b> It will use the default provider of {@link NuitonValidator}
- *
- * @param type type of bean to validate
- * @param context context of validation
- * @param scopes authorized scopes (if {@code null}, will use all scopes)
- * @param <O> type of bean to validate
- * @return the new instanciated {@link BeanValidator}.
- * @throws NullPointerException if type is {@code null}
- * @see NuitonValidatorFactory#getDefaultProviderName()
- */
- public static <O> BeanValidator<O> newBeanValidator(Class<O> type,
- String context,
- NuitonValidatorScope... scopes) throws NullPointerException {
-
-
- // get the provider default name
- String providerName = NuitonValidatorFactory.getDefaultProviderName();
-
- // get the bean validator with this provider
- BeanValidator<O> beanValidator = newBeanValidator(providerName,
- type,
- context,
- scopes
- );
- return beanValidator;
- }
-
- /**
- * Obtain a new {@link BeanValidator} for the given parameters.
- * <p/>
- * <b>Note:</b> It will use the provider of {@link NuitonValidator}
- * defined by the {@code providerName}.
- *
- * @param providerName name of {@link NuitonValidator} to use
- * @param type type of bean to validate
- * @param context context of validation
- * @param scopes authorized scopes (if {@code null}, will use all scopes)
- * @param <O> type of bean to validate
- * @return the new instanciated {@link BeanValidator}.
- * @throws NullPointerException if type is {@code null}
- * @see NuitonValidatorFactory#getProvider(String)
- */
- public static <O> BeanValidator<O> newBeanValidator(String providerName,
- Class<O> type,
- String context,
- NuitonValidatorScope... scopes) throws NullPointerException {
-
- if (type == null) {
- throw new NullPointerException(
- "type parameter can not be null.");
- }
-
- // get delegate validator provider
- NuitonValidatorProvider provider =
- NuitonValidatorFactory.getProvider(providerName);
-
- // get bean validator creator
- BeanValidatorCreator creator = getCreator();
-
- // create the new instance of bean validator
- BeanValidator<O> beanValidator =
- creator.newBeanValidator(provider, type, context, scopes);
-
- return beanValidator;
- }
-
- /**
- * Contract to create a {@link BeanValidator}.
- * <p/>
- * A such object is registred in the {@link BeanValidatorFactory} to create
- * new instances of a {@link BeanValidator}.
- *
- * @see BeanValidatorFactory
- * @see BeanValidatorFactory#getCreator()
- * @see BeanValidatorFactory#setCreator(BeanValidatorCreator)
- * @see BeanValidatorFactory#isDefaultCreator()
- * @since 2.0
- */
- public interface BeanValidatorCreator {
-
- /**
- * Given the parameters, instanciate a new {@link BeanValidator}.
- *
- * @param provider the delegate validator provider
- * @param type the type of object to validate
- * @param context the context of validation (can be {@code null})
- * @param scopes scopes to use (if none given, will use all available scopes)
- * @param <O> type of object to validate
- * @return the new instance of bean validator
- */
- <O> BeanValidator<O> newBeanValidator(
- NuitonValidatorProvider provider,
- Class<O> type,
- String context,
- NuitonValidatorScope... scopes
-
- );
- }
-
- /**
- * Default implementation of {@link BeanValidatorCreator} which just
- * instanciate a {@link BeanValidator} from the given parameters.
- * <p/>
- * If no bean validator creator is given to the {@link BeanValidatorFactory}
- * it will instanciate a such creator and use it unless you change it.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
- public static class DefaultBeanValidatorCreator implements BeanValidatorCreator {
- @Override
- public <O> BeanValidator<O> newBeanValidator(
- NuitonValidatorProvider provider,
- Class<O> type,
- String context,
- NuitonValidatorScope... scopes) {
-
- BeanValidator<O> beanValidator = new BeanValidator<O>(provider,
- type,
- context,
- scopes
- );
- return beanValidator;
- }
- }
-}
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorListener.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorListener.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorListener.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,50 +0,0 @@
-/*
- * #%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.bean;
-
-
-import org.nuiton.validator.bean.simple.SimpleBeanValidatorListener;
-
-import java.util.EventListener;
-
-/**
- * The listener contract to be used on {@link BeanValidator} to fire that
- * some messages has changed for a given field and scope.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @see BeanValidatorEvent
- * @since 2.0
- * @deprecated since 2.5.2, use instead the {@link SimpleBeanValidatorListener}.
- */
-@Deprecated
-public interface BeanValidatorListener extends EventListener {
-
- /**
- * Invoked when a validator detects some changes on a field.
- *
- * @param event the event
- */
- void onFieldChanged(BeanValidatorEvent event);
-}
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorMessage.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorMessage.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorMessage.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,148 +0,0 @@
-/*
- * #%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.bean;
-
-import org.nuiton.validator.NuitonValidatorScope;
-import org.nuiton.validator.bean.simple.SimpleBeanValidatorMessage;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import static org.nuiton.i18n.I18n._;
-
-/**
- * The object to box a validation message.
- *
- * @param <E> type of message (use for override {@link #compareTo(Object)}
- * method.
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- * @deprecated since 2.5.2, use instead the {@link SimpleBeanValidatorMessage}.
- */
-@Deprecated
-public class BeanValidatorMessage<E extends BeanValidatorMessage<?>> implements Comparable<E>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- /** the validator that produce the message */
- protected BeanValidator<?> validator;
-
- /** the field that produce the message */
- protected String field;
-
- /** the label of the message (to be displayed somewhere) */
- protected String message;
-
- /** the scope of the message */
- protected NuitonValidatorScope scope;
-
- public BeanValidatorMessage(BeanValidator<?> validator,
- String field,
- String message,
- NuitonValidatorScope scope) {
- this.field = field;
- this.validator = validator;
- this.message = message == null ? null : message.trim();
- this.scope = scope;
- }
-
- public BeanValidator<?> getValidator() {
- return validator;
- }
-
- public String getField() {
- return field;
- }
-
- public NuitonValidatorScope getScope() {
- return scope;
- }
-
- public String getMessage() {
- return message;
- }
-
- @Override
- public int compareTo(E o) {
- // sort on scope
- int result = getScope().compareTo(o.getScope());
- if (result == 0) {
- // sort on field name
- result = field.compareTo(o.field);
- if (result == 0) {
- // sort on message
- result = message.compareTo(o.message);
- }
- }
- return result;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof BeanValidatorMessage<?>)) {
- return false;
- }
-
- BeanValidatorMessage<?> that = (BeanValidatorMessage<?>) o;
-
- return field.equals(that.field) &&
- (message != null ? !message.equals(that.message) : that.message == null) &&
- scope == that.scope;
- }
-
- @Override
- public int hashCode() {
- int result = field.hashCode();
- result = 31 * result + (message != null ? message.hashCode() : 0);
- result = 31 * result + (scope != null ? scope.hashCode() : 0);
- return result;
- }
-
- @Override
- public String toString() {
- return scope + " - " + getI18nError(message);
- }
-
- public String getI18nError(String error) {
- String text;
- if (!error.contains("##")) {
- text = _(error);
- } else {
- StringTokenizer stk = new StringTokenizer(error, "##");
- String errorName = stk.nextToken();
- List<String> args = new ArrayList<String>();
- while (stk.hasMoreTokens()) {
- args.add(stk.nextToken());
- }
- text = _(errorName, args.toArray());
- }
- return text;
- }
-}
Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorUtil.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorUtil.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/BeanValidatorUtil.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,133 +0,0 @@
-/*
- * #%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.bean;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.validator.NuitonValidatorScope;
-
-import java.beans.BeanInfo;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.List;
-
-/**
- * The helper class for bean validation module.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- * @deprecated since 2.5.2, for the moment none of this was used, and will no be replaced.
- */
-@Deprecated
-public class BeanValidatorUtil {
-
- /** Logger */
- static private final Log log = LogFactory.getLog(BeanValidatorUtil.class);
-
- protected BeanValidatorUtil() {
- // no instance
- }
-
- /**
- * Convert a value to a given type and then if was succesffull try to set it
- * in the bean manage by the validator.
- *
- * @param validator validator to be involved
- * @param fieldName the name of the bean property
- * @param value the actual value to convert
- * @param valueClass the type of the conversion
- */
- public static void convert(BeanValidator<?> validator,
- String fieldName,
- String value,
- Class<?> valueClass) {
-
- Object result = validator.convert(fieldName, value, valueClass);
- if (result != null) {
- try {
- BeanInfo info =
- Introspector.getBeanInfo(validator.getBean().getClass());
-
- for (PropertyDescriptor descriptor :
- info.getPropertyDescriptors()) {
- if (fieldName.equals(descriptor.getName()) &&
- descriptor.getWriteMethod() != null) {
-
- descriptor.getWriteMethod().invoke(
- validator.getBean(),
- result
- );
- break;
- }
- }
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("could not obtain beanInfo for " +
- valueClass.getClass() + ", reason : " +
- e.getMessage(), e);
- }
- }
- } else {
- //fixme : conversion failed, we should be able to notify ui
- // that values has changed ?
- // otherwise, bean value has not changed,...
- }
- }
-
- public static EnumSet<NuitonValidatorScope> getScopes(
- List<BeanValidatorMessage<?>> messages) {
- EnumSet<NuitonValidatorScope> result =
- EnumSet.noneOf(NuitonValidatorScope.class);
- for (BeanValidatorMessage<?> m : messages) {
- result.add(m.getScope());
- }
- return result;
- }
-
- public static EnumMap<NuitonValidatorScope, Integer> getScopesCount(
- List<BeanValidatorMessage<?>> messages) {
- EnumMap<NuitonValidatorScope, Integer> result =
- new EnumMap<NuitonValidatorScope, Integer>(NuitonValidatorScope.class);
- for (NuitonValidatorScope s : NuitonValidatorScope.values()) {
- result.put(s, 0);
- }
- for (BeanValidatorMessage<?> m : messages) {
-
- NuitonValidatorScope scope = m.getScope();
-
- result.put(scope, result.get(scope) + 1);
- }
-
- for (NuitonValidatorScope s : NuitonValidatorScope.values()) {
- if (result.get(s) == 0) {
- result.remove(s);
- }
- }
- return result;
- }
-
-}
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorEvent.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorEvent.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorEvent.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -27,7 +27,7 @@
import org.nuiton.validator.bean.AbstractValidatorEvent;
/**
- * TODO
+ * Event to be fired when some messages changed on a given field / scope of a bean.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.5.2
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorMessage.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorMessage.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/list/BeanListValidatorMessage.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -24,7 +24,6 @@
*/
import org.nuiton.validator.NuitonValidatorScope;
-import org.nuiton.validator.bean.BeanValidatorMessage;
import java.io.Serializable;
import java.util.ArrayList;
@@ -110,7 +109,7 @@
if (this == o) {
return true;
}
- if (!(o instanceof BeanValidatorMessage<?>)) {
+ if (!(o instanceof BeanListValidatorMessage<?>)) {
return false;
}
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidatorEvent.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidatorEvent.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidatorEvent.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -27,7 +27,7 @@
import org.nuiton.validator.bean.AbstractValidatorEvent;
/**
- * TODO
+ * Event to be fired when some messages changed on a given field / scope of a bean.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.5.2
Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/bean/BeanValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/bean/BeanValidatorTest.java 2012-08-11 07:54:10 UTC (rev 2394)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/bean/BeanValidatorTest.java 2012-08-11 07:54:22 UTC (rev 2395)
@@ -1,314 +0,0 @@
-/*
- * #%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.bean;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.nuiton.validator.NuitonValidatorScope;
-import org.nuiton.validator.xwork2.XWork2NuitonValidatorProvider;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @deprecated since 2.5.2.
- */
-@Deprecated
-public class BeanValidatorTest {
-
- /** Logger */
- static protected final Log log = LogFactory.getLog(BeanValidatorTest.class);
-
- protected BeanValidator<SimpleBean> validator;
-
- protected SimpleBean bean;
-
- BeanValidatorListenerImpl fatalListener;
-
- BeanValidatorListenerImpl errorListener;
-
- BeanValidatorListenerImpl warningListener;
-
- BeanValidatorListenerImpl infoListener;
-
- @Before
- public void setUp() {
-
- bean = new SimpleBean();
- }
-
- protected void prepareValidator(String context) {
-
- validator = BeanValidatorFactory.newBeanValidator(XWork2NuitonValidatorProvider.PROVIDER_NAME, SimpleBean.class, context);
-
- validator.addBeanValidatorListener(fatalListener = new BeanValidatorListenerImpl(NuitonValidatorScope.FATAL));
- validator.addBeanValidatorListener(errorListener = new BeanValidatorListenerImpl(NuitonValidatorScope.ERROR));
- validator.addBeanValidatorListener(warningListener = new BeanValidatorListenerImpl(NuitonValidatorScope.WARNING));
- validator.addBeanValidatorListener(infoListener = new BeanValidatorListenerImpl(NuitonValidatorScope.INFO));
- }
-
- @After
- public void tearDown() {
- bean = null;
- if (validator != null) {
- validator.setBean(null);
- validator = null;
- }
- }
-
- private static final String STRING_VALUE_FATAL = "stringValue.fatal";
-
- private static final String STRING_VALUE_ERROR = "stringValue.error";
-
- private static final String STRING_VALUE_WARNING = "stringValue.warning";
-
- private static final String INT_VALUE_FATAL = "intValue.fatal";
-
- private static final String INT_VALUE_ERROR = "intValue.error";
-
- private static final String INT_VALUE_INFO = "intValue.info";
-
- @Test(expected = IllegalStateException.class)
- public void testValidateWithBad() {
-
- // with marchepo context, there is a unknown field in scope error
-
- prepareValidator("marchepo");
- }
-
- @Test
- public void testValidate() {
-
- prepareValidator(null);
-
- assertMessages(fatalListener);
- assertMessages(errorListener);
- assertMessages(warningListener);
- assertMessages(infoListener);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- validator.setBean(bean);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, STRING_VALUE_ERROR, INT_VALUE_ERROR);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- bean.setStringValue("one");
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, INT_VALUE_ERROR);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- bean.setStringValue("oneone");
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, INT_VALUE_ERROR);
- assertMessages(warningListener);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- bean.setIntValue(1);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener);
- assertMessages(warningListener);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- bean.setIntValue(10);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener);
- assertMessages(warningListener);
- assertMessages(infoListener);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
-
- bean.setStringValue(null);
- bean.setIntValue(0);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, STRING_VALUE_ERROR, INT_VALUE_ERROR);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
-
- bean.setStringValue("5");
- bean.setIntValue(5);
- assertMessages(fatalListener);
- assertMessages(errorListener);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
- }
-
- @Test
- public void testConvert() {
-
-
- prepareValidator(null);
-
- assertMessages(errorListener);
- assertMessages(warningListener);
- assertMessages(infoListener);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
-
- validator.setBean(bean);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, STRING_VALUE_ERROR, INT_VALUE_ERROR);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
-
- Object value = validator.convert("intValue", "abc", Class.class);
-
- Assert.assertNull(value);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, STRING_VALUE_ERROR, "error.convertor.class");
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- bean.setStringValue("one");
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, "error.convertor.class");
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
-
- value = validator.convert("intValue", "3", Integer.class);
-
- bean.setIntValue((Integer) value);
-
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
-
- bean.setIntValue(-1);
- assertMessages(fatalListener, STRING_VALUE_FATAL, INT_VALUE_FATAL);
- assertMessages(errorListener, INT_VALUE_ERROR);
- assertMessages(warningListener, STRING_VALUE_WARNING);
- assertMessages(infoListener, INT_VALUE_INFO);
-
- if (log.isInfoEnabled()) {
- log.info("-----------------------------------------------");
- }
- }
-
- void assertMessages(BeanValidatorListenerImpl listener,
- String... expected) {
- List<String> actual = listener.getMessages();
- Assert.assertEquals(" shoudl have " +
- Arrays.toString(expected) + " but had " + actual,
- expected.length, actual.size());
- for (String m : expected) {
- Assert.assertEquals("could not find " + m + " in " + actual,
- true, actual.contains(m));
- }
- }
-
- class BeanValidatorListenerImpl implements BeanValidatorListener {
-
- final NuitonValidatorScope scope;
-
- public BeanValidatorListenerImpl(NuitonValidatorScope scope) {
- this.scope = scope;
- }
-
- List<String> messages = new ArrayList<String>();
-
- public List<String> getMessages() {
- return messages;
- }
-
- @Override
- public void onFieldChanged(BeanValidatorEvent event) {
- if (scope != event.getScope()) {
- return;
- }
- String[] messagesToDelete = event.getMessagesToDelete();
- if (messagesToDelete != null && messagesToDelete.length > 0) {
- if (log.isInfoEnabled()) {
- log.info(event.getScope() + " messages to delete : " + Arrays.toString(messagesToDelete));
- }
- for (String m : messagesToDelete) {
- messages.remove(m);
- }
- }
- String[] messagesToAdd = event.getMessagesToAdd();
- if (messagesToAdd != null && messagesToAdd.length > 0) {
- if (log.isInfoEnabled()) {
- log.info(event.getScope() + " messages to add : " + Arrays.toString(messagesToAdd));
- }
- messages.addAll(Arrays.asList(messagesToAdd));
- }
- }
- }
-}
1
0
r2394 - trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple
by tchemit@users.nuiton.org 11 Aug '12
by tchemit@users.nuiton.org 11 Aug '12
11 Aug '12
Author: tchemit
Date: 2012-08-11 09:54:10 +0200 (Sat, 11 Aug 2012)
New Revision: 2394
Url: http://nuiton.org/repositories/revision/nuiton-utils/2394
Log:
readd useful methods on SimpleBeanValidator (aka BeanValidatorutil)
Added:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java 2012-08-11 07:54:10 UTC (rev 2394)
@@ -0,0 +1,52 @@
+package org.nuiton.validator.bean.simple;
+
+import org.nuiton.validator.NuitonValidatorScope;
+
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.List;
+
+/**
+ * Useful methods arond {@link SimpleBeanValidator}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.5.4
+ */
+public class SimpleBeanValidators {
+
+ protected SimpleBeanValidators() {
+ // no constructor on helper class
+ }
+
+ public static EnumSet<NuitonValidatorScope> getScopes(
+ List<SimpleBeanValidatorMessage<?>> messages) {
+ EnumSet<NuitonValidatorScope> result =
+ EnumSet.noneOf(NuitonValidatorScope.class);
+ for (SimpleBeanValidatorMessage<?> m : messages) {
+ result.add(m.getScope());
+ }
+ return result;
+ }
+
+ public static EnumMap<NuitonValidatorScope, Integer> getScopesCount(
+ List<SimpleBeanValidatorMessage<?>> messages) {
+ EnumMap<NuitonValidatorScope, Integer> result =
+ new EnumMap<NuitonValidatorScope, Integer>(NuitonValidatorScope.class);
+ for (NuitonValidatorScope s : NuitonValidatorScope.values()) {
+ result.put(s, 0);
+ }
+ for (SimpleBeanValidatorMessage<?> m : messages) {
+
+ NuitonValidatorScope scope = m.getScope();
+
+ result.put(scope, result.get(scope) + 1);
+ }
+
+ for (NuitonValidatorScope s : NuitonValidatorScope.values()) {
+ if (result.get(s) == 0) {
+ result.remove(s);
+ }
+ }
+ return result;
+ }
+}
Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/bean/simple/SimpleBeanValidators.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
r2393 - in trunk: . nuiton-csv nuiton-profiling nuiton-utils nuiton-utils-maven-report-plugin nuiton-validator
by tchemit@users.nuiton.org 11 Aug '12
by tchemit@users.nuiton.org 11 Aug '12
11 Aug '12
Author: tchemit
Date: 2012-08-11 09:52:34 +0200 (Sat, 11 Aug 2012)
New Revision: 2393
Url: http://nuiton.org/repositories/revision/nuiton-utils/2393
Log:
bump to version 2.6-SNAPSHOT
Modified:
trunk/nuiton-csv/pom.xml
trunk/nuiton-profiling/pom.xml
trunk/nuiton-utils-maven-report-plugin/pom.xml
trunk/nuiton-utils/pom.xml
trunk/nuiton-validator/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-csv/pom.xml
===================================================================
--- trunk/nuiton-csv/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
+++ trunk/nuiton-csv/pom.xml 2012-08-11 07:52:34 UTC (rev 2393)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.4-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<artifactId>nuiton-csv</artifactId>
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
+++ trunk/nuiton-profiling/pom.xml 2012-08-11 07:52:34 UTC (rev 2393)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.4-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<artifactId>nuiton-profiling</artifactId>
Modified: trunk/nuiton-utils/pom.xml
===================================================================
--- trunk/nuiton-utils/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
+++ trunk/nuiton-utils/pom.xml 2012-08-11 07:52:34 UTC (rev 2393)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.4-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<artifactId>nuiton-utils</artifactId>
Modified: trunk/nuiton-utils-maven-report-plugin/pom.xml
===================================================================
--- trunk/nuiton-utils-maven-report-plugin/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
+++ trunk/nuiton-utils-maven-report-plugin/pom.xml 2012-08-11 07:52:34 UTC (rev 2393)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.4-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<artifactId>nuiton-utils-maven-report-plugin</artifactId>
Modified: trunk/nuiton-validator/pom.xml
===================================================================
--- trunk/nuiton-validator/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
+++ trunk/nuiton-validator/pom.xml 2012-08-11 07:52:34 UTC (rev 2393)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.4-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<artifactId>nuiton-validator</artifactId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
+++ trunk/pom.xml 2012-08-11 07:52:34 UTC (rev 2393)
@@ -27,11 +27,11 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.3.5</version>
+ <version>3.3.6</version>
</parent>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.4-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
<modules>
<module>nuiton-utils</module>
1
0
r2392 - in trunk: . nuiton-csv nuiton-profiling nuiton-utils nuiton-utils-maven-report-plugin nuiton-validator
by maven-release@users.nuiton.org 08 Aug '12
by maven-release@users.nuiton.org 08 Aug '12
08 Aug '12
Author: maven-release
Date: 2012-08-08 10:43:14 +0200 (Wed, 08 Aug 2012)
New Revision: 2392
Url: http://nuiton.org/repositories/revision/nuiton-utils/2392
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/nuiton-csv/pom.xml
trunk/nuiton-profiling/pom.xml
trunk/nuiton-utils-maven-report-plugin/pom.xml
trunk/nuiton-utils/pom.xml
trunk/nuiton-validator/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-csv/pom.xml
===================================================================
--- trunk/nuiton-csv/pom.xml 2012-08-08 08:43:12 UTC (rev 2391)
+++ trunk/nuiton-csv/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4-SNAPSHOT</version>
</parent>
<artifactId>nuiton-csv</artifactId>
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2012-08-08 08:43:12 UTC (rev 2391)
+++ trunk/nuiton-profiling/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4-SNAPSHOT</version>
</parent>
<artifactId>nuiton-profiling</artifactId>
Modified: trunk/nuiton-utils/pom.xml
===================================================================
--- trunk/nuiton-utils/pom.xml 2012-08-08 08:43:12 UTC (rev 2391)
+++ trunk/nuiton-utils/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4-SNAPSHOT</version>
</parent>
<artifactId>nuiton-utils</artifactId>
Modified: trunk/nuiton-utils-maven-report-plugin/pom.xml
===================================================================
--- trunk/nuiton-utils-maven-report-plugin/pom.xml 2012-08-08 08:43:12 UTC (rev 2391)
+++ trunk/nuiton-utils-maven-report-plugin/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4-SNAPSHOT</version>
</parent>
<artifactId>nuiton-utils-maven-report-plugin</artifactId>
Modified: trunk/nuiton-validator/pom.xml
===================================================================
--- trunk/nuiton-validator/pom.xml 2012-08-08 08:43:12 UTC (rev 2391)
+++ trunk/nuiton-validator/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4-SNAPSHOT</version>
</parent>
<artifactId>nuiton-validator</artifactId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-08 08:43:12 UTC (rev 2391)
+++ trunk/pom.xml 2012-08-08 08:43:14 UTC (rev 2392)
@@ -31,7 +31,7 @@
</parent>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3</version>
+ <version>2.5.4-SNAPSHOT</version>
<modules>
<module>nuiton-utils</module>
@@ -317,12 +317,12 @@
<scm>
<connection>
- scm:svn:http://svn.nuiton.org/svn/nuiton-utils/tags/nuiton-utils-2.5.3
+ scm:svn:http://svn.nuiton.org/svn/nuiton-utils/trunk
</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/nuiton-utils/tags/nuiton-utils-2.5.3
+ scm:svn:http://svn.nuiton.org/svn/nuiton-utils/trunk
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/nuiton-utils/tags/nuiton-utils-2.…</url>
+ <url>http://www.nuiton.org/repositories/browse/nuiton-utils/trunk</url>
</scm>
<distributionManagement>
1
0
Author: maven-release
Date: 2012-08-08 10:43:12 +0200 (Wed, 08 Aug 2012)
New Revision: 2391
Url: http://nuiton.org/repositories/revision/nuiton-utils/2391
Log:
[maven-release-plugin] copy for tag nuiton-utils-2.5.3
Added:
tags/nuiton-utils-2.5.3/
Property changes on: tags/nuiton-utils-2.5.3
___________________________________________________________________
Added: svn:ignore
+ target
velocity.log
maven.log
.eclipse
.classpath
*.iml
*.ipr
*.iws
.settings
.project
testdir
Added: svn:mergeinfo
+
1
0
r2390 - in trunk: . nuiton-csv nuiton-profiling nuiton-utils nuiton-utils-maven-report-plugin nuiton-validator
by maven-release@users.nuiton.org 08 Aug '12
by maven-release@users.nuiton.org 08 Aug '12
08 Aug '12
Author: maven-release
Date: 2012-08-08 10:43:10 +0200 (Wed, 08 Aug 2012)
New Revision: 2390
Url: http://nuiton.org/repositories/revision/nuiton-utils/2390
Log:
[maven-release-plugin] prepare release nuiton-utils-2.5.3
Modified:
trunk/nuiton-csv/pom.xml
trunk/nuiton-profiling/pom.xml
trunk/nuiton-utils-maven-report-plugin/pom.xml
trunk/nuiton-utils/pom.xml
trunk/nuiton-validator/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-csv/pom.xml
===================================================================
--- trunk/nuiton-csv/pom.xml 2012-08-08 08:41:35 UTC (rev 2389)
+++ trunk/nuiton-csv/pom.xml 2012-08-08 08:43:10 UTC (rev 2390)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3-SNAPSHOT</version>
+ <version>2.5.3</version>
</parent>
<artifactId>nuiton-csv</artifactId>
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2012-08-08 08:41:35 UTC (rev 2389)
+++ trunk/nuiton-profiling/pom.xml 2012-08-08 08:43:10 UTC (rev 2390)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3-SNAPSHOT</version>
+ <version>2.5.3</version>
</parent>
<artifactId>nuiton-profiling</artifactId>
Modified: trunk/nuiton-utils/pom.xml
===================================================================
--- trunk/nuiton-utils/pom.xml 2012-08-08 08:41:35 UTC (rev 2389)
+++ trunk/nuiton-utils/pom.xml 2012-08-08 08:43:10 UTC (rev 2390)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3-SNAPSHOT</version>
+ <version>2.5.3</version>
</parent>
<artifactId>nuiton-utils</artifactId>
Modified: trunk/nuiton-utils-maven-report-plugin/pom.xml
===================================================================
--- trunk/nuiton-utils-maven-report-plugin/pom.xml 2012-08-08 08:41:35 UTC (rev 2389)
+++ trunk/nuiton-utils-maven-report-plugin/pom.xml 2012-08-08 08:43:10 UTC (rev 2390)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3-SNAPSHOT</version>
+ <version>2.5.3</version>
</parent>
<artifactId>nuiton-utils-maven-report-plugin</artifactId>
Modified: trunk/nuiton-validator/pom.xml
===================================================================
--- trunk/nuiton-validator/pom.xml 2012-08-08 08:41:35 UTC (rev 2389)
+++ trunk/nuiton-validator/pom.xml 2012-08-08 08:43:10 UTC (rev 2390)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3-SNAPSHOT</version>
+ <version>2.5.3</version>
</parent>
<artifactId>nuiton-validator</artifactId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-08 08:41:35 UTC (rev 2389)
+++ trunk/pom.xml 2012-08-08 08:43:10 UTC (rev 2390)
@@ -31,7 +31,7 @@
</parent>
<artifactId>nuiton-utils-parent</artifactId>
- <version>2.5.3-SNAPSHOT</version>
+ <version>2.5.3</version>
<modules>
<module>nuiton-utils</module>
@@ -317,12 +317,12 @@
<scm>
<connection>
- scm:svn:http://svn.nuiton.org/svn/nuiton-utils/trunk
+ scm:svn:http://svn.nuiton.org/svn/nuiton-utils/tags/nuiton-utils-2.5.3
</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/nuiton-utils/trunk
+ scm:svn:http://svn.nuiton.org/svn/nuiton-utils/tags/nuiton-utils-2.5.3
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/nuiton-utils/trunk</url>
+ <url>http://www.nuiton.org/repositories/browse/nuiton-utils/tags/nuiton-utils-2.…</url>
</scm>
<distributionManagement>
1
0
r2389 - trunk/nuiton-utils/src/main/java/org/nuiton/util/converter
by tchemit@users.nuiton.org 08 Aug '12
by tchemit@users.nuiton.org 08 Aug '12
08 Aug '12
Author: tchemit
Date: 2012-08-08 10:41:35 +0200 (Wed, 08 Aug 2012)
New Revision: 2389
Url: http://nuiton.org/repositories/revision/nuiton-utils/2389
Log:
add missing svn properties and license header
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ColorConverter.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ColorConverter.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ColorConverter.java 2012-08-07 07:51:22 UTC (rev 2388)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ColorConverter.java 2012-08-08 08:41:35 UTC (rev 2389)
@@ -1,4 +1,27 @@
package org.nuiton.util.converter;
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 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%
+ */
import org.apache.commons.beanutils.ConversionException;
Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/converter/ColorConverter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0