mcconnell 2003/12/01 23:35:53
Modified: repository/spi/src/java/org/apache/avalon/repository/criteria
Criteria.java
Log:
Move value resolution to the Parameter class.
Revision Changes Path
1.6 +3 -65
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Criteria.java
Index: Criteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/criteria/Criteria.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Criteria.java 26 Nov 2003 17:05:47 -0000 1.5
+++ Criteria.java 2 Dec 2003 07:35:53 -0000 1.6
@@ -110,7 +110,7 @@
public void put( final String key, final Object value )
{
final Parameter p = getParameter( key );
- final Object v = resolveValue( p, value );
+ final Object v = p.resolve( value );
super.put( key, v );
}
@@ -170,52 +170,7 @@
private Object resolveValue( Parameter param, Object value )
throws ValidationException
{
- if( value == null ) return null;
- Class c = getParameterClass( param );
- if( c.isInstance( value ) )
- {
- return value;
- }
- else
- {
- Constructor constructor = null;
- try
- {
- constructor =
- c.getConstructor(
- new Class[]{ value.getClass() } );
- }
- catch( NoSuchMethodException nsme )
- {
- final String error =
- "Value of class: ["
- + value.getClass().getName()
- + "] supplied for key ["
- + param.getKey()
- + "] is not an instance of type: ["
- + param.getClassname()
- + "].";
- throw new IllegalArgumentException( error );
- }
-
- try
- {
- return constructor.newInstance(
- new Object[]{ value } );
- }
- catch( Throwable e )
- {
- final String error =
- "Value of class: ["
- + value.getClass().getName()
- + "] supplied for key ["
- + param.getKey()
- + "] is not an instance of or was not resolvable to the type: ["
- + param.getClassname()
- + "].";
- throw new ValidationException( error, e );
- }
- }
+ return param.resolve( value );
}
private Parameter getParameterFromObject( Object key )
@@ -227,23 +182,6 @@
else
{
return getParameter( key.toString() );
- }
- }
-
- private Class getParameterClass( Parameter param )
- throws ValidationException
- {
- try
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- return loader.loadClass( param.getClassname() );
- }
- catch( Throwable e )
- {
- final String error =
- "Unable to resolve parameter class: "
- + param.getClassname();
- throw new ValidationException( error, e );
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]