adammurdoch 02/02/25 02:42:45
Modified: proposal/myrmidon build.xml
proposal/myrmidon/src/java/org/apache/myrmidon/api
AbstractTask.java TaskContext.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer
ClassicConfigurer.java DefaultConfigurer.java
Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/components/converter
DefaultMasterConverter.java Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
DefaultDeployer.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
DefaultEmbeddor.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
DefaultExecutor.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/type
MultiSourceTypeFactory.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace
DefaultTaskContext.java DefaultWorkspace.java
Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/framework
AbstractContainerTask.java
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer
Configurer.java
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role
RoleInfo.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional
Script.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit
JUnitTask.java
proposal/myrmidon/src/main/org/apache/tools/ant/types/converters
StringToPathConverter.java
proposal/myrmidon/src/manifest core-services.xml
proposal/myrmidon/src/testcases/org/apache/myrmidon
AbstractProjectTest.java
proposal/myrmidon/src/testcases/org/apache/myrmidon/components
AbstractComponentTest.java
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer
ConfigTest4.java DefaultConfigurerTest.java
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer
DefaultDeployerTest.java TestConverter1.java
Added: proposal/myrmidon/src/java/org/apache/myrmidon/api
Context.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace
PropertyUtil.java
proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories
ExecManagerFactory.java Resources.properties
VfsManagerFactory.java
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer
ConfigTestConfigProps.java
ConfigTestConfigurable.java
ConfigTestInterfaceProp.java
ConfigTestMultiSetter.java
ConfigTestMultiTypedAdder.java
ConfigTestObjectProps.java
ConfigTestPrimConvert.java
ConfigTestStringProps.java
ConfigTestTypedConfigProp.java
ConfigTestTypedProp.java MyRole1Adaptor.java
ObjectToMyRole1Converter.java
Removed:
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer
PropertyException.java PropertyUtil.java
proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys
ExecManagerFactory.java Resources.properties
VfsManagerFactory.java
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer
TaskContextAdapter.java
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/converter
MasterConverter.java
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer
ConfigTest1.java ConfigTest10.java ConfigTest2.java
ConfigTest3.java ConfigTest5.java ConfigTest6.java
ConfigTest7.java ConfigTest8.java ConfigTest9.java
StringToMyRole1Converter.java
Log:
Replaced usage of Avalon Context with Myrmidon specific Context:
* Moved read-only property and resolve methods from TaskContext to new Context
interface. TaskContext now extends the new Context interface.
* Changed the Configurer methods to use the new Context. Both implementations
use the supplied Context to do property resolution.
* Renamed TaskContext.getPropertys() -> getProperties().
* Moved PropertyUtil from configurer to workspace package, as that is now
the only place it is used.
* Changed PropertyUtil to work with the new Context.
RoleManager:
* A default implementation for a role can now be specified. Currently
can only do this programatically.
DefaultMasterConverter:
* Removed MasterConverter interface. It is now identified by the Converter
role.
* Now caches the converter instances.
* Changed the converter search algorithm to traverse the *source* class
hierarchy, including all interfaces. Chooses the most specialised
conversion, and fails if there is more than one such choice.
DefaultConfigurer:
* Attempts to convert references, if the type does not match the expected
type.
* Changed handling of nested elements, for named adders/setters:
* If the method type can be mapped to a role, and that role has a default
implementation, then use that default implementation.
* Otherwise, if the method type is an interface, fail.
* Otherwise, create an instance using no-args constructor.
* Changed handling of nested elements, for typed adders/setters:
* If the method type can be mapped to a role, and the element name is
a type of that role, then use that role to create the instance.
* Otherwise, use the type factory for the generic data-type role.
* Attempt to convert the instance if it is not of the expected type.
* Added a bunch of test cases for new functionality.
* Renamed all the ConfigTest classes to have descriptive names.
Misc:
* Renamed package framework.factorys -> framework.factories.
* Made tests work when fork = false.
Revision Changes Path
1.62 +2 -2 jakarta-ant/proposal/myrmidon/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- build.xml 21 Feb 2002 03:26:23 -0000 1.61
+++ build.xml 25 Feb 2002 10:42:43 -0000 1.62
@@ -455,11 +455,11 @@
</jar>
<junit printsummary="on"
- fork="true">
+ fork="false">
<formatter type="brief" usefile="false"/>
<classpath>
<fileset dir="${test.working.dir}/dist/bin/lib"
includes="**/*.jar"/>
- <fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar,
**/*.atl"/>
+ <fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar,
**/*.atl" excludes="crimson.jar"/>
</classpath>
<classpath location="${test.classes}"/>
1.22 +2 -3
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java
Index: AbstractTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- AbstractTask.java 21 Feb 2002 09:35:13 -0000 1.21
+++ AbstractTask.java 25 Feb 2002 10:42:43 -0000 1.22
@@ -14,7 +14,7 @@
* This is the class that Task writers should extend to provide custom tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.21 $ $Date: 2002/02/21 09:35:13 $
+ * @version $Revision: 1.22 $ $Date: 2002/02/25 10:42:43 $
*/
public abstract class AbstractTask
extends AbstractLogEnabled
@@ -37,8 +37,7 @@
/**
* Execute task.
* This method is called to perform actual work associated with task.
- * It is called after Task has been Configured and Initialized and before
- * beig Disposed (If task implements appropriate interfaces).
+ * It is called after Task has been configured.
*
* @exception TaskException if an error occurs
*/
1.20 +2 -29
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java
Index: TaskContext.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- TaskContext.java 21 Feb 2002 09:29:53 -0000 1.19
+++ TaskContext.java 25 Feb 2002 10:42:43 -0000 1.20
@@ -8,7 +8,6 @@
package org.apache.myrmidon.api;
import java.io.File;
-import java.util.Map;
import org.apache.avalon.framework.Enum;
/**
@@ -18,9 +17,10 @@
* Unlike other APIs the Logging is provided through another interface
(LogEnabled).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.19 $ $Date: 2002/02/21 09:29:53 $
+ * @version $Revision: 1.20 $ $Date: 2002/02/25 10:42:43 $
*/
public interface TaskContext
+ extends Context
{
//these values are used when setting properties to indicate the scope at
//which properties are set
@@ -71,33 +71,6 @@
*/
File resolveFile( String filename )
throws TaskException;
-
- /**
- * Resolve a value according to the context.
- * This involves evaluating the string and thus removing
- * ${} sequences according to the rules specified at
- * ............
- *
- * @param value the value to resolve
- * @return the resolved value
- */
- Object resolveValue( String value )
- throws TaskException;
-
- /**
- * Retrieve property for name.
- *
- * @param name the name of property
- * @return the value of property
- */
- Object getProperty( String name );
-
- /**
- * Retrieve a copy of all the properties accessible via context.
- *
- * @return the map of all property names to values
- */
- Map getPropertys();
/**
* Set property value in current context.
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/Context.java
Index: Context.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.api;
import java.util.Map;
/**
* A context - a set of named properties.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:43 $
*/
public interface Context
{
/**
* Resolve a value according to the context.
* This involves evaluating the string and replacing
* ${} sequences with property values.
*
* @param value the value to resolve
* @return the resolved value
*/
Object resolveValue( String value )
throws TaskException;
/**
* Retrieve property for name.
*
* @param name the name of property
* @return the value of property, or null if the property has no value.
*/
Object getProperty( String name );
/**
* Retrieve a copy of all the properties accessible via context.
*
* @return the map of all property names to values
*/
Map getProperties();
}
1.6 +10 -11
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java
Index: ClassicConfigurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ClassicConfigurer.java 21 Feb 2002 11:06:40 -0000 1.5
+++ ClassicConfigurer.java 25 Feb 2002 10:42:43 -0000 1.6
@@ -10,20 +10,21 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import org.apache.aut.converter.Converter;
+import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.aut.converter.ConverterException;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.myrmidon.api.Context;
+import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.configurer.Configurer;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
/**
* Class used to configure tasks.
@@ -41,12 +42,12 @@
private static final boolean DEBUG = false;
///Converter to use for converting between values
- private MasterConverter m_converter;
+ private Converter m_converter;
public void service( final ServiceManager serviceManager )
throws ServiceException
{
- m_converter = (MasterConverter)serviceManager.lookup(
MasterConverter.ROLE );
+ m_converter = (Converter)serviceManager.lookup( Converter.ROLE );
}
/**
@@ -216,16 +217,14 @@
{
try
{
- final Object objectValue =
- PropertyUtil.resolveProperty( value, context, false );
-
+ final Object objectValue = context.resolveValue( value );
setValue( object, objectValue, methods, context );
}
- catch( final PropertyException pe )
+ catch( final TaskException te )
{
final String message =
REZ.getString( "bad-property-resolve.error", value );
- throw new ConfigurationException( message, pe );
+ throw new ConfigurationException( message, te );
}
}
1.32 +89 -56
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java
Index: DefaultConfigurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DefaultConfigurer.java 24 Feb 2002 07:52:08 -0000 1.31
+++ DefaultConfigurer.java 25 Feb 2002 10:42:43 -0000 1.32
@@ -9,22 +9,21 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.aut.converter.Converter;
+import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Resolvable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
+import org.apache.myrmidon.api.Context;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.configurer.Configurer;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.TypeFactory;
@@ -34,7 +33,7 @@
* Class used to configure tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.31 $ $Date: 2002/02/24 07:52:08 $
+ * @version $Revision: 1.32 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultConfigurer
extends AbstractLogEnabled
@@ -44,7 +43,7 @@
ResourceManager.getPackageResources( DefaultConfigurer.class );
///Converter to use for converting between values
- private MasterConverter m_converter;
+ private Converter m_converter;
//TypeManager to use to create types in typed adders
private TypeManager m_typeManager;
@@ -59,7 +58,7 @@
public void service( final ServiceManager serviceManager )
throws ServiceException
{
- m_converter = (MasterConverter)serviceManager.lookup(
MasterConverter.ROLE );
+ m_converter = (Converter)serviceManager.lookup( Converter.ROLE );
m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE
);
m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE
);
}
@@ -140,7 +139,7 @@
{
final String message =
REZ.getString( "no-such-attribute.error", elemName,
name );
- throw new ReportableConfigurationException( message,
nspe );
+ throw new ReportableConfigurationException( message );
}
catch( final Exception ce )
{
@@ -187,7 +186,7 @@
{
final String message =
REZ.getString( "no-such-element.error", elemName,
name );
- throw new ReportableConfigurationException( message,
nspe );
+ throw new ReportableConfigurationException( message );
}
catch( final ReportableConfigurationException ce )
{
@@ -349,26 +348,29 @@
= getConfigurerFromName( state.getConfigurer(), name, false );
// Resolve any props in the id
- Object id = PropertyUtil.resolveProperty( unresolvedId, context,
false );
+ String id = context.resolveValue( unresolvedId ).toString();
// Locate the referenced object
- Object ref = null;
- try
- {
- ref = context.get( id );
- }
- catch( final ContextException e )
+ Object ref = context.getProperty( id );
+ if( ref == null )
{
final String message = REZ.getString( "unknown-reference.error",
id );
- throw new ConfigurationException( message, e );
+ throw new ConfigurationException( message );
}
- // Check the types
+ // Convert the object, if necessary
final Class type = childConfigurer.getType();
if( !type.isInstance( ref ) )
{
- final String message = REZ.getString(
"mismatch-ref-types.error", id, type.getName(), ref.getClass().getName() );
- throw new ConfigurationException( message );
+ try
+ {
+ ref = m_converter.convert( type, ref, context );
+ }
+ catch( ConverterException e )
+ {
+ final String message = REZ.getString(
"mismatch-ref-types.error", id, name );
+ throw new ConfigurationException( message, e );
+ }
}
// Set the child element
@@ -408,17 +410,14 @@
throws Exception
{
// Resolve property references in the attribute value
- Object objValue = PropertyUtil.resolveProperty( value, context,
false );
+ Object objValue = context.resolveValue( value );
// Convert the value to the appropriate type
-
- Object converterContext = context;
- if( context instanceof Resolvable )
+ final Class type = setter.getType();
+ if( ! type.isInstance( objValue ) )
{
- converterContext = ( (Resolvable)context ).resolve( context );
+ objValue = m_converter.convert( type, objValue, context );
}
- final Class clazz = setter.getType();
- objValue = m_converter.convert( clazz, objValue, converterContext );
// Set the value
setter.addValue( state, objValue );
@@ -451,27 +450,38 @@
{
final String name = element.getName();
final Class type = childConfigurer.getType();
- Object child = childConfigurer.createValue( state );
- if( null == child && Configuration.class == type )
+ if( Configuration.class == type )
{
//special case where you have add...(Configuration)
return element;
}
- else if( null == child )
+
+ // Create an instance
+ Object child = childConfigurer.createValue( state );
+ if( null == child )
{
- // Create an instance
- if( type.isInterface() )
+ if( childConfigurer == state.getConfigurer().getTypedProperty() )
{
- child = createdTypedObject( name, type );
+ // Typed property
+ child = createTypedObject( name, type );
}
else
{
- child = createObject( type );
+ // Named property
+ child = createNamedObject( type );
}
}
+ // Configure the object
configureObject( child, element, context );
+
+ // Convert the object, if necessary
+ if( ! type.isInstance( child ) )
+ {
+ child = m_converter.convert( type, child, context );
+ }
+
return child;
}
@@ -521,38 +531,61 @@
}
/**
- * Utility method to create an instance of the
- * specified type that satisfies supplied interface.
+ * Creates an instance for a named property.
*/
- private Object createdTypedObject( final String name,
- final Class type )
+ private Object createNamedObject( final Class type )
throws Exception
{
- // Attempt to create the object
- final Object obj;
- try
- {
- final TypeFactory factory = m_typeManager.getFactory(
DataType.class );
- obj = factory.create( name );
+ // Map the expected type to a role. If found, instantiate the
default
+ // type for that role
+ final RoleInfo roleInfo = m_roleManager.getRoleByType( type );
+ if( roleInfo != null ) {
+ final String typeName = roleInfo.getDefaultType();
+ if( typeName != null )
+ {
+ // Create the instance
+ final TypeFactory factory = m_typeManager.getFactory(
roleInfo.getType() );
+ return factory.create( typeName );
+ }
}
- catch( final Exception e )
+
+ if( type.isInterface() )
{
- final String message =
- REZ.getString( "create-typed-object.error",
- name,
- type.getName() );
- throw new ConfigurationException( message, e );
+ // An interface - don't know how to instantiate it
+ final String message = REZ.getString(
"instantiate-interface.error", type.getName() );
+ throw new ConfigurationException( message );
}
- // Check the types
- if( !type.isInstance( obj ) )
+ // Use the no-args constructor
+ return createObject( type );
+ }
+
+ /**
+ * Creates an instance of the typed property.
+ */
+ private Object createTypedObject( final String name,
+ final Class type )
+ throws Exception
+ {
+ // Map the expected type to a role. If found, attempt to create
+ // an instance
+ final RoleInfo roleInfo = m_roleManager.getRoleByType( type );
+ if( roleInfo != null )
{
- final String message =
- REZ.getString( "mismatched-typed-object.error", name,
type.getName() );
- throw new ConfigurationException( message );
+ final TypeFactory factory = m_typeManager.getFactory(
roleInfo.getType() );
+ if( factory.canCreate( name ) )
+ {
+ return factory.create( name );
+ }
}
- return obj;
+ // Use the generic 'data-type' role.
+ final TypeFactory factory = m_typeManager.getFactory( DataType.class
);
+ if( ! factory.canCreate( name ) )
+ {
+ throw new NoSuchPropertyException();
+ }
+ return factory.create( name );
}
/**
1.14 +4 -7
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/Resources.properties,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Resources.properties 24 Feb 2002 07:43:37 -0000 1.13
+++ Resources.properties 25 Feb 2002 10:42:43 -0000 1.14
@@ -1,6 +1,6 @@
create-object.error=Could not create an object of class {0}.
extra-config-for-ref.error=A reference element can only include an "id"
attribute.
-mismatch-ref-types.error=Mismatched type for reference "{0}". Was expecting
an object of type {1}, instead found an object of type {2}.
+mismatch-ref-types.error=Could not convert reference "{0}" to the type
expected for property "{1}".
incompatible-element-types.error=Incompatible creator and adder/setter
methods found in class {0} for property "{1}".
multiple-adder-methods-for-element.error=Multiple add{1}() or set{1}()
methods found in class {0}.
multiple-creator-methods-for-element.error=Multiple {1}() methods found in
class {0}.
@@ -9,16 +9,13 @@
must-be-element.error=This property must be configured using a nested
element.
too-many-values.error=Too many values for this property.
no-complex-type.error=Can not get complex type for non-primitive type {0}.
-no-such-attribute.error=Attribute "{1}" is not allowed for element <{0}>.
+no-such-attribute.error=Attribute "{1}" is not supported for element <{0}>.
bad-set-attribute.error=Could not set attribute "{1}" for element <{0}>.
bad-set-class-attribute.error=Could not set attribute "{0}" for object of
class {1}.
-no-such-element.error=Nested <{1}> elements are not allowed for element
<{0}>.
-no-content.error=Text content is not allowed in element <{0}>.
+no-such-element.error=Nested <{1}> elements are not supported for element
<{0}>.
+no-content.error=Text content is not supported in element <{0}>.
bad-set-content.error=Could not set text content for element <{0}>.
typed-adder-non-interface.error=The typed adder for class "{0}" must have a
single parameter that is an interface rather than {1} which defines a class.
create-typed-object.error=Could not create an object of type "{0}" of class
{1}.
unknown-reference.error=Could not find referenced object "{0}".
bad-configure-element.error=Could not configure element <{0}>.
-
-prop.mismatched-braces.error=Malformed property with mismatched }'s.
-prop.missing-value.error=Unable to find "{0}" to expand during property
resolution.
1.20 +86 -47
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java
Index: DefaultMasterConverter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DefaultMasterConverter.java 21 Feb 2002 11:06:41 -0000 1.19
+++ DefaultMasterConverter.java 25 Feb 2002 10:42:43 -0000 1.20
@@ -7,6 +7,9 @@
*/
package org.apache.myrmidon.components.converter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
@@ -16,7 +19,6 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
@@ -25,20 +27,21 @@
* Converter engine to handle converting between types.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.19 $ $Date: 2002/02/21 11:06:41 $
+ * @version $Revision: 1.20 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultMasterConverter
extends AbstractLogEnabled
- implements MasterConverter, Serviceable
+ implements Converter, Serviceable
{
private final static Resources REZ =
ResourceManager.getPackageResources( DefaultMasterConverter.class );
- private final static boolean DEBUG = false;
-
private ConverterRegistry m_registry;
private TypeFactory m_factory;
+ /** Map from converter name to Converter. */
+ private Map m_converters = new HashMap();
+
/**
* Retrieve relevent services needed to deploy.
*
@@ -83,73 +86,109 @@
return original;
}
- if( DEBUG )
- {
- final String message =
- REZ.getString( "converter-lookup.notice",
- originalClass.getName(),
- destination.getName() );
- getLogger().debug( message );
- }
-
- //Searching inheritance hierarchy for converter
- final String name = getConverterName( originalClass, destination );
-
try
{
- //TODO: Start caching converters instead of repeatedly
instantiating em.
- final Converter converter = (Converter)m_factory.create( name );
+ // Search inheritance hierarchy for converter
+ final String name = getConverterName( originalClass, destination
);
- if( DEBUG )
+ // Create the converter
+ Converter converter = (Converter)m_converters.get( name );
+ if( converter == null )
{
- final String message = REZ.getString(
"found-converter.notice", converter );
- getLogger().debug( message );
+ converter = (Converter)m_factory.create( name );
+ m_converters.put( name, converter );
}
+ // Convert
final Object object = converter.convert( destination, original,
context );
if( destination.isInstance( object ) )
{
return object;
}
- else
- {
- final String message =
- REZ.getString( "bad-return-type.error",
- name,
- object,
- destination.getName() );
- throw new ConverterException( message );
- }
+
+ final String message =
+ REZ.getString( "bad-return-type.error",
+ object.getClass().getName(),
+ destination.getName() );
+ throw new ConverterException( message );
}
- catch( final TypeException te )
+ catch( final Exception e )
{
- final String message = REZ.getString( "bad-typemanager.error" );
- throw new ConverterException( message, te );
+ final String message = REZ.getString( "convert.error",
+ originalClass.getName(),
+ destination.getName() );
+ throw new ConverterException( message, e );
}
}
+ /**
+ * Determine the name of the converter to use to convert between
+ * original and destination classes.
+ */
private String getConverterName( final Class originalClass,
final Class destination )
throws ConverterException
{
- //TODO: Maybe we should search the source classes hierarchy aswell
- for( Class clazz = destination;
- clazz != null;
- clazz = clazz.getSuperclass() )
+ //TODO: Maybe we should search the destination classes hierarchy as
well
+
+ // Recursively iterate over the super-types of the original class,
+ // looking for a converter from source type -> destination type.
+ // If more than one is found, choose the most specialised.
+
+ Class match = null;
+ String converterName = null;
+ ArrayList queue = new ArrayList();
+ queue.add( originalClass );
+
+ while( ! queue.isEmpty() )
{
- final String name =
- m_registry.getConverterName( originalClass.getName(),
- clazz.getName() );
- if( name != null )
+ Class clazz = (Class)queue.remove( 0 );
+
+ // Add superclass and all interfaces
+ if( clazz.getSuperclass() != null )
+ {
+ queue.add( clazz.getSuperclass() );
+ }
+ final Class[] interfaces = clazz.getInterfaces();
+ for( int i = 0; i < interfaces.length; i++ )
+ {
+ queue.add( interfaces[i ] );
+ }
+
+ // Check if we can convert from current class to destination
+ final String name = m_registry.getConverterName( clazz.getName(),
+
destination.getName() );
+ if( name == null )
+ {
+ continue;
+ }
+
+ // Choose the more specialised source class
+ if( match == null || match.isAssignableFrom( clazz ) )
{
- return name;
+ match = clazz;
+ converterName = name;
}
+ else if( clazz.isAssignableFrom( clazz ) )
+ {
+ continue;
+ }
+ else
+ {
+ // Duplicate
+ final String message = REZ.getString(
"ambiguous-converter.error" );
+ throw new ConverterException( message );
+ }
+ }
+
+ // TODO - should cache the (src, dest) -> converter mapping
+ if( match != null )
+ {
+ return converterName;
}
- final String message =
- REZ.getString( "no-converter.error",
- originalClass.getName(),
- destination.getName() );
+ // Could not find a converter
+ final String message = REZ.getString( "no-converter.error" );
throw new ConverterException( message );
}
}
1.4 +4 -6
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 29 Dec 2001 21:13:07 -0000 1.3
+++ Resources.properties 25 Feb 2002 10:42:43 -0000 1.4
@@ -1,7 +1,5 @@
-converter-lookup.notice=Looking for converter from {0} to {1}.
-found-converter.notice=Found Converter: {0}.
-
-no-converter-factory.error=Unable to retrieve Converter factory from
TypeManager.
-no-converter.error=Unable to find converter for {0} to {1} conversion.
+convert.error=Could not convert from {0} to {1}.
+no-converter.error=Could not find an appropriate converter.
bad-typemanager.error=Badly configured TypeManager missing converter
definition.
-bad-return-type.error=The TypeManager for {0} returned "{1}" which is not of
the expected type {2}.
+bad-return-type.error=Converter {0} returned an object of type {1} which is
assignable to the expected type {2}.
+ambiguous-converter.error=More than one converter available for this
conversion.
1.30 +2 -2
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
Index: DefaultDeployer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DefaultDeployer.java 24 Feb 2002 07:43:37 -0000 1.29
+++ DefaultDeployer.java 25 Feb 2002 10:42:43 -0000 1.30
@@ -35,7 +35,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.29 $ $Date: 2002/02/24 07:43:37 $
+ * @version $Revision: 1.30 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultDeployer
extends AbstractLogEnabled
@@ -261,7 +261,7 @@
final String name = roleDef.getShortHand();
final String role = roleDef.getRoleName();
final Class type = deployment.getClassLoader().loadClass( role );
- final RoleInfo roleInfo = new RoleInfo( role, name, type );
+ final RoleInfo roleInfo = new RoleInfo( role, name, type, null );
m_roleManager.addRole( roleInfo );
if( getLogger().isDebugEnabled() )
1.30 +3 -3
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
Index: DefaultEmbeddor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DefaultEmbeddor.java 24 Feb 2002 07:43:37 -0000 1.29
+++ DefaultEmbeddor.java 25 Feb 2002 10:42:43 -0000 1.30
@@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.aut.converter.Converter;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.ExtensionFileFilter;
@@ -29,7 +30,6 @@
import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.deployer.DeploymentException;
import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
@@ -49,7 +49,7 @@
* Instantiate this to embed inside other applications.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.29 $ $Date: 2002/02/24 07:43:37 $
+ * @version $Revision: 1.30 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultEmbeddor
extends AbstractLogEnabled
@@ -246,7 +246,7 @@
// Create the components
createComponent( ConverterRegistry.class, PREFIX +
"converter.DefaultConverterRegistry" );
createComponent( ExtensionManager.class, PREFIX +
"extensions.DefaultExtensionManager" );
- createComponent( MasterConverter.class, PREFIX +
"converter.DefaultMasterConverter" );
+ createComponent( Converter.class, PREFIX +
"converter.DefaultMasterConverter" );
createComponent( Configurer.class, PREFIX +
"configurer.DefaultConfigurer" );
createComponent( TypeManager.class, PREFIX +
"type.DefaultTypeManager" );
createComponent( RoleManager.class, PREFIX +
"role.DefaultRoleManager" );
1.27 +3 -5
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java
Index: DefaultExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- DefaultExecutor.java 21 Feb 2002 11:06:40 -0000 1.26
+++ DefaultExecutor.java 25 Feb 2002 10:42:43 -0000 1.27
@@ -13,9 +13,9 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.api.Task;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
@@ -24,13 +24,12 @@
import org.apache.myrmidon.interfaces.executor.Executor;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
-import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
/**
* The basic executor that just executes the tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.26 $ $Date: 2002/02/21 11:06:40 $
+ * @version $Revision: 1.27 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultExecutor
extends AbstractLogEnabled
@@ -103,8 +102,7 @@
{
try
{
- final TaskContextAdapter context = new TaskContextAdapter(
taskContext );
- m_configurer.configure( task, taskModel, context );
+ m_configurer.configure( task, taskModel, taskContext );
}
catch( final Throwable throwable )
{
1.12 +6 -6
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/MultiSourceTypeFactory.java
Index: MultiSourceTypeFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/MultiSourceTypeFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MultiSourceTypeFactory.java 14 Feb 2002 02:00:07 -0000 1.11
+++ MultiSourceTypeFactory.java 25 Feb 2002 10:42:43 -0000 1.12
@@ -14,10 +14,10 @@
import org.apache.myrmidon.interfaces.type.TypeFactory;
/**
- * This factory acts as a proxy to set of object factorys.
+ * This factory acts as a proxy to set of object factories.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.11 $ $Date: 2002/02/14 02:00:07 $
+ * @version $Revision: 1.12 $ $Date: 2002/02/25 10:42:43 $
*/
public class MultiSourceTypeFactory
implements TypeFactory
@@ -29,9 +29,9 @@
private final MultiSourceTypeFactory m_parent;
///Map of name->factory list
- private final HashMap m_factorys = new HashMap();
+ private final HashMap m_factories = new HashMap();
- ///Type expected to be created from factorys
+ ///Type expected to be created from factories
private final Class m_type;
public MultiSourceTypeFactory( final Class type )
@@ -51,7 +51,7 @@
*/
public void register( final String name, final TypeFactory factory )
{
- m_factorys.put( name, factory );
+ m_factories.put( name, factory );
}
/**
@@ -118,6 +118,6 @@
protected final TypeFactory getTypeFactory( final String name )
{
- return (TypeFactory)m_factorys.get( name );
+ return (TypeFactory)m_factories.get( name );
}
}
1.16 +12 -46
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
Index: DefaultTaskContext.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultTaskContext.java 24 Feb 2002 07:43:37 -0000 1.15
+++ DefaultTaskContext.java 25 Feb 2002 10:42:43 -0000 1.16
@@ -13,20 +13,16 @@
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.components.configurer.PropertyException;
-import org.apache.myrmidon.components.configurer.PropertyUtil;
-import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
/**
* Default implementation of TaskContext.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.15 $ $Date: 2002/02/24 07:43:37 $
+ * @version $Revision: 1.16 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultTaskContext
implements TaskContext
@@ -73,14 +69,9 @@
}
/**
- * Retrieve an item from the Context.
- *
- * @param key the key of item
- * @return the item stored in context
- * @exception ContextException if item not present
+ * Retrieve a property.
*/
- public Object get( final Object key )
- throws ContextException
+ private Object get( final String key )
{
final Object data = m_contextData.get( key );
if( null != data )
@@ -96,10 +87,10 @@
if( null == m_parent )
{
// There was no parent, and no data
- throw new ContextException( "Unable to locate " + key );
+ return null;
}
- return m_parent.getProperty( key.toString() );
+ return m_parent.getProperty( key );
}
/**
@@ -109,15 +100,7 @@
*/
public String getName()
{
- try
- {
- return (String)get( NAME );
- }
- catch( final ContextException ce )
- {
- final String message = REZ.getString( "no-name.error" );
- throw new IllegalStateException( message );
- }
+ return (String)get( NAME );
}
/**
@@ -127,15 +110,7 @@
*/
public File getBaseDirectory()
{
- try
- {
- return (File)get( BASE_DIRECTORY );
- }
- catch( final ContextException ce )
- {
- final String message = REZ.getString( "no-dir.error" );
- throw new IllegalStateException( message );
- }
+ return (File)get( BASE_DIRECTORY );
}
/**
@@ -205,10 +180,8 @@
{
try
{
- final TaskContextAdapter context = new TaskContextAdapter( this
);
-
final Object object =
- PropertyUtil.resolveProperty( value, context, false );
+ PropertyUtil.resolveProperty( value, this, false );
if( null == object )
{
@@ -218,10 +191,10 @@
return object;
}
- catch( final PropertyException pe )
+ catch( final TaskException te )
{
final String message = REZ.getString( "bad-resolve.error", value
);
- throw new TaskException( message, pe );
+ throw new TaskException( message, te );
}
}
@@ -233,14 +206,7 @@
*/
public Object getProperty( final String name )
{
- try
- {
- return get( name );
- }
- catch( final ContextException ce )
- {
- return null;
- }
+ return get( name );
}
/**
@@ -248,7 +214,7 @@
*
* @return the map of all property names to values
*/
- public Map getPropertys()
+ public Map getProperties()
{
return null;
}
1.27 +4 -4
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
Index: DefaultWorkspace.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- DefaultWorkspace.java 24 Feb 2002 07:43:37 -0000 1.26
+++ DefaultWorkspace.java 25 Feb 2002 10:42:43 -0000 1.27
@@ -45,7 +45,7 @@
* This is the default implementation of Workspace.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.26 $ $Date: 2002/02/24 07:43:37 $
+ * @version $Revision: 1.27 $ $Date: 2002/02/25 10:42:43 $
*/
public class DefaultWorkspace
extends AbstractLogEnabled
@@ -59,7 +59,7 @@
private ServiceManager m_serviceManager;
private Parameters m_parameters;
private TaskContext m_baseContext;
- private HashMap m_entrys = new HashMap();
+ private HashMap m_entries = new HashMap();
private TypeManager m_typeManager;
private Deployer m_deployer;
private Hierarchy m_hierarchy;
@@ -279,7 +279,7 @@
private ProjectEntry getProjectEntry( final Project project )
throws TaskException
{
- ProjectEntry entry = (ProjectEntry)m_entrys.get( project );
+ ProjectEntry entry = (ProjectEntry)m_entries.get( project );
if( null == entry )
{
@@ -287,7 +287,7 @@
{
final ExecutionFrame frame = createExecutionFrame( project );
entry = new ProjectEntry( project, frame );
- m_entrys.put( project, entry );
+ m_entries.put( project, entry );
}
catch( Exception e )
{
1.7 +5 -1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/Resources.properties,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Resources.properties 14 Feb 2002 02:12:23 -0000 1.6
+++ Resources.properties 25 Feb 2002 10:42:44 -0000 1.7
@@ -20,4 +20,8 @@
null-resolved-value.error=Value "{0}" resolved to null.
bad-resolve.error=Unable to resolve value "{0}".
bad-find-service.error=Could not find service "{0}".
-bad-service-class.error=Find service "{0}" but it was of type {1} where it
was expected to be of type {2}.
\ No newline at end of file
+bad-service-class.error=Find service "{0}" but it was of type {1} where it
was expected to be of type {2}.
+
+#PropertyUtil
+prop.mismatched-braces.error=Malformed property with mismatched }'s.
+prop.missing-value.error=Unable to find "{0}" to expand during property
resolution.
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/PropertyUtil.java
Index: PropertyUtil.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.workspace;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.Context;
import org.apache.myrmidon.api.TaskException;
/**
* Utility class to evaluate properties.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:43 $
*/
public final class PropertyUtil
{
private final static Resources REZ =
ResourceManager.getPackageResources( PropertyUtil.class );
private PropertyUtil()
{
}
/**
* Resolve a string property. This evaluates all property
* substitutions based on specified context.
*
* @param property the property to resolve
* @param context the context in which to resolve property
* @param ignoreUndefined if false will throw an TaskException if
property is not found
* @return the reolved property
* @exception TaskException if an error occurs
*/
public static Object resolveProperty( final String property,
final Context context,
final boolean ignoreUndefined )
throws TaskException
{
int start = findBeginning( property, 0 );
if( -1 == start )
{
return property;
}
int end = findEnding( property, start );
final int length = property.length();
if( 0 == start && end == ( length - 1 ) )
{
return resolveValue( property.substring( start + 2, end ),
context,
ignoreUndefined );
}
final StringBuffer sb = new StringBuffer( length * 2 );
int lastPlace = 0;
while( true )
{
final Object value =
resolveValue( property.substring( start + 2, end ),
context,
ignoreUndefined );
sb.append( property.substring( lastPlace, start ) );
sb.append( value );
lastPlace = end + 1;
start = findBeginning( property, lastPlace );
if( -1 == start )
{
break;
}
end = findEnding( property, start );
}
sb.append( property.substring( lastPlace, length ) );
return sb.toString();
}
/**
* Resolve a string property. This recursively evaluates all property
* substitutions based on specified context.
*
* @param property the property to resolve
* @param context the context in which to resolve property
* @param ignoreUndefined if false will throw an TaskException if
property is not found
* @return the reolved property
* @exception TaskException if an error occurs
*/
public static Object recursiveResolveProperty( final String property,
final Context context,
final boolean
ignoreUndefined )
throws TaskException
{
int start = findBeginning( property, 0 );
if( -1 == start )
{
return property;
}
int end = findNestedEnding( property, start );
final int length = property.length();
if( 0 == start && end == ( length - 1 ) )
{
final String propertyName = property.substring( start + 2, end );
final Object key = recursiveResolveProperty( propertyName,
context, ignoreUndefined );
return resolveValue( key.toString(), context, ignoreUndefined );
}
final StringBuffer sb = new StringBuffer( length * 2 );
int lastPlace = 0;
while( true )
{
final String propertyName = property.substring( start + 2, end );
final Object key = recursiveResolveProperty( propertyName,
context, ignoreUndefined );
final Object value = resolveValue( key.toString(), context,
ignoreUndefined );
sb.append( property.substring( lastPlace, start ) );
sb.append( value );
lastPlace = end + 1;
start = findBeginning( property, lastPlace );
if( -1 == start )
{
break;
}
end = findNestedEnding( property, start );
}
sb.append( property.substring( lastPlace, length ) );
return sb.toString();
}
private static int findBeginning( final String property, final int
currentPosition )
{
//TODO: Check if it is commented out
return property.indexOf( "${", currentPosition );
}
private static int findEnding( final String property, final int
currentPosition )
throws TaskException
{
//TODO: Check if it is commented out
final int index = property.indexOf( '}', currentPosition );
if( -1 == index )
{
final String message = REZ.getString(
"prop.mismatched-braces.error" );
throw new TaskException( message );
}
return index;
}
private static int findNestedEnding( final String property, final int
currentPosition )
throws TaskException
{
final int length = property.length();
final int start = currentPosition + 2;
int weight = 1;
for( int i = start; ( weight > 0 ) && ( i < length ); i++ )
{
final char ch = property.charAt( i );
switch( ch )
{
case '}':
//TODO: Check if it is commented out
weight--;
if( weight == 0 )
{
return i;
}
break;
case '$':
{
//TODO: Check if it is commented out
final int next = i + 1;
if( next < length && '{' == property.charAt( next ) )
{
weight++;
}
}
break;
}
}
final String message = REZ.getString( "prop.mismatched-braces.error"
);
throw new TaskException( message );
}
/**
* Retrieve a value from the specified context using the specified key.
* If there is no such value and ignoreUndefined is not false then a
* TaskException is generated.
*
* @param key the key of value in context
* @param context the Context
* @param ignoreUndefined true if undefined variables are ignored
* @return the object retrieved from context
* @exception TaskException if an error occurs
*/
private static Object resolveValue( final String key,
final Context context,
final boolean ignoreUndefined )
throws TaskException
{
final Object value = context.getProperty( key );
if( value != null )
{
return value;
}
if( ignoreUndefined )
{
return "";
}
final String message = REZ.getString( "prop.missing-value.error", key
);
throw new TaskException( message );
}
}
1.18 +7 -11
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java
Index: AbstractContainerTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- AbstractContainerTask.java 21 Feb 2002 10:16:43 -0000 1.17
+++ AbstractContainerTask.java 25 Feb 2002 10:42:44 -0000 1.18
@@ -7,6 +7,8 @@
*/
package org.apache.myrmidon.framework;
+import org.apache.aut.converter.Converter;
+import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration;
@@ -14,21 +16,17 @@
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
-import org.apache.aut.converter.Converter;
-import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.interfaces.configurer.Configurer;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.executor.Executor;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
-import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
/**
* This is the class that Task writers should extend to provide custom tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.17 $ $Date: 2002/02/21 10:16:43 $
+ * @version $Revision: 1.18 $ $Date: 2002/02/25 10:42:44 $
*/
public abstract class AbstractContainerTask
extends AbstractTask
@@ -37,7 +35,7 @@
ResourceManager.getPackageResources( AbstractContainerTask.class );
///For converting own attributes
- private MasterConverter m_converter;
+ private Converter m_converter;
///For configuring own sub-elements
private Configurer m_configurer;
@@ -55,7 +53,7 @@
{
super.contextualize( context );
m_configurer = (Configurer)getService( Configurer.class );
- m_converter = (MasterConverter)getService( MasterConverter.class );
+ m_converter = (Converter)getService( Converter.class );
m_executor = (Executor)getService( Executor.class );
}
@@ -91,8 +89,7 @@
protected final void configure( final Object object, final Configuration
element )
throws ConfigurationException
{
- final TaskContextAdapter context = new TaskContextAdapter(
getContext() );
- getConfigurer().configure( object, element, context );
+ getConfigurer().configure( object, element, getContext() );
}
/**
@@ -106,8 +103,7 @@
protected final void configure( final Object object, final String name,
final String value )
throws ConfigurationException
{
- final TaskContextAdapter context = new TaskContextAdapter(
getContext() );
- getConfigurer().configure( object, name, value, context );
+ getConfigurer().configure( object, name, value, getContext() );
}
/**
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/ExecManagerFactory.java
Index: ExecManagerFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.factories;
import java.io.File;
import org.apache.aut.nativelib.ExecException;
import org.apache.aut.nativelib.impl.DefaultExecManager;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.interfaces.service.AntServiceException;
import org.apache.myrmidon.interfaces.service.ServiceFactory;
/**
* A Factory responsible for creating the ExecManager service.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:44 $
*/
public class ExecManagerFactory
implements ServiceFactory
{
private final static Resources REZ =
ResourceManager.getPackageResources( ExecManagerFactory.class );
/**
* Create the ExecManager Service.
*/
public Object createService()
throws AntServiceException
{
final File home = getHomeDirectory();
try
{
return new DefaultExecManager( home );
}
catch( final ExecException ee )
{
throw new AntServiceException( ee.getMessage(), ee );
}
}
/**
* Utility method to retrieve home directory.
*/
private static File getHomeDirectory()
throws AntServiceException
{
final String home = System.getProperty( "myrmidon.home" );
if( null == home )
{
final String message = REZ.getString( "missing-home-dir.error" );
throw new AntServiceException( message );
}
return new File( home );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/Resources.properties
Index: Resources.properties
===================================================================
missing-home-dir.error=Cannot locate antRun scripts: Property 'myrmidon.home'
not specified
create-vfs-manager.error=Could not create the VFS manager.
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/VfsManagerFactory.java
Index: VfsManagerFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.factories;
import org.apache.aut.vfs.FileSystemManager;
import org.apache.aut.vfs.impl.DefaultFileSystemManager;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.interfaces.service.AntServiceException;
import org.apache.myrmidon.interfaces.service.ServiceFactory;
/**
* A factory that creates the [EMAIL PROTECTED] FileSystemManager} service.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:44 $
*/
public class VfsManagerFactory
implements ServiceFactory
{
private final static Resources REZ
= ResourceManager.getPackageResources( VfsManagerFactory.class );
/**
* Create a service that coresponds to this factory.
*/
public Object createService()
throws AntServiceException
{
try
{
return new DefaultFileSystemManager();
}
catch( Exception e )
{
final String message = REZ.getString( "create-vfs-manager.error"
);
throw new AntServiceException( message );
}
}
}
1.7 +2 -2
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/Configurer.java
Index: Configurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/Configurer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Configurer.java 21 Feb 2002 11:06:41 -0000 1.6
+++ Configurer.java 25 Feb 2002 10:42:44 -0000 1.7
@@ -9,13 +9,13 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
+import org.apache.myrmidon.api.Context;
/**
* Class used to configure tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.6 $ $Date: 2002/02/21 11:06:41 $
+ * @version $Revision: 1.7 $ $Date: 2002/02/25 10:42:44 $
*/
public interface Configurer
{
1.2 +28 -11
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java
Index: RoleInfo.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RoleInfo.java 21 Feb 2002 12:52:07 -0000 1.1
+++ RoleInfo.java 25 Feb 2002 10:42:44 -0000 1.2
@@ -13,13 +13,14 @@
* A role definition. Role definitions are immutable.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.1 $ $Date: 2002/02/21 12:52:07 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/25 10:42:44 $
*/
public final class RoleInfo
{
private final String m_name;
private final String m_shorthand;
private final Class m_type;
+ private final String m_defaultType;
/**
* Creates a role definition.
@@ -28,9 +29,7 @@
*/
public RoleInfo( final String name )
{
- m_name = name;
- m_shorthand = null;
- m_type = null;
+ this( name, null, null, null );
}
/**
@@ -41,9 +40,7 @@
*/
public RoleInfo( final String name, final String shorthand )
{
- m_name = name;
- m_shorthand = shorthand;
- m_type = null;
+ this( name, shorthand, null, null );
}
/**
@@ -55,9 +52,7 @@
*/
public RoleInfo( final String name, final String shorthand, final Class
type )
{
- m_name = name;
- m_shorthand = shorthand;
- m_type = type;
+ this( name, shorthand, type, null );
}
/**
@@ -66,9 +61,21 @@
*/
public RoleInfo( final String shorthand, final Class type )
{
- m_name = type.getName();
+ this( type.getName(), shorthand, type, null );
+ }
+
+ /**
+ * Creates a role definition.
+ */
+ public RoleInfo( final String name,
+ final String shorthand,
+ final Class type,
+ final String defaultType )
+ {
+ m_name = name;
m_shorthand = shorthand;
m_type = type;
+ m_defaultType = defaultType;
}
/**
@@ -126,5 +133,15 @@
public Class getType()
{
return m_type;
+ }
+
+ /**
+ * Returns the name of the default implementation of this role.
+ *
+ * @return The default type name, or null if this role has no default
type.
+ */
+ public String getDefaultType()
+ {
+ return m_defaultType;
}
}
1.16 +1 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
Index: Script.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Script.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Script.java 21 Feb 2002 09:41:54 -0000 1.15
+++ Script.java 25 Feb 2002 10:42:44 -0000 1.16
@@ -88,7 +88,7 @@
{
try
{
- addBeans( getContext().getPropertys() );
+ addBeans( getContext().getProperties() );
//In Ant2 there is no difference between properties and
references
//addBeans( getProject().getReferences() );
1.42 +2 -2
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Index: JUnitTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- JUnitTask.java 21 Feb 2002 09:39:53 -0000 1.41
+++ JUnitTask.java 25 Feb 2002 10:42:44 -0000 1.42
@@ -617,7 +617,7 @@
// Create a temporary file to pass the Ant properties to the forked
test
File propsFile = new File( "junit" + ( new Random(
System.currentTimeMillis() ) ).nextLong() + ".properties" );
cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() );
- Map p = getContext().getPropertys();
+ Map p = getContext().getProperties();
Properties props = new Properties();
for( Iterator enum = p.keySet().iterator(); enum.hasNext(); )
{
@@ -663,7 +663,7 @@
private int executeInVM( JUnitTest test )
throws TaskException
{
- test.setProperties( getContext().getPropertys() );
+ test.setProperties( getContext().getProperties() );
if( dir != null )
{
getLogger().warn( "dir attribute ignored if running in the same
VM" );
1.4 +0 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java
Index: StringToPathConverter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StringToPathConverter.java 21 Feb 2002 10:16:43 -0000 1.3
+++ StringToPathConverter.java 25 Feb 2002 10:42:44 -0000 1.4
@@ -7,7 +7,6 @@
*/
package org.apache.tools.ant.types.converters;
-import org.apache.avalon.framework.context.Context;
import org.apache.aut.converter.AbstractConverter;
import org.apache.aut.converter.ConverterException;
import org.apache.tools.ant.types.Path;
1.3 +2 -2
jakarta-ant/proposal/myrmidon/src/manifest/core-services.xml
Index: core-services.xml
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/manifest/core-services.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- core-services.xml 15 Feb 2002 07:36:06 -0000 1.2
+++ core-services.xml 25 Feb 2002 10:42:44 -0000 1.3
@@ -1,6 +1,6 @@
<services version="1.0">
- <exec-manager
factory="org.apache.myrmidon.framework.factorys.ExecManagerFactory"/>
- <file-system-manager
factory="org.apache.myrmidon.framework.factorys.VfsManagerFactory">
+ <exec-manager
factory="org.apache.myrmidon.framework.factories.ExecManagerFactory"/>
+ <file-system-manager
factory="org.apache.myrmidon.framework.factories.VfsManagerFactory">
<provider scheme="zip"
classname="org.apache.aut.vfs.provider.zip.ZipFileSystemProvider"/>
<provider scheme="jar"
classname="org.apache.aut.vfs.provider.zip.ZipFileSystemProvider"/>
<provider scheme="smb"
classname="org.apache.aut.vfs.provider.smb.SmbFileSystemProvider"/>
1.2 +4 -1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractProjectTest.java
Index: AbstractProjectTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractProjectTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractProjectTest.java 21 Feb 2002 03:23:37 -0000 1.1
+++ AbstractProjectTest.java 25 Feb 2002 10:42:44 -0000 1.2
@@ -19,7 +19,7 @@
* A base class for test cases which need to execute projects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.1 $ $Date: 2002/02/21 03:23:37 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/25 10:42:44 $
*/
public class AbstractProjectTest
extends AbstractMyrmidonTest
@@ -50,6 +50,9 @@
{
if( m_embeddor == null )
{
+ // Need to set the context classloader - The default embeddor
uses it
+ Thread.currentThread().setContextClassLoader(
getClass().getClassLoader() );
+
final Logger logger = createLogger();
m_embeddor = new DefaultEmbeddor();
m_embeddor.enableLogging( logger );
1.10 +25 -2
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
Index: AbstractComponentTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractComponentTest.java 24 Feb 2002 07:43:38 -0000 1.9
+++ AbstractComponentTest.java 25 Feb 2002 10:42:44 -0000 1.10
@@ -29,9 +29,9 @@
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
+import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
import org.apache.myrmidon.interfaces.type.TypeException;
@@ -83,7 +83,7 @@
List components = new ArrayList();
Object component = new DefaultMasterConverter();
- m_serviceManager.put( MasterConverter.ROLE, component );
+ m_serviceManager.put( Converter.ROLE, component );
components.add( component );
component = new DefaultConverterRegistry();
@@ -138,6 +138,29 @@
}
}
+ /**
+ * Utility method to register a role.
+ */
+ protected void registerRole( final RoleInfo roleInfo )
+ throws Exception
+ {
+ RoleManager roleMgr = (RoleManager)getServiceManager().lookup(
RoleManager.ROLE );
+ roleMgr.addRole( roleInfo );
+ }
+
+ /**
+ * Utility method to register a type.
+ */
+ protected void registerType( final Class roleType,
+ final String typeName,
+ final Class type )
+ throws Exception
+ {
+ final ClassLoader loader = getClass().getClassLoader();
+ final DefaultTypeFactory factory = new DefaultTypeFactory( loader );
+ factory.addNameClassMapping( typeName, type.getName() );
+ getTypeManager().registerType( roleType, typeName, factory );
+ }
/**
* Utility method to register a Converter.
1.2 +2 -3
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest4.java
Index: ConfigTest4.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest4.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigTest4.java 28 Jan 2002 00:08:31 -0000 1.1
+++ ConfigTest4.java 25 Feb 2002 10:42:44 -0000 1.2
@@ -7,14 +7,13 @@
*/
package org.apache.myrmidon.components.configurer;
-import java.util.ArrayList;
-import junit.framework.AssertionFailedError;
+
/**
* Simple class to test typed adder.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.1 $ $Date: 2002/01/28 00:08:31 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/25 10:42:44 $
*/
public class ConfigTest4
{
1.16 +184 -96
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java
Index: DefaultConfigurerTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultConfigurerTest.java 24 Feb 2002 07:43:38 -0000 1.15
+++ DefaultConfigurerTest.java 25 Feb 2002 10:42:45 -0000 1.16
@@ -13,16 +13,12 @@
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.context.Context;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.components.AbstractComponentTest;
import org.apache.myrmidon.components.workspace.DefaultTaskContext;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.configurer.Configurer;
-import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
import org.apache.myrmidon.interfaces.role.RoleInfo;
-import org.apache.myrmidon.interfaces.role.RoleManager;
-import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
/**
* Test cases for the default configurer and related classes.
@@ -37,7 +33,6 @@
private Configurer m_configurer;
private DefaultTaskContext m_context;
- private Context m_adaptor;
public DefaultConfigurerTest( String name )
{
@@ -59,7 +54,6 @@
m_context = new DefaultTaskContext();
final File baseDir = new File( "." ).getAbsoluteFile();
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
- m_adaptor = new TaskContextAdapter( m_context );
}
/**
@@ -75,13 +69,13 @@
final String value2 = "some other value";
config.setAttribute( "prop", value2 );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check result
- final ConfigTest1 expected = new ConfigTest1();
+ final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( value1 );
expected.addProp( value2 );
assertEquals( expected, test );
@@ -99,18 +93,15 @@
config.setAttribute( "integer-prop", "-401" );
// Register the converter
- final Class converterClass = StringToIntegerConverter.class;
- final Class sourceClass = String.class;
- final Class destClass = Integer.class;
- registerConverter( converterClass, sourceClass, destClass );
+ registerConverter( StringToIntegerConverter.class, String.class,
Integer.class );
- final ConfigTest10 test = new ConfigTest10();
+ final ConfigTestPrimConvert test = new ConfigTestPrimConvert();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check result
- final ConfigTest10 expected = new ConfigTest10();
+ final ConfigTestPrimConvert expected = new ConfigTestPrimConvert();
expected.setIntProp( 90 );
expected.setIntegerProp( new Integer(-401) );
assertEquals( expected, test );
@@ -126,12 +117,12 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setAttribute( "unknown", "some value" );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
// Configure the object
try
{
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -158,17 +149,17 @@
child2.setAttribute( "some-prop", value2 );
config.addChild( child2 );
- final ConfigTest2 test = new ConfigTest2();
+ final ConfigTestObjectProps test = new ConfigTestObjectProps();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check result
- final ConfigTest2 expected = new ConfigTest2();
- ConfigTest1 elem = new ConfigTest1();
+ final ConfigTestObjectProps expected = new ConfigTestObjectProps();
+ ConfigTestStringProps elem = new ConfigTestStringProps();
elem.setSomeProp( value1 );
expected.setProp( elem );
- elem = new ConfigTest1();
+ elem = new ConfigTestStringProps();
elem.setSomeProp( value2 );
expected.addAnotherProp( elem );
assertEquals( expected, test );
@@ -185,12 +176,12 @@
final DefaultConfiguration elem = new DefaultConfiguration(
"unknown", "test" );
config.addChild( elem );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
// Configure the object
try
{
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -211,13 +202,13 @@
final String value1 = "some value";
config.setValue( value1 );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check result
- final ConfigTest1 expected = new ConfigTest1();
+ final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.addContent( value1 );
assertEquals( expected, test );
}
@@ -232,12 +223,12 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setValue( "some value" );
- final ConfigTest2 test = new ConfigTest2();
+ final ConfigTestObjectProps test = new ConfigTestObjectProps();
// Configure the object
try
{
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -257,15 +248,15 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setAttribute( "prop", "some ${prop-a} value" );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
m_context.setProperty( "prop-a", "other" );
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check the configured object
- final ConfigTest1 expected = new ConfigTest1();
+ final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.addProp( "some other value" );
assertEquals( expected, test );
}
@@ -279,15 +270,15 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setAttribute( "some-prop-ref", "prop-a" );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
m_context.setProperty( "prop-a", "some value" );
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check the configured object
- final ConfigTest1 expected = new ConfigTest1();
+ final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some value" );
assertEquals( expected, test );
}
@@ -303,15 +294,15 @@
elem.setAttribute( "id", "prop-a" );
config.addChild( elem );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
m_context.setProperty( "prop-a", "some value" );
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check the configured object
- final ConfigTest1 expected = new ConfigTest1();
+ final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some value" );
assertEquals( expected, test );
}
@@ -329,12 +320,12 @@
elem.setAttribute( "extra-attr", "some value" );
config.addChild( elem );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
try
{
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -348,6 +339,57 @@
}
/**
+ * Tests reference type conversion.
+ */
+ public void testReferenceConversion() throws Exception
+ {
+ // Setup test data
+ final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
+ config.setAttribute( "prop-a-ref", "id" );
+
+ final Integer refValue = new Integer( 21 );
+ m_context.setProperty( "id", refValue );
+
+ registerConverter( ObjectToMyRole1Converter.class, Object.class,
MyRole1.class );
+
+ final ConfigTestInterfaceProp test = new ConfigTestInterfaceProp();
+
+ // Configure
+ m_configurer.configure( test, config, m_context );
+
+ // Check result
+ final ConfigTestInterfaceProp expected = new
ConfigTestInterfaceProp();
+ expected.addPropA( new MyRole1Adaptor( refValue ) );
+ assertEquals( expected, test );
+ }
+
+ /**
+ * Tests that the role's default type is used for interface typed
+ * elements.
+ */
+ public void testInterfaceAdder()
+ throws Exception
+ {
+ // Setup test data
+ final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
+ final DefaultConfiguration child = new DefaultConfiguration(
"prop-a", "test" );
+ config.addChild( child );
+
+ registerRole( new RoleInfo( "myrole1", null, MyRole1.class,
"default-type" ) );
+ registerType( MyRole1.class, "default-type", MyType1.class );
+
+ final ConfigTestInterfaceProp test = new ConfigTestInterfaceProp();
+
+ // Configure object
+ m_configurer.configure( test, config, m_context );
+
+ // Check result
+ final ConfigTestInterfaceProp expected = new
ConfigTestInterfaceProp();
+ expected.addPropA( new MyType1() );
+ assertEquals( expected, test );
+ }
+
+ /**
* Tests whether an object with a non-iterface typed adder causes an
* exception.
*/
@@ -362,7 +404,7 @@
try
{
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -386,12 +428,12 @@
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
- final ConfigTest5 test = new ConfigTest5();
+ final ConfigTestMultiTypedAdder test = new
ConfigTestMultiTypedAdder();
try
{
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -399,7 +441,7 @@
final String[] messages = {
REZ.getString( "bad-configure-element.error", "test" ),
REZ.getString( "multiple-adder-methods-for-element.error",
- ConfigTest5.class.getName(),
+ ConfigTestMultiTypedAdder.class.getName(),
"")
};
assertSameMessage( messages, ce );
@@ -419,25 +461,76 @@
config.addChild( child1 );
config.addChild( child2 );
- final ClassLoader loader = getClass().getClassLoader();
- final DefaultTypeFactory factory = new DefaultTypeFactory( loader );
- factory.addNameClassMapping( "my-type1", MyType1.class.getName() );
- factory.addNameClassMapping( "my-type2", MyType2.class.getName() );
- getTypeManager().registerType( DataType.class, "my-type1", factory );
- getTypeManager().registerType( DataType.class, "my-type2", factory );
+ registerType( DataType.class, "my-type1", MyType1.class );
+ registerType( DataType.class, "my-type2", MyType2.class );
- final ConfigTest6 test = new ConfigTest6();
+ final ConfigTestTypedProp test = new ConfigTestTypedProp();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
- final ConfigTest6 expected = new ConfigTest6();
+ final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
expected.add( new MyType2() );
assertEquals( expected, test );
}
/**
+ * Tests to check that role is used for typed adder.
+ */
+ public void testTypedAdderRole()
+ throws Exception
+ {
+ // Setup test data
+ final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
+ final DefaultConfiguration child1 = new DefaultConfiguration(
"my-type1", "test" );
+ config.addChild( child1 );
+
+ // Register incompatible types with the same name, as data-type and
myrole1.
+ registerRole( new RoleInfo( "myrole1", "myrole1", MyRole1.class ) );
+ registerType( MyRole1.class, "my-type1", MyType1.class );
+ registerType( DataType.class, "my-type1", StringBuffer.class );
+
+ final ConfigTestTypedProp test = new ConfigTestTypedProp();
+
+ // Configure the object
+ m_configurer.configure( test, config, m_context );
+
+ // Check the result
+ final ConfigTestTypedProp expected = new ConfigTestTypedProp();
+ expected.add( new MyType1() );
+ assertEquals( expected, test );
+ }
+
+ /**
+ * Tests conversion with a typed adder.
+ */
+ public void testTypedAdderConversion()
+ throws Exception
+ {
+ // Setup test data
+ final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
+ final DefaultConfiguration child = new DefaultConfiguration(
"some-type", "test" );
+ child.setAttribute( "prop", "some value" );
+ config.addChild( child );
+
+ registerType( DataType.class, "some-type",
ConfigTestStringProps.class );
+ registerConverter( ObjectToMyRole1Converter.class, Object.class,
MyRole1.class );
+
+ final ConfigTestTypedProp test = new ConfigTestTypedProp();
+
+ // Configure the object
+ m_configurer.configure( test, config, m_context );
+
+ // Check the result
+ final ConfigTestTypedProp expected = new ConfigTestTypedProp();
+ final ConfigTestStringProps nested = new ConfigTestStringProps();
+ nested.addProp( "some value" );
+ expected.add( new MyRole1Adaptor( nested ) );
+ assertEquals( expected, test );
+ }
+
+ /**
* Tests to see if typed adder can be used via an attribute.
*/
public void testTypedAdderAttribute()
@@ -448,19 +541,17 @@
config.setAttribute( "my-role1", "some value" );
// Set up the converter and role
- RoleManager roleMgr = (RoleManager)getServiceManager().lookup(
RoleManager.ROLE );
- final RoleInfo roleInfo = new RoleInfo("my-role1", MyRole1.class );
- roleMgr.addRole( roleInfo );
- registerConverter( StringToMyRole1Converter.class, String.class,
MyRole1.class );
+ registerRole( new RoleInfo("my-role1", MyRole1.class ) );
+ registerConverter( ObjectToMyRole1Converter.class, String.class,
MyRole1.class );
- final ConfigTest6 test = new ConfigTest6();
+ final ConfigTestTypedProp test = new ConfigTestTypedProp();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check result
- final ConfigTest6 expected = new ConfigTest6();
- expected.add( new MyType1() );
+ final ConfigTestTypedProp expected = new ConfigTestTypedProp();
+ expected.add( new MyRole1Adaptor( "some value" ) );
assertEquals( expected, test );
}
@@ -477,12 +568,12 @@
config.addChild( child1 );
config.addChild( child2 );
- final ConfigTest7 test = new ConfigTest7();
+ final ConfigTestTypedConfigProp test = new
ConfigTestTypedConfigProp();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
- final ConfigTest7 expected = new ConfigTest7();
+ final ConfigTestTypedConfigProp expected = new
ConfigTestTypedConfigProp();
expected.add( child1 );
expected.add( child2 );
assertEquals( expected, test );
@@ -501,12 +592,12 @@
config.addChild( child1 );
config.addChild( child2 );
- final ConfigTest8 test = new ConfigTest8();
+ final ConfigTestConfigProps test = new ConfigTestConfigProps();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
- final ConfigTest8 expected = new ConfigTest8();
+ final ConfigTestConfigProps expected = new ConfigTestConfigProps();
expected.addConfig( child1 );
expected.addConfig( child2 );
assertEquals( expected, test );
@@ -521,12 +612,12 @@
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
- final ConfigTest9 test = new ConfigTest9();
+ final ConfigTestConfigurable test = new ConfigTestConfigurable();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
- final ConfigTest9 expected = new ConfigTest9();
+ final ConfigTestConfigurable expected = new ConfigTestConfigurable();
expected.configure( config );
assertEquals( expected, test );
}
@@ -541,22 +632,22 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setAttribute( "some-prop-ref", "${id}" );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
m_context.setProperty( "id", "prop-a" );
m_context.setProperty( "prop-a", "some indirect value" );
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Check the configured object
- final ConfigTest1 expected = new ConfigTest1();
+ final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some indirect value" );
assertEquals( expected, test );
}
/**
- * Test an unknown reference.
+ * Tests an unknown reference.
*/
public void testUnknownReference()
throws Exception
@@ -565,12 +656,12 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setAttribute( "some-prop-ref", "unknown-prop" );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
// Configure the object
try
{
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -593,14 +684,14 @@
final DefaultConfiguration config = new DefaultConfiguration(
"test", "test" );
config.setAttribute( "some-prop-ref", "prop-a" );
- final ConfigTest1 test = new ConfigTest1();
+ final ConfigTestStringProps test = new ConfigTestStringProps();
- m_context.setProperty( "prop-a", new ConfigTest2() );
+ m_context.setProperty( "prop-a", new ConfigTestObjectProps() );
// Configure the object
try
{
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -609,8 +700,7 @@
REZ.getString( "bad-set-attribute.error", "test",
"some-prop-ref" ),
REZ.getString( "mismatch-ref-types.error",
"prop-a",
- String.class.getName(),
- ConfigTest2.class.getName() )
+ "some-prop" )
};
assertSameMessage( messages, e );
}
@@ -631,19 +721,17 @@
config.addChild( child );
// Add role mapping, and add to reference to context
- final RoleManager roleMgr = (RoleManager)getServiceManager().lookup(
RoleManager.ROLE );
- final RoleInfo roleInfo = new RoleInfo( "my-role1", MyRole1.class );
- roleMgr.addRole( roleInfo );
+ registerRole( new RoleInfo( "my-role1", MyRole1.class ) );
m_context.setProperty( "id", new MyType1() );
m_context.setProperty( "id2", new MyType2() );
- final ConfigTest6 test = new ConfigTest6();
+ final ConfigTestTypedProp test = new ConfigTestTypedProp();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Compare against expected value
- final ConfigTest6 expected = new ConfigTest6();
+ final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
expected.add( new MyType2() );
assertEquals( expected, test );
@@ -660,12 +748,12 @@
elem.setAttribute( "not-a-prop", "not-a-value" );
config.addChild( elem );
- final ConfigTest2 test = new ConfigTest2();
+ final ConfigTestObjectProps test = new ConfigTestObjectProps();
try
{
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -693,16 +781,16 @@
elem = new DefaultConfiguration( "prop3", "test" );
config.addChild( elem );
- final ConfigTest3 test = new ConfigTest3();
+ final ConfigTestMultiSetter test = new ConfigTestMultiSetter();
// Configure the object
- m_configurer.configure( test, config, m_adaptor );
+ m_configurer.configure( test, config, m_context );
// Test expected value
- final ConfigTest3 expected = new ConfigTest3();
- expected.setProp1( new ConfigTest1() );
- expected.setProp2( new ConfigTest1() );
- expected.addProp3( new ConfigTest1() );
+ final ConfigTestMultiSetter expected = new ConfigTestMultiSetter();
+ expected.setProp1( new ConfigTestStringProps() );
+ expected.setProp2( new ConfigTestStringProps() );
+ expected.addProp3( new ConfigTestStringProps() );
assertEquals( expected, test );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestConfigProps.java
Index: ConfigTestConfigProps.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
import org.apache.avalon.framework.configuration.Configuration;
/**
* Simple class to test adder for Configurations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:44 $
*/
public class ConfigTestConfigProps
{
private ArrayList m_configurations = new ArrayList();
public void addConfig( final Configuration configuration )
{
m_configurations.add( configuration );
}
public boolean equals( final Object object )
{
final ConfigTestConfigProps other = (ConfigTestConfigProps)object;
return m_configurations.equals( other.m_configurations );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestConfigurable.java
Index: ConfigTestConfigurable.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* Simple class to test [EMAIL PROTECTED] Configurable}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:44 $
*/
public class ConfigTestConfigurable
implements Configurable
{
private Configuration m_configuration;
public void configure( Configuration configuration )
throws ConfigurationException
{
m_configuration = configuration;
}
public boolean equals( final Object object )
{
final ConfigTestConfigurable other = (ConfigTestConfigurable)object;
return m_configuration == other.m_configuration;
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestInterfaceProp.java
Index: ConfigTestInterfaceProp.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
/**
* A test class with an interface property.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:44 $
*/
public class ConfigTestInterfaceProp
{
private final ArrayList m_elems = new ArrayList();
public void addPropA( final MyRole1 role1 )
{
m_elems.add( role1 );
}
public boolean equals( Object obj )
{
final ConfigTestInterfaceProp test = (ConfigTestInterfaceProp)obj;
return m_elems.equals( test.m_elems );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestMultiSetter.java
Index: ConfigTestMultiSetter.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
import junit.framework.AssertionFailedError;
/**
* A test class with multiple setters/adders/creators for a property.
*
* @author Adam Murdoch
*/
public class ConfigTestMultiSetter
{
private ConfigTestStringProps m_prop1;
private ConfigTestStringProps m_prop2;
private ArrayList m_prop3 = new ArrayList();
public boolean equals( Object obj )
{
ConfigTestMultiSetter test = (ConfigTestMultiSetter)obj;
if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) )
{
return false;
}
if( !DefaultConfigurerTest.equals( m_prop2, test.m_prop2 ) )
{
return false;
}
if( !m_prop3.equals( test.m_prop3 ) )
{
return false;
}
return true;
}
//
// Multiple setters
//
public void setProp1( final String value )
{
throw new AssertionFailedError();
}
public void setProp1( final ConfigTestStringProps value )
{
m_prop1 = value;
}
//
// Setter and Adder
//
public void addProp2( final String value )
{
throw new AssertionFailedError();
}
public void setProp2( final ConfigTestStringProps value )
{
m_prop2 = value;
}
//
// Multiple Adders
//
public void addProp3( final String value )
{
throw new AssertionFailedError();
}
public void addProp3( final ConfigTestStringProps value )
{
m_prop3.add( value );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestMultiTypedAdder.java
Index: ConfigTestMultiTypedAdder.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
/**
* Simple class with more than one typed adder method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:45 $
*/
public class ConfigTestMultiTypedAdder
{
public void add( final MyRole1 role1 )
{
}
public void add( final MyRole2 role2 )
{
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestObjectProps.java
Index: ConfigTestObjectProps.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
import java.util.List;
/**
* A simple test class.
*
* @author Adam Murdoch
*/
public class ConfigTestObjectProps
{
ConfigTestStringProps m_prop;
List m_propList = new ArrayList();
public boolean equals( Object obj )
{
ConfigTestObjectProps test = (ConfigTestObjectProps)obj;
if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) )
{
return false;
}
if( !m_propList.equals( test.m_propList ) )
{
return false;
}
return true;
}
public void setProp( final ConfigTestStringProps test )
{
m_prop = test;
}
public void addAnotherProp( final ConfigTestStringProps test )
{
m_propList.add( test );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestPrimConvert.java
Index: ConfigTestPrimConvert.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import org.apache.myrmidon.components.AbstractComponentTest;
/**
* A class for testing conversion.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
*/
public class ConfigTestPrimConvert
{
private int m_intProp;
private Integer m_integerProp;
public void setIntProp( final int intProp )
{
m_intProp = intProp;
}
public void setIntegerProp( final Integer integerProp )
{
m_integerProp = integerProp;
}
public boolean equals( Object obj )
{
ConfigTestPrimConvert test = (ConfigTestPrimConvert)obj;
if( m_intProp != test.m_intProp )
{
return false;
}
if ( !AbstractComponentTest.equals( m_integerProp, test.m_integerProp
) )
{
return false;
}
return true;
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestStringProps.java
Index: ConfigTestStringProps.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
import java.util.List;
import org.apache.myrmidon.framework.DataType;
/**
* A simple test class with string properties.
*
* @author Adam Murdoch
*/
public class ConfigTestStringProps
implements DataType
{
private String m_someProp;
private List m_propList = new ArrayList();
private String m_content;
public boolean equals( final Object obj )
{
final ConfigTestStringProps test = (ConfigTestStringProps)obj;
if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) )
{
return false;
}
else if( !m_propList.equals( test.m_propList ) )
{
return false;
}
else if( !DefaultConfigurerTest.equals( m_content, test.m_content ) )
{
return false;
}
else
{
return true;
}
}
public void setSomeProp( final String value )
{
m_someProp = value;
}
public void addProp( final String value )
{
m_propList.add( value );
}
public void addContent( final String content )
{
m_content = content;
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestTypedConfigProp.java
Index: ConfigTestTypedConfigProp.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
import org.apache.avalon.framework.configuration.Configuration;
/**
* Simple class to test adder for Configurations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:45 $
*/
public class ConfigTestTypedConfigProp
{
private ArrayList m_configurations = new ArrayList();
public void add( final Configuration configuration )
{
m_configurations.add( configuration );
}
public boolean equals( final Object object )
{
final ConfigTestTypedConfigProp other =
(ConfigTestTypedConfigProp)object;
return m_configurations.equals( other.m_configurations );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestTypedProp.java
Index: ConfigTestTypedProp.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import java.util.ArrayList;
/**
* Simple class to test typed adder.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:45 $
*/
public class ConfigTestTypedProp
{
private ArrayList m_roles = new ArrayList();
public void add( final MyRole1 role1 )
{
m_roles.add( role1 );
}
public boolean equals( final Object object )
{
final ConfigTestTypedProp other = (ConfigTestTypedProp)object;
return m_roles.equals( other.m_roles );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/MyRole1Adaptor.java
Index: MyRole1Adaptor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import org.apache.myrmidon.AbstractMyrmidonTest;
/**
* Adapts an Object to MyRole
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:45 $
*/
public class MyRole1Adaptor
implements MyRole1
{
private final Object m_object;
public MyRole1Adaptor( final Object o )
{
m_object = o;
}
public boolean equals( Object obj )
{
final MyRole1Adaptor adaptor = (MyRole1Adaptor)obj;
return AbstractMyrmidonTest.equals( m_object, adaptor.m_object );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ObjectToMyRole1Converter.java
Index: ObjectToMyRole1Converter.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.configurer;
import org.apache.aut.converter.AbstractConverter;
import org.apache.aut.converter.ConverterException;
/**
* Converts from Object to MyRole1.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/02/25 10:42:45 $
*/
public class ObjectToMyRole1Converter
extends AbstractConverter
{
public ObjectToMyRole1Converter()
{
super( Object.class, MyRole1.class );
}
protected Object convert( Object original, Object context )
throws ConverterException
{
return new MyRole1Adaptor( original );
}
}
1.10 +7 -9
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java
Index: DefaultDeployerTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DefaultDeployerTest.java 21 Feb 2002 12:52:07 -0000 1.9
+++ DefaultDeployerTest.java 25 Feb 2002 10:42:45 -0000 1.10
@@ -7,21 +7,19 @@
*/
package org.apache.myrmidon.components.deployer;
+import java.io.File;
+import org.apache.aut.converter.Converter;
+import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.components.AbstractComponentTest;
import org.apache.myrmidon.framework.DataType;
-import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
-import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
-import org.apache.myrmidon.interfaces.type.TypeFactory;
-import org.apache.myrmidon.interfaces.type.TypeManager;
+import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.TypeException;
-import org.apache.aut.converter.ConverterException;
-import org.apache.aut.converter.Converter;
-import java.io.File;
+import org.apache.myrmidon.interfaces.type.TypeFactory;
/**
* Test cases for the default deployer.
@@ -37,7 +35,7 @@
private Deployer m_deployer;
private RoleManager m_roleManager;
- private MasterConverter m_converter;
+ private Converter m_converter;
public DefaultDeployerTest( final String name )
{
@@ -52,7 +50,7 @@
{
super.setUp();
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE );
- m_converter = (MasterConverter)getServiceManager().lookup(
MasterConverter.ROLE );
+ m_converter = (Converter)getServiceManager().lookup( Converter.ROLE
);
// Add some core roles
m_roleManager = (RoleManager)getServiceManager().lookup(
RoleManager.ROLE );
1.4 +0 -1
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/TestConverter1.java
Index: TestConverter1.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/TestConverter1.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestConverter1.java 21 Feb 2002 10:16:43 -0000 1.3
+++ TestConverter1.java 25 Feb 2002 10:42:45 -0000 1.4
@@ -9,7 +9,6 @@
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
-import org.apache.avalon.framework.context.Context;
/**
* A test converter.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>