mcconnell 2003/11/25 10:57:30
Modified: kernel/impl project.xml
kernel/impl/conf merlin.properties
kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
DefaultCriteria.java
Log:
Sync. with defaults and repo changes.
Revision Changes Path
1.7 +1 -1 avalon-sandbox/kernel/impl/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/impl/project.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- project.xml 24 Nov 2003 21:26:36 -0000 1.6
+++ project.xml 25 Nov 2003 18:57:29 -0000 1.7
@@ -163,7 +163,7 @@
<dependency>
<groupId>avalon-util</groupId>
<artifactId>avalon-util-defaults</artifactId>
- <version>1.0-dev</version>
+ <version>1.1-dev</version>
</dependency>
<dependency>
<groupId>avalon-util</groupId>
1.2 +1 -1 avalon-sandbox/kernel/impl/conf/merlin.properties
Index: merlin.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/impl/conf/merlin.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- merlin.properties 24 Nov 2003 22:09:58 -0000 1.1
+++ merlin.properties 25 Nov 2003 18:57:29 -0000 1.2
@@ -22,7 +22,7 @@
# A url to the default location of the merlin kernel
# configuration file.
#
-merlin.kernel = ${merlin.config}/kernel.xml
+merlin.kernel = file:///${merlin.config}/kernel.xml
#----------------------------------------------------------------------
1.6 +32 -114
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java
Index: DefaultCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultCriteria.java 24 Nov 2003 22:09:13 -0000 1.5
+++ DefaultCriteria.java 25 Nov 2003 18:57:30 -0000 1.6
@@ -64,6 +64,7 @@
import org.apache.avalon.repository.criteria.Criteria;
import org.apache.avalon.repository.criteria.ValidationException;
import org.apache.avalon.repository.criteria.Parameter;
+import org.apache.avalon.repository.criteria.AbstractCriteria;
import org.apache.avalon.defaults.Defaults;
import org.apache.avalon.defaults.DefaultsFinder;
@@ -80,7 +81,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision$
*/
-public class DefaultCriteria implements KernelCriteria
+public class DefaultCriteria extends AbstractCriteria implements KernelCriteria
{
//--------------------------------------------------------------
// static
@@ -119,6 +120,8 @@
*/
public DefaultCriteria()
{
+ super( PARAMS );
+
Properties avalon = getStaticProperties( AVALON );
Properties merlin = getStaticProperties( MERLIN );
Properties env = getEnvinronment();
@@ -148,6 +151,30 @@
printProperties( defaults, "defaults (resolved)" );
System.out.print( "" );
+ //
+ // following aquistion of the default parameters we need to assign
+ // them as criteria values before we expose the criteria instance to the
+ // client
+ //
+
+ StringBuffer errors = new StringBuffer();
+ for( int i=0; i<PARAMS.length; i++ )
+ {
+ Parameter param = PARAMS[i];
+ final String key = param.getKey();
+ try
+ {
+ setValue( key, defaults.getProperty( key ));
+ }
+ catch( Exception re )
+ {
+ final String error =
+ "Unable to set the default value for the property: " + key
+ + " due to an enexpected error.";
+ System.out.println( error );
+ re.printStackTrace();
+ }
+ }
}
private void printProperties( Properties properties, String label )
@@ -192,116 +219,20 @@
//--------------------------------------------------------------
/**
- * Return the template backing the criteria.
- * @return the template
+ * Return the set of parameters backing this criteria.
+ * @return the parameters
*/
public Parameter[] getParameters()
{
return PARAMS;
}
- /**
- * Set a named parameter of the criteria to a value.
- * @param key the parameter key
- * @param value the value to assign to the key
- * @exception ValidationException if the supplied value fails
- * the validation test for its associated parameter
- */
- public void setValue( final String key, final Object value )
- throws ValidationException
- {
- Parameter p = getParameter( key );
- verify( p, value );
- m_bindings.put( key, value );
- }
-
- /**
- * Return the currently assigned value for a key.
- * @return the assigned value
- */
- public Object getValue( final String key )
- {
- getParameter( key ); // verify key
- return m_bindings.get( key );
- }
-
- /**
- * Return the current state of the criteria as a map.
- * @return the criteria as a map
- */
- public Map getMap()
- {
- Hashtable map = new Hashtable();
- for( int i=0; i<PARAMS.length; i++ )
- {
- final String key = PARAMS[i].getKey();
- Object value = m_bindings.get( key );
- if( value != null )
- {
- map.put( key, value );
- }
- }
- return map;
- }
-
public String toString()
{
return "[merlin: " + getMap() + "]";
}
/**
- * Verify a value relative to the parameter constraints.
- * @param value the value to verify
- * @exception ValidationException if the value is invalid
- */
- public void verify( Parameter param, Object value )
- throws ValidationException
- {
- Class c = getParameterClass( param );
- if( value == null ) return;
- if( !c.isInstance( value ) )
- {
- final String error =
- "Value of class: ["
- + value.getClass().getName()
- + "] supplied for key ["
- + param.getKey()
- + "] is not an instance of type: ["
- + param.getClassname()
- + "].";
- throw new ValidationException( error );
- }
- }
-
- 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 );
- }
- }
-
- public Parameter getParameter( final String key )
- {
- for( int i=0; i<PARAMS.length; i++ )
- {
- Parameter parameter = PARAMS[i];
- if( parameter.getKey().equals( key ) ) return parameter;
- }
- final String error = "Unknown key: [" + key + "].";
- throw new IllegalArgumentException( error );
- }
-
- /**
* Read in the static defined properties that contribute to
* the default context value establishment.
*
@@ -311,23 +242,11 @@
*/
private Properties getStaticProperties( String path ) throws
KernelRuntimeException
{
+
Properties bootstrap = new Properties();
try
{
- InputStream input =
- DefaultCriteria.class.getResourceAsStream( path );
- if( input == null )
- {
- final String error =
- "Internal error, unable to locate enbedded resource: "
- + path
- + " from the resource: "
- + DefaultCriteria.class.getProtectionDomain()
- .getCodeSource().getLocation();
- throw new IllegalStateException( error );
- }
- bootstrap.load( input );
- return bootstrap;
+ return Defaults.getStaticProperties( DefaultCriteria.class, path );
}
catch ( IOException e )
{
@@ -336,5 +255,4 @@
+ path, e );
}
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]