[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Mon Jun 25 20:59:34 EDT 2007
User: gavin
Date: 07/06/25 20:59:34
Modified: src/main/org/jboss/seam/core Validators.java
Log:
get rid of non-dynamic-locale aware validator
Revision Changes Path
1.12 +19 -37 jboss-seam/src/main/org/jboss/seam/core/Validators.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Validators.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Validators.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- Validators.java 24 Jun 2007 22:24:50 -0000 1.11
+++ Validators.java 26 Jun 2007 00:59:34 -0000 1.12
@@ -3,10 +3,10 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.beans.FeatureDescriptor;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.el.ELContext;
import javax.el.ELException;
@@ -19,7 +19,6 @@
import org.hibernate.validator.InvalidValue;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.Seam;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
@@ -40,15 +39,20 @@
public class Validators
{
+ //TODO: should use weak references here...
+ private Map<Key, ClassValidator> classValidators = new ConcurrentHashMap<Key, ClassValidator>();
+
class Key
{
private Class validatableClass;
private java.util.Locale locale;
+
public Key(Class validatableClass, java.util.Locale locale)
{
this.validatableClass = validatableClass;
this.locale = locale;
}
+
@Override
public boolean equals(Object other)
{
@@ -56,6 +60,7 @@
return key.validatableClass.equals(validatableClass)
&& key.locale.equals(locale);
}
+
@Override
public int hashCode()
{
@@ -63,62 +68,39 @@
}
}
- //TODO: should use weak references here...
- //TODO: use Model.forClass(...) instead!!
- private Map<Key, ClassValidator> classValidators = Collections.synchronizedMap( new HashMap<Key, ClassValidator>() );
-
/**
* Get the cached ClassValidator instance.
*
* @param modelClass the class to be validated
- * @param name the component name
*/
- public <T> ClassValidator<T> getValidator(Class<T> modelClass, String name)
+ public <T> ClassValidator<T> getValidator(Class<T> modelClass)
{
- Key key = new Key( modelClass, ResourceBundle.instance().getLocale() );
- //TODO: use Model.forClass(...) instead!!
+ java.util.ResourceBundle bundle = ResourceBundle.instance();
+ Locale none = bundle==null ? new Locale("NONE") : bundle.getLocale();
+ Key key = new Key( modelClass, none );
ClassValidator result = classValidators.get(key);
if (result==null)
{
- result = createValidator(modelClass, name);
+ result = createValidator(modelClass);
classValidators.put(key, result);
}
return result;
}
/**
- * Get the cached ClassValidator instance.
- *
- * @param modelClass the class to be validated
- */
- public <T> ClassValidator<T> getValidator(Class<T> modelClass)
- {
- return getValidator(modelClass, null);
- }
-
- /**
* Create a new ClassValidator, or get it from the
* Component object for the default role of the
* class.
*
* @param modelClass the class to be validated
- * @param name the component name
*/
- protected ClassValidator createValidator(Class modelClass, String name)
- {
- Component component = name==null ? null : Component.forName(name);
- if (component==null)
+ protected <T> ClassValidator<T> createValidator(Class<T> modelClass)
{
java.util.ResourceBundle bundle = ResourceBundle.instance();
return bundle==null ?
new ClassValidator(modelClass) :
new ClassValidator(modelClass, bundle);
}
- else
- {
- return component.getValidator();
- }
- }
/**
* Validate that the given value can be assigned to the property given by the value
@@ -192,7 +174,7 @@
if (base!=null && property!=null )
{
context.setPropertyResolved(true);
- invalidValues = getValidator( base.getClass(), Seam.getComponentName( base.getClass() ) )
+ invalidValues = getValidator( base.getClass() )
.getPotentialInvalidValues( property.toString(), value );
}
More information about the jboss-cvs-commits
mailing list