* 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. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271539 13f79535-47bb-0310-9956-ffa450edef68master
@@ -455,11 +455,11 @@ Legal: | |||||
</jar> | </jar> | ||||
<junit printsummary="on" | <junit printsummary="on" | ||||
fork="true"> | |||||
fork="false"> | |||||
<formatter type="brief" usefile="false"/> | <formatter type="brief" usefile="false"/> | ||||
<classpath> | <classpath> | ||||
<fileset dir="${test.working.dir}/dist/bin/lib" includes="**/*.jar"/> | <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> | ||||
<classpath location="${test.classes}"/> | <classpath location="${test.classes}"/> | ||||
@@ -37,8 +37,7 @@ public abstract class AbstractTask | |||||
/** | /** | ||||
* Execute task. | * Execute task. | ||||
* This method is called to perform actual work associated with 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 | * @exception TaskException if an error occurs | ||||
*/ | */ | ||||
@@ -0,0 +1,47 @@ | |||||
/* | |||||
* 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:peter@apache.org">Peter Donald</a> | |||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
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(); | |||||
} |
@@ -8,7 +8,6 @@ | |||||
package org.apache.myrmidon.api; | package org.apache.myrmidon.api; | ||||
import java.io.File; | import java.io.File; | ||||
import java.util.Map; | |||||
import org.apache.avalon.framework.Enum; | import org.apache.avalon.framework.Enum; | ||||
/** | /** | ||||
@@ -21,6 +20,7 @@ import org.apache.avalon.framework.Enum; | |||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public interface TaskContext | public interface TaskContext | ||||
extends Context | |||||
{ | { | ||||
//these values are used when setting properties to indicate the scope at | //these values are used when setting properties to indicate the scope at | ||||
//which properties are set | //which properties are set | ||||
@@ -72,33 +72,6 @@ public interface TaskContext | |||||
File resolveFile( String filename ) | File resolveFile( String filename ) | ||||
throws TaskException; | 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. | * Set property value in current context. | ||||
* | * | ||||
@@ -10,20 +10,21 @@ package org.apache.myrmidon.components.configurer; | |||||
import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
import java.util.ArrayList; | 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.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.framework.configuration.Configurable; | import org.apache.avalon.framework.configuration.Configurable; | ||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
import org.apache.avalon.framework.configuration.ConfigurationException; | 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.AbstractLogEnabled; | ||||
import org.apache.avalon.framework.logger.LogEnabled; | 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.ServiceException; | ||||
import org.apache.avalon.framework.service.ServiceManager; | 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.configurer.Configurer; | ||||
import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
/** | /** | ||||
* Class used to configure tasks. | * Class used to configure tasks. | ||||
@@ -41,12 +42,12 @@ public class ClassicConfigurer | |||||
private static final boolean DEBUG = false; | private static final boolean DEBUG = false; | ||||
///Converter to use for converting between values | ///Converter to use for converting between values | ||||
private MasterConverter m_converter; | |||||
private Converter m_converter; | |||||
public void service( final ServiceManager serviceManager ) | public void service( final ServiceManager serviceManager ) | ||||
throws ServiceException | throws ServiceException | ||||
{ | { | ||||
m_converter = (MasterConverter)serviceManager.lookup( MasterConverter.ROLE ); | |||||
m_converter = (Converter)serviceManager.lookup( Converter.ROLE ); | |||||
} | } | ||||
/** | /** | ||||
@@ -216,16 +217,14 @@ public class ClassicConfigurer | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
final Object objectValue = | |||||
PropertyUtil.resolveProperty( value, context, false ); | |||||
final Object objectValue = context.resolveValue( value ); | |||||
setValue( object, objectValue, methods, context ); | setValue( object, objectValue, methods, context ); | ||||
} | } | ||||
catch( final PropertyException pe ) | |||||
catch( final TaskException te ) | |||||
{ | { | ||||
final String message = | final String message = | ||||
REZ.getString( "bad-property-resolve.error", value ); | REZ.getString( "bad-property-resolve.error", value ); | ||||
throw new ConfigurationException( message, pe ); | |||||
throw new ConfigurationException( message, te ); | |||||
} | } | ||||
} | } | ||||
@@ -9,22 +9,21 @@ package org.apache.myrmidon.components.configurer; | |||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | 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.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.framework.configuration.Configurable; | import org.apache.avalon.framework.configuration.Configurable; | ||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
import org.apache.avalon.framework.configuration.ConfigurationException; | 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.AbstractLogEnabled; | ||||
import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
import org.apache.avalon.framework.service.ServiceException; | import org.apache.avalon.framework.service.ServiceException; | ||||
import org.apache.avalon.framework.service.ServiceManager; | import org.apache.avalon.framework.service.ServiceManager; | ||||
import org.apache.avalon.framework.service.Serviceable; | import org.apache.avalon.framework.service.Serviceable; | ||||
import org.apache.myrmidon.api.Context; | |||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | 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.RoleInfo; | ||||
import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
@@ -44,7 +43,7 @@ public class DefaultConfigurer | |||||
ResourceManager.getPackageResources( DefaultConfigurer.class ); | ResourceManager.getPackageResources( DefaultConfigurer.class ); | ||||
///Converter to use for converting between values | ///Converter to use for converting between values | ||||
private MasterConverter m_converter; | |||||
private Converter m_converter; | |||||
//TypeManager to use to create types in typed adders | //TypeManager to use to create types in typed adders | ||||
private TypeManager m_typeManager; | private TypeManager m_typeManager; | ||||
@@ -59,7 +58,7 @@ public class DefaultConfigurer | |||||
public void service( final ServiceManager serviceManager ) | public void service( final ServiceManager serviceManager ) | ||||
throws ServiceException | throws ServiceException | ||||
{ | { | ||||
m_converter = (MasterConverter)serviceManager.lookup( MasterConverter.ROLE ); | |||||
m_converter = (Converter)serviceManager.lookup( Converter.ROLE ); | |||||
m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE ); | m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE ); | ||||
m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE ); | m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE ); | ||||
} | } | ||||
@@ -140,7 +139,7 @@ public class DefaultConfigurer | |||||
{ | { | ||||
final String message = | final String message = | ||||
REZ.getString( "no-such-attribute.error", elemName, name ); | REZ.getString( "no-such-attribute.error", elemName, name ); | ||||
throw new ReportableConfigurationException( message, nspe ); | |||||
throw new ReportableConfigurationException( message ); | |||||
} | } | ||||
catch( final Exception ce ) | catch( final Exception ce ) | ||||
{ | { | ||||
@@ -187,7 +186,7 @@ public class DefaultConfigurer | |||||
{ | { | ||||
final String message = | final String message = | ||||
REZ.getString( "no-such-element.error", elemName, name ); | REZ.getString( "no-such-element.error", elemName, name ); | ||||
throw new ReportableConfigurationException( message, nspe ); | |||||
throw new ReportableConfigurationException( message ); | |||||
} | } | ||||
catch( final ReportableConfigurationException ce ) | catch( final ReportableConfigurationException ce ) | ||||
{ | { | ||||
@@ -349,26 +348,29 @@ public class DefaultConfigurer | |||||
= getConfigurerFromName( state.getConfigurer(), name, false ); | = getConfigurerFromName( state.getConfigurer(), name, false ); | ||||
// Resolve any props in the id | // Resolve any props in the id | ||||
Object id = PropertyUtil.resolveProperty( unresolvedId, context, false ); | |||||
String id = context.resolveValue( unresolvedId ).toString(); | |||||
// Locate the referenced object | // 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 ); | 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(); | final Class type = childConfigurer.getType(); | ||||
if( !type.isInstance( ref ) ) | 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 | // Set the child element | ||||
@@ -408,17 +410,14 @@ public class DefaultConfigurer | |||||
throws Exception | throws Exception | ||||
{ | { | ||||
// Resolve property references in the attribute value | // 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 | // 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 | // Set the value | ||||
setter.addValue( state, objValue ); | setter.addValue( state, objValue ); | ||||
@@ -451,27 +450,38 @@ public class DefaultConfigurer | |||||
{ | { | ||||
final String name = element.getName(); | final String name = element.getName(); | ||||
final Class type = childConfigurer.getType(); | 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) | //special case where you have add...(Configuration) | ||||
return element; | 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 | else | ||||
{ | { | ||||
child = createObject( type ); | |||||
// Named property | |||||
child = createNamedObject( type ); | |||||
} | } | ||||
} | } | ||||
// Configure the object | |||||
configureObject( child, element, context ); | configureObject( child, element, context ); | ||||
// Convert the object, if necessary | |||||
if( ! type.isInstance( child ) ) | |||||
{ | |||||
child = m_converter.convert( type, child, context ); | |||||
} | |||||
return child; | return child; | ||||
} | } | ||||
@@ -521,38 +531,61 @@ public class DefaultConfigurer | |||||
} | } | ||||
/** | /** | ||||
* 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 | 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,37 +0,0 @@ | |||||
/* | |||||
* 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; | |||||
/** | |||||
* Exception thrown when evaluating a property. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class PropertyException | |||||
extends Exception | |||||
{ | |||||
/** | |||||
* Basic constructor for exception that does not specify a message | |||||
*/ | |||||
public PropertyException() | |||||
{ | |||||
this( "" ); | |||||
} | |||||
/** | |||||
* Basic constructor with a message | |||||
* | |||||
* @param message the message | |||||
*/ | |||||
public PropertyException( final String message ) | |||||
{ | |||||
super( message ); | |||||
} | |||||
} | |||||
@@ -1,6 +1,6 @@ | |||||
create-object.error=Could not create an object of class {0}. | 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. | 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}". | 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-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}. | multiple-creator-methods-for-element.error=Multiple {1}() methods found in class {0}. | ||||
@@ -9,16 +9,13 @@ pending-property-value.error=An object created using the creator method has not | |||||
must-be-element.error=This property must be configured using a nested element. | must-be-element.error=This property must be configured using a nested element. | ||||
too-many-values.error=Too many values for this property. | 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-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-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}. | 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}>. | 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. | 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}. | create-typed-object.error=Could not create an object of type "{0}" of class {1}. | ||||
unknown-reference.error=Could not find referenced object "{0}". | unknown-reference.error=Could not find referenced object "{0}". | ||||
bad-configure-element.error=Could not configure element <{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. |
@@ -7,6 +7,9 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.converter; | 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.Converter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
@@ -16,7 +19,6 @@ import org.apache.avalon.framework.service.ServiceException; | |||||
import org.apache.avalon.framework.service.ServiceManager; | import org.apache.avalon.framework.service.ServiceManager; | ||||
import org.apache.avalon.framework.service.Serviceable; | import org.apache.avalon.framework.service.Serviceable; | ||||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | 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.TypeException; | ||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
@@ -29,16 +31,17 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
*/ | */ | ||||
public class DefaultMasterConverter | public class DefaultMasterConverter | ||||
extends AbstractLogEnabled | extends AbstractLogEnabled | ||||
implements MasterConverter, Serviceable | |||||
implements Converter, Serviceable | |||||
{ | { | ||||
private final static Resources REZ = | private final static Resources REZ = | ||||
ResourceManager.getPackageResources( DefaultMasterConverter.class ); | ResourceManager.getPackageResources( DefaultMasterConverter.class ); | ||||
private final static boolean DEBUG = false; | |||||
private ConverterRegistry m_registry; | private ConverterRegistry m_registry; | ||||
private TypeFactory m_factory; | private TypeFactory m_factory; | ||||
/** Map from converter name to Converter. */ | |||||
private Map m_converters = new HashMap(); | |||||
/** | /** | ||||
* Retrieve relevent services needed to deploy. | * Retrieve relevent services needed to deploy. | ||||
* | * | ||||
@@ -83,73 +86,109 @@ public class DefaultMasterConverter | |||||
return original; | 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 | 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 ); | final Object object = converter.convert( destination, original, context ); | ||||
if( destination.isInstance( object ) ) | if( destination.isInstance( object ) ) | ||||
{ | { | ||||
return 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, | private String getConverterName( final Class originalClass, | ||||
final Class destination ) | final Class destination ) | ||||
throws ConverterException | 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 ); | throw new ConverterException( message ); | ||||
} | } | ||||
} | } |
@@ -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-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. |
@@ -261,7 +261,7 @@ public class DefaultDeployer | |||||
final String name = roleDef.getShortHand(); | final String name = roleDef.getShortHand(); | ||||
final String role = roleDef.getRoleName(); | final String role = roleDef.getRoleName(); | ||||
final Class type = deployment.getClassLoader().loadClass( role ); | 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 ); | m_roleManager.addRole( roleInfo ); | ||||
if( getLogger().isDebugEnabled() ) | if( getLogger().isDebugEnabled() ) | ||||
@@ -12,6 +12,7 @@ import java.io.FilenameFilter; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.aut.converter.Converter; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.excalibur.io.ExtensionFileFilter; | import org.apache.avalon.excalibur.io.ExtensionFileFilter; | ||||
@@ -29,7 +30,6 @@ import org.apache.myrmidon.interfaces.aspect.AspectManager; | |||||
import org.apache.myrmidon.interfaces.builder.ProjectBuilder; | import org.apache.myrmidon.interfaces.builder.ProjectBuilder; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | 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.Deployer; | ||||
import org.apache.myrmidon.interfaces.deployer.DeploymentException; | import org.apache.myrmidon.interfaces.deployer.DeploymentException; | ||||
import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | ||||
@@ -246,7 +246,7 @@ public class DefaultEmbeddor | |||||
// Create the components | // Create the components | ||||
createComponent( ConverterRegistry.class, PREFIX + "converter.DefaultConverterRegistry" ); | createComponent( ConverterRegistry.class, PREFIX + "converter.DefaultConverterRegistry" ); | ||||
createComponent( ExtensionManager.class, PREFIX + "extensions.DefaultExtensionManager" ); | 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( Configurer.class, PREFIX + "configurer.DefaultConfigurer" ); | ||||
createComponent( TypeManager.class, PREFIX + "type.DefaultTypeManager" ); | createComponent( TypeManager.class, PREFIX + "type.DefaultTypeManager" ); | ||||
createComponent( RoleManager.class, PREFIX + "role.DefaultRoleManager" ); | createComponent( RoleManager.class, PREFIX + "role.DefaultRoleManager" ); | ||||
@@ -13,9 +13,9 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | import org.apache.avalon.framework.logger.AbstractLogEnabled; | ||||
import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
import org.apache.avalon.framework.logger.Logger; | 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.ServiceException; | ||||
import org.apache.avalon.framework.service.ServiceManager; | 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.Task; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
@@ -24,7 +24,6 @@ import org.apache.myrmidon.interfaces.executor.ExecutionFrame; | |||||
import org.apache.myrmidon.interfaces.executor.Executor; | import org.apache.myrmidon.interfaces.executor.Executor; | ||||
import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter; | |||||
/** | /** | ||||
* The basic executor that just executes the tasks. | * The basic executor that just executes the tasks. | ||||
@@ -103,8 +102,7 @@ public class DefaultExecutor | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
final TaskContextAdapter context = new TaskContextAdapter( taskContext ); | |||||
m_configurer.configure( task, taskModel, context ); | |||||
m_configurer.configure( task, taskModel, taskContext ); | |||||
} | } | ||||
catch( final Throwable throwable ) | catch( final Throwable throwable ) | ||||
{ | { | ||||
@@ -14,7 +14,7 @@ import org.apache.myrmidon.interfaces.type.TypeException; | |||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | 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:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
@@ -29,9 +29,9 @@ public class MultiSourceTypeFactory | |||||
private final MultiSourceTypeFactory m_parent; | private final MultiSourceTypeFactory m_parent; | ||||
///Map of name->factory list | ///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; | private final Class m_type; | ||||
public MultiSourceTypeFactory( final Class type ) | public MultiSourceTypeFactory( final Class type ) | ||||
@@ -51,7 +51,7 @@ public class MultiSourceTypeFactory | |||||
*/ | */ | ||||
public void register( final String name, final TypeFactory factory ) | public void register( final String name, final TypeFactory factory ) | ||||
{ | { | ||||
m_factorys.put( name, factory ); | |||||
m_factories.put( name, factory ); | |||||
} | } | ||||
/** | /** | ||||
@@ -118,6 +118,6 @@ public class MultiSourceTypeFactory | |||||
protected final TypeFactory getTypeFactory( final String name ) | protected final TypeFactory getTypeFactory( final String name ) | ||||
{ | { | ||||
return (TypeFactory)m_factorys.get( name ); | |||||
return (TypeFactory)m_factories.get( name ); | |||||
} | } | ||||
} | } |
@@ -13,14 +13,10 @@ import java.util.Map; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.excalibur.io.FileUtil; | 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.ServiceException; | ||||
import org.apache.avalon.framework.service.ServiceManager; | import org.apache.avalon.framework.service.ServiceManager; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | 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. | * Default implementation of TaskContext. | ||||
@@ -73,14 +69,9 @@ public class DefaultTaskContext | |||||
} | } | ||||
/** | /** | ||||
* 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 ); | final Object data = m_contextData.get( key ); | ||||
if( null != data ) | if( null != data ) | ||||
@@ -96,10 +87,10 @@ public class DefaultTaskContext | |||||
if( null == m_parent ) | if( null == m_parent ) | ||||
{ | { | ||||
// There was no parent, and no data | // 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 class DefaultTaskContext | |||||
*/ | */ | ||||
public String getName() | 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 class DefaultTaskContext | |||||
*/ | */ | ||||
public File getBaseDirectory() | 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 @@ public class DefaultTaskContext | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
final TaskContextAdapter context = new TaskContextAdapter( this ); | |||||
final Object object = | final Object object = | ||||
PropertyUtil.resolveProperty( value, context, false ); | |||||
PropertyUtil.resolveProperty( value, this, false ); | |||||
if( null == object ) | if( null == object ) | ||||
{ | { | ||||
@@ -218,10 +191,10 @@ public class DefaultTaskContext | |||||
return object; | return object; | ||||
} | } | ||||
catch( final PropertyException pe ) | |||||
catch( final TaskException te ) | |||||
{ | { | ||||
final String message = REZ.getString( "bad-resolve.error", value ); | final String message = REZ.getString( "bad-resolve.error", value ); | ||||
throw new TaskException( message, pe ); | |||||
throw new TaskException( message, te ); | |||||
} | } | ||||
} | } | ||||
@@ -233,14 +206,7 @@ public class DefaultTaskContext | |||||
*/ | */ | ||||
public Object getProperty( final String name ) | public Object getProperty( final String name ) | ||||
{ | { | ||||
try | |||||
{ | |||||
return get( name ); | |||||
} | |||||
catch( final ContextException ce ) | |||||
{ | |||||
return null; | |||||
} | |||||
return get( name ); | |||||
} | } | ||||
/** | /** | ||||
@@ -248,7 +214,7 @@ public class DefaultTaskContext | |||||
* | * | ||||
* @return the map of all property names to values | * @return the map of all property names to values | ||||
*/ | */ | ||||
public Map getPropertys() | |||||
public Map getProperties() | |||||
{ | { | ||||
return null; | return null; | ||||
} | } | ||||
@@ -59,7 +59,7 @@ public class DefaultWorkspace | |||||
private ServiceManager m_serviceManager; | private ServiceManager m_serviceManager; | ||||
private Parameters m_parameters; | private Parameters m_parameters; | ||||
private TaskContext m_baseContext; | private TaskContext m_baseContext; | ||||
private HashMap m_entrys = new HashMap(); | |||||
private HashMap m_entries = new HashMap(); | |||||
private TypeManager m_typeManager; | private TypeManager m_typeManager; | ||||
private Deployer m_deployer; | private Deployer m_deployer; | ||||
private Hierarchy m_hierarchy; | private Hierarchy m_hierarchy; | ||||
@@ -279,7 +279,7 @@ public class DefaultWorkspace | |||||
private ProjectEntry getProjectEntry( final Project project ) | private ProjectEntry getProjectEntry( final Project project ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
ProjectEntry entry = (ProjectEntry)m_entrys.get( project ); | |||||
ProjectEntry entry = (ProjectEntry)m_entries.get( project ); | |||||
if( null == entry ) | if( null == entry ) | ||||
{ | { | ||||
@@ -287,7 +287,7 @@ public class DefaultWorkspace | |||||
{ | { | ||||
final ExecutionFrame frame = createExecutionFrame( project ); | final ExecutionFrame frame = createExecutionFrame( project ); | ||||
entry = new ProjectEntry( project, frame ); | entry = new ProjectEntry( project, frame ); | ||||
m_entrys.put( project, entry ); | |||||
m_entries.put( project, entry ); | |||||
} | } | ||||
catch( Exception e ) | catch( Exception e ) | ||||
{ | { | ||||
@@ -5,15 +5,15 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | |||||
package org.apache.myrmidon.components.workspace; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.avalon.framework.context.ContextException; | |||||
import org.apache.myrmidon.api.Context; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | /** | ||||
* Utility class to evaluate propertys. | |||||
* Utility class to evaluate properties. | |||||
* | * | ||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
@@ -33,14 +33,14 @@ public final class PropertyUtil | |||||
* | * | ||||
* @param property the property to resolve | * @param property the property to resolve | ||||
* @param context the context in which to resolve property | * @param context the context in which to resolve property | ||||
* @param ignoreUndefined if false will throw an PropertyException if property is not found | |||||
* @param ignoreUndefined if false will throw an TaskException if property is not found | |||||
* @return the reolved property | * @return the reolved property | ||||
* @exception PropertyException if an error occurs | |||||
* @exception TaskException if an error occurs | |||||
*/ | */ | ||||
public static Object resolveProperty( final String property, | public static Object resolveProperty( final String property, | ||||
final Context context, | final Context context, | ||||
final boolean ignoreUndefined ) | final boolean ignoreUndefined ) | ||||
throws PropertyException | |||||
throws TaskException | |||||
{ | { | ||||
int start = findBeginning( property, 0 ); | int start = findBeginning( property, 0 ); | ||||
if( -1 == start ) | if( -1 == start ) | ||||
@@ -94,14 +94,14 @@ public final class PropertyUtil | |||||
* | * | ||||
* @param property the property to resolve | * @param property the property to resolve | ||||
* @param context the context in which to resolve property | * @param context the context in which to resolve property | ||||
* @param ignoreUndefined if false will throw an PropertyException if property is not found | |||||
* @param ignoreUndefined if false will throw an TaskException if property is not found | |||||
* @return the reolved property | * @return the reolved property | ||||
* @exception PropertyException if an error occurs | |||||
* @exception TaskException if an error occurs | |||||
*/ | */ | ||||
public static Object recursiveResolveProperty( final String property, | public static Object recursiveResolveProperty( final String property, | ||||
final Context context, | final Context context, | ||||
final boolean ignoreUndefined ) | final boolean ignoreUndefined ) | ||||
throws PropertyException | |||||
throws TaskException | |||||
{ | { | ||||
int start = findBeginning( property, 0 ); | int start = findBeginning( property, 0 ); | ||||
if( -1 == start ) | if( -1 == start ) | ||||
@@ -156,21 +156,21 @@ public final class PropertyUtil | |||||
} | } | ||||
private static int findEnding( final String property, final int currentPosition ) | private static int findEnding( final String property, final int currentPosition ) | ||||
throws PropertyException | |||||
throws TaskException | |||||
{ | { | ||||
//TODO: Check if it is commented out | //TODO: Check if it is commented out | ||||
final int index = property.indexOf( '}', currentPosition ); | final int index = property.indexOf( '}', currentPosition ); | ||||
if( -1 == index ) | if( -1 == index ) | ||||
{ | { | ||||
final String message = REZ.getString( "prop.mismatched-braces.error" ); | final String message = REZ.getString( "prop.mismatched-braces.error" ); | ||||
throw new PropertyException( message ); | |||||
throw new TaskException( message ); | |||||
} | } | ||||
return index; | return index; | ||||
} | } | ||||
private static int findNestedEnding( final String property, final int currentPosition ) | private static int findNestedEnding( final String property, final int currentPosition ) | ||||
throws PropertyException | |||||
throws TaskException | |||||
{ | { | ||||
final int length = property.length(); | final int length = property.length(); | ||||
final int start = currentPosition + 2; | final int start = currentPosition + 2; | ||||
@@ -204,42 +204,36 @@ public final class PropertyUtil | |||||
} | } | ||||
final String message = REZ.getString( "prop.mismatched-braces.error" ); | final String message = REZ.getString( "prop.mismatched-braces.error" ); | ||||
throw new PropertyException( message ); | |||||
throw new TaskException( message ); | |||||
} | } | ||||
/** | /** | ||||
* Retrieve a value from the specified context using the specified key. | * Retrieve a value from the specified context using the specified key. | ||||
* If there is no such value and ignoreUndefined is not false then a | * If there is no such value and ignoreUndefined is not false then a | ||||
* PropertyException is generated. | |||||
* TaskException is generated. | |||||
* | * | ||||
* @param key the key of value in context | * @param key the key of value in context | ||||
* @param context the Context | * @param context the Context | ||||
* @param ignoreUndefined true if undefined variables are ignored | * @param ignoreUndefined true if undefined variables are ignored | ||||
* @return the object retrieved from context | * @return the object retrieved from context | ||||
* @exception PropertyException if an error occurs | |||||
* @exception TaskException if an error occurs | |||||
*/ | */ | ||||
private static Object resolveValue( final String key, | private static Object resolveValue( final String key, | ||||
final Context context, | final Context context, | ||||
final boolean ignoreUndefined ) | final boolean ignoreUndefined ) | ||||
throws PropertyException | |||||
throws TaskException | |||||
{ | { | ||||
try | |||||
final Object value = context.getProperty( key ); | |||||
if( value != null ) | |||||
{ | { | ||||
return context.get( key ); | |||||
return value; | |||||
} | } | ||||
catch( final ContextException ce ) | |||||
if( ignoreUndefined ) | |||||
{ | { | ||||
if( ignoreUndefined ) | |||||
{ | |||||
return ""; | |||||
} | |||||
else | |||||
{ | |||||
final String message = | |||||
REZ.getString( "prop.missing-value.error", key ); | |||||
throw new PropertyException( message ); | |||||
} | |||||
return ""; | |||||
} | } | ||||
final String message = REZ.getString( "prop.missing-value.error", key ); | |||||
throw new TaskException( message ); | |||||
} | } | ||||
} | } | ||||
@@ -20,4 +20,8 @@ bad-property.error=Property {0} must have a value of type {1}. | |||||
null-resolved-value.error=Value "{0}" resolved to null. | null-resolved-value.error=Value "{0}" resolved to null. | ||||
bad-resolve.error=Unable to resolve value "{0}". | bad-resolve.error=Unable to resolve value "{0}". | ||||
bad-find-service.error=Could not find service "{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}. | |||||
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. |
@@ -7,6 +7,8 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.framework; | 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.ResourceManager; | ||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
@@ -14,15 +16,11 @@ import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | 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.configurer.Configurer; | ||||
import org.apache.myrmidon.interfaces.converter.MasterConverter; | |||||
import org.apache.myrmidon.interfaces.executor.Executor; | import org.apache.myrmidon.interfaces.executor.Executor; | ||||
import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
import org.apache.myrmidon.interfaces.type.TypeManager; | 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. | * This is the class that Task writers should extend to provide custom tasks. | ||||
@@ -37,7 +35,7 @@ public abstract class AbstractContainerTask | |||||
ResourceManager.getPackageResources( AbstractContainerTask.class ); | ResourceManager.getPackageResources( AbstractContainerTask.class ); | ||||
///For converting own attributes | ///For converting own attributes | ||||
private MasterConverter m_converter; | |||||
private Converter m_converter; | |||||
///For configuring own sub-elements | ///For configuring own sub-elements | ||||
private Configurer m_configurer; | private Configurer m_configurer; | ||||
@@ -55,7 +53,7 @@ public abstract class AbstractContainerTask | |||||
{ | { | ||||
super.contextualize( context ); | super.contextualize( context ); | ||||
m_configurer = (Configurer)getService( Configurer.class ); | m_configurer = (Configurer)getService( Configurer.class ); | ||||
m_converter = (MasterConverter)getService( MasterConverter.class ); | |||||
m_converter = (Converter)getService( Converter.class ); | |||||
m_executor = (Executor)getService( Executor.class ); | m_executor = (Executor)getService( Executor.class ); | ||||
} | } | ||||
@@ -91,8 +89,7 @@ public abstract class AbstractContainerTask | |||||
protected final void configure( final Object object, final Configuration element ) | protected final void configure( final Object object, final Configuration element ) | ||||
throws ConfigurationException | throws ConfigurationException | ||||
{ | { | ||||
final TaskContextAdapter context = new TaskContextAdapter( getContext() ); | |||||
getConfigurer().configure( object, element, context ); | |||||
getConfigurer().configure( object, element, getContext() ); | |||||
} | } | ||||
/** | /** | ||||
@@ -106,8 +103,7 @@ public abstract class AbstractContainerTask | |||||
protected final void configure( final Object object, final String name, final String value ) | protected final void configure( final Object object, final String name, final String value ) | ||||
throws ConfigurationException | throws ConfigurationException | ||||
{ | { | ||||
final TaskContextAdapter context = new TaskContextAdapter( getContext() ); | |||||
getConfigurer().configure( object, name, value, context ); | |||||
getConfigurer().configure( object, name, value, getContext() ); | |||||
} | } | ||||
/** | /** | ||||
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.myrmidon.framework.factorys; | |||||
package org.apache.myrmidon.framework.factories; | |||||
import java.io.File; | import java.io.File; | ||||
import org.apache.aut.nativelib.ExecException; | import org.apache.aut.nativelib.ExecException; |
@@ -5,7 +5,7 @@ | |||||
* version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
* the LICENSE.txt file. | * the LICENSE.txt file. | ||||
*/ | */ | ||||
package org.apache.myrmidon.framework.factorys; | |||||
package org.apache.myrmidon.framework.factories; | |||||
import org.apache.aut.vfs.FileSystemManager; | import org.apache.aut.vfs.FileSystemManager; | ||||
import org.apache.aut.vfs.impl.DefaultFileSystemManager; | import org.apache.aut.vfs.impl.DefaultFileSystemManager; |
@@ -9,7 +9,7 @@ package org.apache.myrmidon.interfaces.configurer; | |||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
import org.apache.avalon.framework.configuration.ConfigurationException; | 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. | * Class used to configure tasks. | ||||
@@ -1,50 +0,0 @@ | |||||
/* | |||||
* 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.interfaces.configurer; | |||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.avalon.framework.context.ContextException; | |||||
import org.apache.avalon.framework.context.Resolvable; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
/** | |||||
* This class adpats the TaskContext API to the Avalon Context API. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class TaskContextAdapter | |||||
implements Context, Resolvable | |||||
{ | |||||
private final TaskContext m_context; | |||||
public TaskContextAdapter( final TaskContext context ) | |||||
{ | |||||
m_context = context; | |||||
} | |||||
public Object resolve( Context context ) | |||||
throws ContextException | |||||
{ | |||||
return m_context; | |||||
} | |||||
public Object get( Object key ) | |||||
throws ContextException | |||||
{ | |||||
final Object value = m_context.getProperty( key.toString() ); | |||||
if( null != value ) | |||||
{ | |||||
return value; | |||||
} | |||||
else | |||||
{ | |||||
throw new ContextException( "Missing key " + key ); | |||||
} | |||||
} | |||||
} |
@@ -1,22 +0,0 @@ | |||||
/* | |||||
* 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.interfaces.converter; | |||||
import org.apache.aut.converter.Converter; | |||||
/** | |||||
* Master Converter to handle converting between types. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public interface MasterConverter | |||||
extends Converter | |||||
{ | |||||
String ROLE = MasterConverter.class.getName(); | |||||
} |
@@ -20,6 +20,7 @@ public final class RoleInfo | |||||
private final String m_name; | private final String m_name; | ||||
private final String m_shorthand; | private final String m_shorthand; | ||||
private final Class m_type; | private final Class m_type; | ||||
private final String m_defaultType; | |||||
/** | /** | ||||
* Creates a role definition. | * Creates a role definition. | ||||
@@ -28,9 +29,7 @@ public final class RoleInfo | |||||
*/ | */ | ||||
public RoleInfo( final String name ) | public RoleInfo( final String name ) | ||||
{ | { | ||||
m_name = name; | |||||
m_shorthand = null; | |||||
m_type = null; | |||||
this( name, null, null, null ); | |||||
} | } | ||||
/** | /** | ||||
@@ -41,9 +40,7 @@ public final class RoleInfo | |||||
*/ | */ | ||||
public RoleInfo( final String name, final String shorthand ) | 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 final class RoleInfo | |||||
*/ | */ | ||||
public RoleInfo( final String name, final String shorthand, final Class type ) | 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 final class RoleInfo | |||||
*/ | */ | ||||
public RoleInfo( final String shorthand, final Class type ) | 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_shorthand = shorthand; | ||||
m_type = type; | m_type = type; | ||||
m_defaultType = defaultType; | |||||
} | } | ||||
/** | /** | ||||
@@ -127,4 +134,14 @@ public final class RoleInfo | |||||
{ | { | ||||
return m_type; | 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; | |||||
} | |||||
} | } |
@@ -88,7 +88,7 @@ public class Script extends AbstractTask | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
addBeans( getContext().getPropertys() ); | |||||
addBeans( getContext().getProperties() ); | |||||
//In Ant2 there is no difference between properties and references | //In Ant2 there is no difference between properties and references | ||||
//addBeans( getProject().getReferences() ); | //addBeans( getProject().getReferences() ); | ||||
@@ -617,7 +617,7 @@ public class JUnitTask extends AbstractTask | |||||
// Create a temporary file to pass the Ant properties to the forked test | // Create a temporary file to pass the Ant properties to the forked test | ||||
File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" ); | File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" ); | ||||
cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() ); | cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() ); | ||||
Map p = getContext().getPropertys(); | |||||
Map p = getContext().getProperties(); | |||||
Properties props = new Properties(); | Properties props = new Properties(); | ||||
for( Iterator enum = p.keySet().iterator(); enum.hasNext(); ) | for( Iterator enum = p.keySet().iterator(); enum.hasNext(); ) | ||||
{ | { | ||||
@@ -663,7 +663,7 @@ public class JUnitTask extends AbstractTask | |||||
private int executeInVM( JUnitTest test ) | private int executeInVM( JUnitTest test ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
test.setProperties( getContext().getPropertys() ); | |||||
test.setProperties( getContext().getProperties() ); | |||||
if( dir != null ) | if( dir != null ) | ||||
{ | { | ||||
getLogger().warn( "dir attribute ignored if running in the same VM" ); | getLogger().warn( "dir attribute ignored if running in the same VM" ); | ||||
@@ -7,7 +7,6 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.types.converters; | 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.AbstractConverter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
@@ -1,6 +1,6 @@ | |||||
<services version="1.0"> | <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="zip" classname="org.apache.aut.vfs.provider.zip.ZipFileSystemProvider"/> | ||||
<provider scheme="jar" 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"/> | <provider scheme="smb" classname="org.apache.aut.vfs.provider.smb.SmbFileSystemProvider"/> | ||||
@@ -50,6 +50,9 @@ public class AbstractProjectTest | |||||
{ | { | ||||
if( m_embeddor == null ) | if( m_embeddor == null ) | ||||
{ | { | ||||
// Need to set the context classloader - The default embeddor uses it | |||||
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() ); | |||||
final Logger logger = createLogger(); | final Logger logger = createLogger(); | ||||
m_embeddor = new DefaultEmbeddor(); | m_embeddor = new DefaultEmbeddor(); | ||||
m_embeddor.enableLogging( logger ); | m_embeddor.enableLogging( logger ); | ||||
@@ -29,9 +29,9 @@ import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
import org.apache.myrmidon.components.type.DefaultTypeManager; | import org.apache.myrmidon.components.type.DefaultTypeManager; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | 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.Deployer; | ||||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | 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.role.RoleManager; | ||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
@@ -83,7 +83,7 @@ public abstract class AbstractComponentTest | |||||
List components = new ArrayList(); | List components = new ArrayList(); | ||||
Object component = new DefaultMasterConverter(); | Object component = new DefaultMasterConverter(); | ||||
m_serviceManager.put( MasterConverter.ROLE, component ); | |||||
m_serviceManager.put( Converter.ROLE, component ); | |||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultConverterRegistry(); | component = new DefaultConverterRegistry(); | ||||
@@ -138,6 +138,29 @@ public abstract class AbstractComponentTest | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 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. | * Utility method to register a Converter. | ||||
@@ -7,8 +7,7 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
/** | /** | ||||
* Simple class to test typed adder. | * Simple class to test typed adder. | ||||
@@ -8,7 +8,6 @@ | |||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
/** | /** | ||||
@@ -17,7 +16,7 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest8 | |||||
public class ConfigTestConfigProps | |||||
{ | { | ||||
private ArrayList m_configurations = new ArrayList(); | private ArrayList m_configurations = new ArrayList(); | ||||
@@ -28,7 +27,7 @@ public class ConfigTest8 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest8 other = (ConfigTest8)object; | |||||
final ConfigTestConfigProps other = (ConfigTestConfigProps)object; | |||||
return m_configurations.equals( other.m_configurations ); | return m_configurations.equals( other.m_configurations ); | ||||
} | } | ||||
} | } |
@@ -7,19 +7,17 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.configuration.Configurable; | 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.configuration.ConfigurationException; | ||||
/** | /** | ||||
* Simple class to test adder for Configurations. | |||||
* Simple class to test {@link Configurable}. | |||||
* | * | ||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest9 | |||||
public class ConfigTestConfigurable | |||||
implements Configurable | implements Configurable | ||||
{ | { | ||||
private Configuration m_configuration; | private Configuration m_configuration; | ||||
@@ -32,7 +30,7 @@ public class ConfigTest9 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest9 other = (ConfigTest9)object; | |||||
final ConfigTestConfigurable other = (ConfigTestConfigurable)object; | |||||
return m_configuration == other.m_configuration; | return m_configuration == other.m_configuration; | ||||
} | } | ||||
} | } |
@@ -0,0 +1,32 @@ | |||||
/* | |||||
* 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:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
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 ); | |||||
} | |||||
} |
@@ -15,15 +15,15 @@ import junit.framework.AssertionFailedError; | |||||
* | * | ||||
* @author Adam Murdoch | * @author Adam Murdoch | ||||
*/ | */ | ||||
public class ConfigTest3 | |||||
public class ConfigTestMultiSetter | |||||
{ | { | ||||
private ConfigTest1 m_prop1; | |||||
private ConfigTest1 m_prop2; | |||||
private ConfigTestStringProps m_prop1; | |||||
private ConfigTestStringProps m_prop2; | |||||
private ArrayList m_prop3 = new ArrayList(); | private ArrayList m_prop3 = new ArrayList(); | ||||
public boolean equals( Object obj ) | public boolean equals( Object obj ) | ||||
{ | { | ||||
ConfigTest3 test = (ConfigTest3)obj; | |||||
ConfigTestMultiSetter test = (ConfigTestMultiSetter)obj; | |||||
if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) ) | if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) ) | ||||
{ | { | ||||
return false; | return false; | ||||
@@ -48,7 +48,7 @@ public class ConfigTest3 | |||||
throw new AssertionFailedError(); | throw new AssertionFailedError(); | ||||
} | } | ||||
public void setProp1( final ConfigTest1 value ) | |||||
public void setProp1( final ConfigTestStringProps value ) | |||||
{ | { | ||||
m_prop1 = value; | m_prop1 = value; | ||||
} | } | ||||
@@ -62,7 +62,7 @@ public class ConfigTest3 | |||||
throw new AssertionFailedError(); | throw new AssertionFailedError(); | ||||
} | } | ||||
public void setProp2( final ConfigTest1 value ) | |||||
public void setProp2( final ConfigTestStringProps value ) | |||||
{ | { | ||||
m_prop2 = value; | m_prop2 = value; | ||||
} | } | ||||
@@ -76,7 +76,7 @@ public class ConfigTest3 | |||||
throw new AssertionFailedError(); | throw new AssertionFailedError(); | ||||
} | } | ||||
public void addProp3( final ConfigTest1 value ) | |||||
public void addProp3( final ConfigTestStringProps value ) | |||||
{ | { | ||||
m_prop3.add( value ); | m_prop3.add( value ); | ||||
} | } |
@@ -7,17 +7,15 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
/** | /** | ||||
* Simple class to test typed adder. | |||||
* Simple class with more than one typed adder method. | |||||
* | * | ||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest5 | |||||
public class ConfigTestMultiTypedAdder | |||||
{ | { | ||||
public void add( final MyRole1 role1 ) | public void add( final MyRole1 role1 ) | ||||
{ | { |
@@ -15,14 +15,14 @@ import java.util.List; | |||||
* | * | ||||
* @author Adam Murdoch | * @author Adam Murdoch | ||||
*/ | */ | ||||
public class ConfigTest2 | |||||
public class ConfigTestObjectProps | |||||
{ | { | ||||
ConfigTest1 m_prop; | |||||
ConfigTestStringProps m_prop; | |||||
List m_propList = new ArrayList(); | List m_propList = new ArrayList(); | ||||
public boolean equals( Object obj ) | public boolean equals( Object obj ) | ||||
{ | { | ||||
ConfigTest2 test = (ConfigTest2)obj; | |||||
ConfigTestObjectProps test = (ConfigTestObjectProps)obj; | |||||
if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) ) | if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) ) | ||||
{ | { | ||||
return false; | return false; | ||||
@@ -34,12 +34,12 @@ public class ConfigTest2 | |||||
return true; | return true; | ||||
} | } | ||||
public void setProp( final ConfigTest1 test ) | |||||
public void setProp( final ConfigTestStringProps test ) | |||||
{ | { | ||||
m_prop = test; | m_prop = test; | ||||
} | } | ||||
public void addAnotherProp( final ConfigTest1 test ) | |||||
public void addAnotherProp( final ConfigTestStringProps test ) | |||||
{ | { | ||||
m_propList.add( test ); | m_propList.add( test ); | ||||
} | } |
@@ -14,24 +14,24 @@ import org.apache.myrmidon.components.AbstractComponentTest; | |||||
* | * | ||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
*/ | */ | ||||
public class ConfigTest10 | |||||
public class ConfigTestPrimConvert | |||||
{ | { | ||||
private int m_intProp; | private int m_intProp; | ||||
private Integer m_integerProp; | private Integer m_integerProp; | ||||
public void setIntProp( int intProp ) | |||||
public void setIntProp( final int intProp ) | |||||
{ | { | ||||
m_intProp = intProp; | m_intProp = intProp; | ||||
} | } | ||||
public void setIntegerProp( Integer integerProp ) | |||||
public void setIntegerProp( final Integer integerProp ) | |||||
{ | { | ||||
m_integerProp = integerProp; | m_integerProp = integerProp; | ||||
} | } | ||||
public boolean equals( Object obj ) | public boolean equals( Object obj ) | ||||
{ | { | ||||
ConfigTest10 test = (ConfigTest10)obj; | |||||
ConfigTestPrimConvert test = (ConfigTestPrimConvert)obj; | |||||
if( m_intProp != test.m_intProp ) | if( m_intProp != test.m_intProp ) | ||||
{ | { | ||||
return false; | return false; |
@@ -9,13 +9,15 @@ package org.apache.myrmidon.components.configurer; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | /** | ||||
* A simple test class. | |||||
* A simple test class with string properties. | |||||
* | * | ||||
* @author Adam Murdoch | * @author Adam Murdoch | ||||
*/ | */ | ||||
public class ConfigTest1 | |||||
public class ConfigTestStringProps | |||||
implements DataType | |||||
{ | { | ||||
private String m_someProp; | private String m_someProp; | ||||
private List m_propList = new ArrayList(); | private List m_propList = new ArrayList(); | ||||
@@ -23,7 +25,7 @@ public class ConfigTest1 | |||||
public boolean equals( final Object obj ) | public boolean equals( final Object obj ) | ||||
{ | { | ||||
final ConfigTest1 test = (ConfigTest1)obj; | |||||
final ConfigTestStringProps test = (ConfigTestStringProps)obj; | |||||
if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) ) | if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) ) | ||||
{ | { | ||||
return false; | return false; |
@@ -8,7 +8,6 @@ | |||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
/** | /** | ||||
@@ -17,7 +16,7 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest7 | |||||
public class ConfigTestTypedConfigProp | |||||
{ | { | ||||
private ArrayList m_configurations = new ArrayList(); | private ArrayList m_configurations = new ArrayList(); | ||||
@@ -28,7 +27,7 @@ public class ConfigTest7 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest7 other = (ConfigTest7)object; | |||||
final ConfigTestTypedConfigProp other = (ConfigTestTypedConfigProp)object; | |||||
return m_configurations.equals( other.m_configurations ); | return m_configurations.equals( other.m_configurations ); | ||||
} | } | ||||
} | } |
@@ -8,8 +8,6 @@ | |||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
/** | /** | ||||
* Simple class to test typed adder. | * Simple class to test typed adder. | ||||
@@ -17,7 +15,7 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest6 | |||||
public class ConfigTestTypedProp | |||||
{ | { | ||||
private ArrayList m_roles = new ArrayList(); | private ArrayList m_roles = new ArrayList(); | ||||
@@ -28,7 +26,7 @@ public class ConfigTest6 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest6 other = (ConfigTest6)object; | |||||
final ConfigTestTypedProp other = (ConfigTestTypedProp)object; | |||||
return m_roles.equals( other.m_roles ); | return m_roles.equals( other.m_roles ); | ||||
} | } | ||||
} | } |
@@ -13,16 +13,12 @@ import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.components.AbstractComponentTest; | import org.apache.myrmidon.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | 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.RoleInfo; | ||||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||||
/** | /** | ||||
* Test cases for the default configurer and related classes. | * Test cases for the default configurer and related classes. | ||||
@@ -37,7 +33,6 @@ public class DefaultConfigurerTest | |||||
private Configurer m_configurer; | private Configurer m_configurer; | ||||
private DefaultTaskContext m_context; | private DefaultTaskContext m_context; | ||||
private Context m_adaptor; | |||||
public DefaultConfigurerTest( String name ) | public DefaultConfigurerTest( String name ) | ||||
{ | { | ||||
@@ -59,7 +54,6 @@ public class DefaultConfigurerTest | |||||
m_context = new DefaultTaskContext(); | m_context = new DefaultTaskContext(); | ||||
final File baseDir = new File( "." ).getAbsoluteFile(); | final File baseDir = new File( "." ).getAbsoluteFile(); | ||||
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | ||||
m_adaptor = new TaskContextAdapter( m_context ); | |||||
} | } | ||||
/** | /** | ||||
@@ -75,13 +69,13 @@ public class DefaultConfigurerTest | |||||
final String value2 = "some other value"; | final String value2 = "some other value"; | ||||
config.setAttribute( "prop", value2 ); | config.setAttribute( "prop", value2 ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( value1 ); | expected.setSomeProp( value1 ); | ||||
expected.addProp( value2 ); | expected.addProp( value2 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -99,18 +93,15 @@ public class DefaultConfigurerTest | |||||
config.setAttribute( "integer-prop", "-401" ); | config.setAttribute( "integer-prop", "-401" ); | ||||
// Register the converter | // 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 | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest10 expected = new ConfigTest10(); | |||||
final ConfigTestPrimConvert expected = new ConfigTestPrimConvert(); | |||||
expected.setIntProp( 90 ); | expected.setIntProp( 90 ); | ||||
expected.setIntegerProp( new Integer(-401) ); | expected.setIntegerProp( new Integer(-401) ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -126,12 +117,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "unknown", "some value" ); | config.setAttribute( "unknown", "some value" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -158,17 +149,17 @@ public class DefaultConfigurerTest | |||||
child2.setAttribute( "some-prop", value2 ); | child2.setAttribute( "some-prop", value2 ); | ||||
config.addChild( child2 ); | config.addChild( child2 ); | ||||
final ConfigTest2 test = new ConfigTest2(); | |||||
final ConfigTestObjectProps test = new ConfigTestObjectProps(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest2 expected = new ConfigTest2(); | |||||
ConfigTest1 elem = new ConfigTest1(); | |||||
final ConfigTestObjectProps expected = new ConfigTestObjectProps(); | |||||
ConfigTestStringProps elem = new ConfigTestStringProps(); | |||||
elem.setSomeProp( value1 ); | elem.setSomeProp( value1 ); | ||||
expected.setProp( elem ); | expected.setProp( elem ); | ||||
elem = new ConfigTest1(); | |||||
elem = new ConfigTestStringProps(); | |||||
elem.setSomeProp( value2 ); | elem.setSomeProp( value2 ); | ||||
expected.addAnotherProp( elem ); | expected.addAnotherProp( elem ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -185,12 +176,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" ); | final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -211,13 +202,13 @@ public class DefaultConfigurerTest | |||||
final String value1 = "some value"; | final String value1 = "some value"; | ||||
config.setValue( value1 ); | config.setValue( value1 ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.addContent( value1 ); | expected.addContent( value1 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -232,12 +223,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setValue( "some value" ); | config.setValue( "some value" ); | ||||
final ConfigTest2 test = new ConfigTest2(); | |||||
final ConfigTestObjectProps test = new ConfigTestObjectProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -257,15 +248,15 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "prop", "some ${prop-a} value" ); | config.setAttribute( "prop", "some ${prop-a} value" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
m_context.setProperty( "prop-a", "other" ); | m_context.setProperty( "prop-a", "other" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.addProp( "some other value" ); | expected.addProp( "some other value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -279,15 +270,15 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "prop-a" ); | config.setAttribute( "some-prop-ref", "prop-a" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( "some value" ); | expected.setSomeProp( "some value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -303,15 +294,15 @@ public class DefaultConfigurerTest | |||||
elem.setAttribute( "id", "prop-a" ); | elem.setAttribute( "id", "prop-a" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( "some value" ); | expected.setSomeProp( "some value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -329,12 +320,12 @@ public class DefaultConfigurerTest | |||||
elem.setAttribute( "extra-attr", "some value" ); | elem.setAttribute( "extra-attr", "some value" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -347,6 +338,57 @@ public class DefaultConfigurerTest | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 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 | * Tests whether an object with a non-iterface typed adder causes an | ||||
* exception. | * exception. | ||||
@@ -362,7 +404,7 @@ public class DefaultConfigurerTest | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -386,12 +428,12 @@ public class DefaultConfigurerTest | |||||
// Setup test data | // Setup test data | ||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
final ConfigTest5 test = new ConfigTest5(); | |||||
final ConfigTestMultiTypedAdder test = new ConfigTestMultiTypedAdder(); | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -399,7 +441,7 @@ public class DefaultConfigurerTest | |||||
final String[] messages = { | final String[] messages = { | ||||
REZ.getString( "bad-configure-element.error", "test" ), | REZ.getString( "bad-configure-element.error", "test" ), | ||||
REZ.getString( "multiple-adder-methods-for-element.error", | REZ.getString( "multiple-adder-methods-for-element.error", | ||||
ConfigTest5.class.getName(), | |||||
ConfigTestMultiTypedAdder.class.getName(), | |||||
"") | "") | ||||
}; | }; | ||||
assertSameMessage( messages, ce ); | assertSameMessage( messages, ce ); | ||||
@@ -419,24 +461,75 @@ public class DefaultConfigurerTest | |||||
config.addChild( child1 ); | config.addChild( child1 ); | ||||
config.addChild( child2 ); | 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 | // 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 MyType1() ); | ||||
expected.add( new MyType2() ); | expected.add( new MyType2() ); | ||||
assertEquals( expected, test ); | 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. | * Tests to see if typed adder can be used via an attribute. | ||||
*/ | */ | ||||
@@ -448,19 +541,17 @@ public class DefaultConfigurerTest | |||||
config.setAttribute( "my-role1", "some value" ); | config.setAttribute( "my-role1", "some value" ); | ||||
// Set up the converter and role | // 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 | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // 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 ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -477,12 +568,12 @@ public class DefaultConfigurerTest | |||||
config.addChild( child1 ); | config.addChild( child1 ); | ||||
config.addChild( child2 ); | config.addChild( child2 ); | ||||
final ConfigTest7 test = new ConfigTest7(); | |||||
final ConfigTestTypedConfigProp test = new ConfigTestTypedConfigProp(); | |||||
// Configure the object | // 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( child1 ); | ||||
expected.add( child2 ); | expected.add( child2 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -501,12 +592,12 @@ public class DefaultConfigurerTest | |||||
config.addChild( child1 ); | config.addChild( child1 ); | ||||
config.addChild( child2 ); | config.addChild( child2 ); | ||||
final ConfigTest8 test = new ConfigTest8(); | |||||
final ConfigTestConfigProps test = new ConfigTestConfigProps(); | |||||
// Configure the object | // 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( child1 ); | ||||
expected.addConfig( child2 ); | expected.addConfig( child2 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -521,12 +612,12 @@ public class DefaultConfigurerTest | |||||
// Setup test data | // Setup test data | ||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
final ConfigTest9 test = new ConfigTest9(); | |||||
final ConfigTestConfigurable test = new ConfigTestConfigurable(); | |||||
// Configure the object | // 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 ); | expected.configure( config ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -541,22 +632,22 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "${id}" ); | 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( "id", "prop-a" ); | ||||
m_context.setProperty( "prop-a", "some indirect value" ); | m_context.setProperty( "prop-a", "some indirect value" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( "some indirect value" ); | expected.setSomeProp( "some indirect value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
/** | /** | ||||
* Test an unknown reference. | |||||
* Tests an unknown reference. | |||||
*/ | */ | ||||
public void testUnknownReference() | public void testUnknownReference() | ||||
throws Exception | throws Exception | ||||
@@ -565,12 +656,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "unknown-prop" ); | config.setAttribute( "some-prop-ref", "unknown-prop" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -593,14 +684,14 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "prop-a" ); | 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 | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -609,8 +700,7 @@ public class DefaultConfigurerTest | |||||
REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ), | REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ), | ||||
REZ.getString( "mismatch-ref-types.error", | REZ.getString( "mismatch-ref-types.error", | ||||
"prop-a", | "prop-a", | ||||
String.class.getName(), | |||||
ConfigTest2.class.getName() ) | |||||
"some-prop" ) | |||||
}; | }; | ||||
assertSameMessage( messages, e ); | assertSameMessage( messages, e ); | ||||
} | } | ||||
@@ -631,19 +721,17 @@ public class DefaultConfigurerTest | |||||
config.addChild( child ); | config.addChild( child ); | ||||
// Add role mapping, and add to reference to context | // 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( "id", new MyType1() ); | ||||
m_context.setProperty( "id2", new MyType2() ); | m_context.setProperty( "id2", new MyType2() ); | ||||
final ConfigTest6 test = new ConfigTest6(); | |||||
final ConfigTestTypedProp test = new ConfigTestTypedProp(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Compare against expected value | // Compare against expected value | ||||
final ConfigTest6 expected = new ConfigTest6(); | |||||
final ConfigTestTypedProp expected = new ConfigTestTypedProp(); | |||||
expected.add( new MyType1() ); | expected.add( new MyType1() ); | ||||
expected.add( new MyType2() ); | expected.add( new MyType2() ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -660,12 +748,12 @@ public class DefaultConfigurerTest | |||||
elem.setAttribute( "not-a-prop", "not-a-value" ); | elem.setAttribute( "not-a-prop", "not-a-value" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest2 test = new ConfigTest2(); | |||||
final ConfigTestObjectProps test = new ConfigTestObjectProps(); | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -693,16 +781,16 @@ public class DefaultConfigurerTest | |||||
elem = new DefaultConfiguration( "prop3", "test" ); | elem = new DefaultConfiguration( "prop3", "test" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest3 test = new ConfigTest3(); | |||||
final ConfigTestMultiSetter test = new ConfigTestMultiSetter(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Test expected value | // 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 ); | assertEquals( expected, test ); | ||||
} | } | ||||
} | } |
@@ -0,0 +1,33 @@ | |||||
/* | |||||
* 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:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
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 ); | |||||
} | |||||
} |
@@ -9,24 +9,24 @@ package org.apache.myrmidon.components.configurer; | |||||
import org.apache.aut.converter.AbstractConverter; | import org.apache.aut.converter.AbstractConverter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.avalon.framework.context.Context; | |||||
/** | /** | ||||
* Converts from a string to a {@link MyRole1} implementation. | |||||
* Converts from Object to MyRole1. | |||||
* | * | ||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
* @version $Revision$ $Date$ | |||||
*/ | */ | ||||
public class StringToMyRole1Converter | |||||
public class ObjectToMyRole1Converter | |||||
extends AbstractConverter | extends AbstractConverter | ||||
{ | { | ||||
public StringToMyRole1Converter() | |||||
public ObjectToMyRole1Converter() | |||||
{ | { | ||||
super( String.class, MyRole1.class ); | |||||
super( Object.class, MyRole1.class ); | |||||
} | } | ||||
protected Object convert( Object original, Object context ) | protected Object convert( Object original, Object context ) | ||||
throws ConverterException | throws ConverterException | ||||
{ | { | ||||
return new MyType1(); | |||||
return new MyRole1Adaptor( original ); | |||||
} | } | ||||
} | } |
@@ -7,21 +7,19 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.deployer; | 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.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.framework.DataType; | 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.ConverterDefinition; | ||||
import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | ||||
import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | 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.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.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. | * Test cases for the default deployer. | ||||
@@ -37,7 +35,7 @@ public class DefaultDeployerTest | |||||
private Deployer m_deployer; | private Deployer m_deployer; | ||||
private RoleManager m_roleManager; | private RoleManager m_roleManager; | ||||
private MasterConverter m_converter; | |||||
private Converter m_converter; | |||||
public DefaultDeployerTest( final String name ) | public DefaultDeployerTest( final String name ) | ||||
{ | { | ||||
@@ -52,7 +50,7 @@ public class DefaultDeployerTest | |||||
{ | { | ||||
super.setUp(); | super.setUp(); | ||||
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE ); | 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 | // Add some core roles | ||||
m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
@@ -9,7 +9,6 @@ package org.apache.myrmidon.components.deployer; | |||||
import org.apache.aut.converter.Converter; | import org.apache.aut.converter.Converter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.avalon.framework.context.Context; | |||||
/** | /** | ||||
* A test converter. | * A test converter. | ||||
@@ -50,6 +50,9 @@ public class AbstractProjectTest | |||||
{ | { | ||||
if( m_embeddor == null ) | if( m_embeddor == null ) | ||||
{ | { | ||||
// Need to set the context classloader - The default embeddor uses it | |||||
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() ); | |||||
final Logger logger = createLogger(); | final Logger logger = createLogger(); | ||||
m_embeddor = new DefaultEmbeddor(); | m_embeddor = new DefaultEmbeddor(); | ||||
m_embeddor.enableLogging( logger ); | m_embeddor.enableLogging( logger ); | ||||
@@ -29,9 +29,9 @@ import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
import org.apache.myrmidon.components.type.DefaultTypeManager; | import org.apache.myrmidon.components.type.DefaultTypeManager; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | 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.Deployer; | ||||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | 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.role.RoleManager; | ||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
@@ -83,7 +83,7 @@ public abstract class AbstractComponentTest | |||||
List components = new ArrayList(); | List components = new ArrayList(); | ||||
Object component = new DefaultMasterConverter(); | Object component = new DefaultMasterConverter(); | ||||
m_serviceManager.put( MasterConverter.ROLE, component ); | |||||
m_serviceManager.put( Converter.ROLE, component ); | |||||
components.add( component ); | components.add( component ); | ||||
component = new DefaultConverterRegistry(); | component = new DefaultConverterRegistry(); | ||||
@@ -138,6 +138,29 @@ public abstract class AbstractComponentTest | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 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. | * Utility method to register a Converter. | ||||
@@ -7,8 +7,7 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
/** | /** | ||||
* Simple class to test typed adder. | * Simple class to test typed adder. | ||||
@@ -8,7 +8,6 @@ | |||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
/** | /** | ||||
@@ -17,7 +16,7 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest8 | |||||
public class ConfigTestConfigProps | |||||
{ | { | ||||
private ArrayList m_configurations = new ArrayList(); | private ArrayList m_configurations = new ArrayList(); | ||||
@@ -28,7 +27,7 @@ public class ConfigTest8 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest8 other = (ConfigTest8)object; | |||||
final ConfigTestConfigProps other = (ConfigTestConfigProps)object; | |||||
return m_configurations.equals( other.m_configurations ); | return m_configurations.equals( other.m_configurations ); | ||||
} | } | ||||
} | } |
@@ -7,19 +7,17 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.configuration.Configurable; | 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.configuration.ConfigurationException; | ||||
/** | /** | ||||
* Simple class to test adder for Configurations. | |||||
* Simple class to test {@link Configurable}. | |||||
* | * | ||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest9 | |||||
public class ConfigTestConfigurable | |||||
implements Configurable | implements Configurable | ||||
{ | { | ||||
private Configuration m_configuration; | private Configuration m_configuration; | ||||
@@ -32,7 +30,7 @@ public class ConfigTest9 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest9 other = (ConfigTest9)object; | |||||
final ConfigTestConfigurable other = (ConfigTestConfigurable)object; | |||||
return m_configuration == other.m_configuration; | return m_configuration == other.m_configuration; | ||||
} | } | ||||
} | } |
@@ -0,0 +1,32 @@ | |||||
/* | |||||
* 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:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
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 ); | |||||
} | |||||
} |
@@ -15,15 +15,15 @@ import junit.framework.AssertionFailedError; | |||||
* | * | ||||
* @author Adam Murdoch | * @author Adam Murdoch | ||||
*/ | */ | ||||
public class ConfigTest3 | |||||
public class ConfigTestMultiSetter | |||||
{ | { | ||||
private ConfigTest1 m_prop1; | |||||
private ConfigTest1 m_prop2; | |||||
private ConfigTestStringProps m_prop1; | |||||
private ConfigTestStringProps m_prop2; | |||||
private ArrayList m_prop3 = new ArrayList(); | private ArrayList m_prop3 = new ArrayList(); | ||||
public boolean equals( Object obj ) | public boolean equals( Object obj ) | ||||
{ | { | ||||
ConfigTest3 test = (ConfigTest3)obj; | |||||
ConfigTestMultiSetter test = (ConfigTestMultiSetter)obj; | |||||
if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) ) | if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) ) | ||||
{ | { | ||||
return false; | return false; | ||||
@@ -48,7 +48,7 @@ public class ConfigTest3 | |||||
throw new AssertionFailedError(); | throw new AssertionFailedError(); | ||||
} | } | ||||
public void setProp1( final ConfigTest1 value ) | |||||
public void setProp1( final ConfigTestStringProps value ) | |||||
{ | { | ||||
m_prop1 = value; | m_prop1 = value; | ||||
} | } | ||||
@@ -62,7 +62,7 @@ public class ConfigTest3 | |||||
throw new AssertionFailedError(); | throw new AssertionFailedError(); | ||||
} | } | ||||
public void setProp2( final ConfigTest1 value ) | |||||
public void setProp2( final ConfigTestStringProps value ) | |||||
{ | { | ||||
m_prop2 = value; | m_prop2 = value; | ||||
} | } | ||||
@@ -76,7 +76,7 @@ public class ConfigTest3 | |||||
throw new AssertionFailedError(); | throw new AssertionFailedError(); | ||||
} | } | ||||
public void addProp3( final ConfigTest1 value ) | |||||
public void addProp3( final ConfigTestStringProps value ) | |||||
{ | { | ||||
m_prop3.add( value ); | m_prop3.add( value ); | ||||
} | } |
@@ -7,17 +7,15 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
/** | /** | ||||
* Simple class to test typed adder. | |||||
* Simple class with more than one typed adder method. | |||||
* | * | ||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest5 | |||||
public class ConfigTestMultiTypedAdder | |||||
{ | { | ||||
public void add( final MyRole1 role1 ) | public void add( final MyRole1 role1 ) | ||||
{ | { |
@@ -15,14 +15,14 @@ import java.util.List; | |||||
* | * | ||||
* @author Adam Murdoch | * @author Adam Murdoch | ||||
*/ | */ | ||||
public class ConfigTest2 | |||||
public class ConfigTestObjectProps | |||||
{ | { | ||||
ConfigTest1 m_prop; | |||||
ConfigTestStringProps m_prop; | |||||
List m_propList = new ArrayList(); | List m_propList = new ArrayList(); | ||||
public boolean equals( Object obj ) | public boolean equals( Object obj ) | ||||
{ | { | ||||
ConfigTest2 test = (ConfigTest2)obj; | |||||
ConfigTestObjectProps test = (ConfigTestObjectProps)obj; | |||||
if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) ) | if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) ) | ||||
{ | { | ||||
return false; | return false; | ||||
@@ -34,12 +34,12 @@ public class ConfigTest2 | |||||
return true; | return true; | ||||
} | } | ||||
public void setProp( final ConfigTest1 test ) | |||||
public void setProp( final ConfigTestStringProps test ) | |||||
{ | { | ||||
m_prop = test; | m_prop = test; | ||||
} | } | ||||
public void addAnotherProp( final ConfigTest1 test ) | |||||
public void addAnotherProp( final ConfigTestStringProps test ) | |||||
{ | { | ||||
m_propList.add( test ); | m_propList.add( test ); | ||||
} | } |
@@ -14,24 +14,24 @@ import org.apache.myrmidon.components.AbstractComponentTest; | |||||
* | * | ||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
*/ | */ | ||||
public class ConfigTest10 | |||||
public class ConfigTestPrimConvert | |||||
{ | { | ||||
private int m_intProp; | private int m_intProp; | ||||
private Integer m_integerProp; | private Integer m_integerProp; | ||||
public void setIntProp( int intProp ) | |||||
public void setIntProp( final int intProp ) | |||||
{ | { | ||||
m_intProp = intProp; | m_intProp = intProp; | ||||
} | } | ||||
public void setIntegerProp( Integer integerProp ) | |||||
public void setIntegerProp( final Integer integerProp ) | |||||
{ | { | ||||
m_integerProp = integerProp; | m_integerProp = integerProp; | ||||
} | } | ||||
public boolean equals( Object obj ) | public boolean equals( Object obj ) | ||||
{ | { | ||||
ConfigTest10 test = (ConfigTest10)obj; | |||||
ConfigTestPrimConvert test = (ConfigTestPrimConvert)obj; | |||||
if( m_intProp != test.m_intProp ) | if( m_intProp != test.m_intProp ) | ||||
{ | { | ||||
return false; | return false; |
@@ -9,13 +9,15 @@ package org.apache.myrmidon.components.configurer; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | /** | ||||
* A simple test class. | |||||
* A simple test class with string properties. | |||||
* | * | ||||
* @author Adam Murdoch | * @author Adam Murdoch | ||||
*/ | */ | ||||
public class ConfigTest1 | |||||
public class ConfigTestStringProps | |||||
implements DataType | |||||
{ | { | ||||
private String m_someProp; | private String m_someProp; | ||||
private List m_propList = new ArrayList(); | private List m_propList = new ArrayList(); | ||||
@@ -23,7 +25,7 @@ public class ConfigTest1 | |||||
public boolean equals( final Object obj ) | public boolean equals( final Object obj ) | ||||
{ | { | ||||
final ConfigTest1 test = (ConfigTest1)obj; | |||||
final ConfigTestStringProps test = (ConfigTestStringProps)obj; | |||||
if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) ) | if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) ) | ||||
{ | { | ||||
return false; | return false; |
@@ -8,7 +8,6 @@ | |||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
/** | /** | ||||
@@ -17,7 +16,7 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest7 | |||||
public class ConfigTestTypedConfigProp | |||||
{ | { | ||||
private ArrayList m_configurations = new ArrayList(); | private ArrayList m_configurations = new ArrayList(); | ||||
@@ -28,7 +27,7 @@ public class ConfigTest7 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest7 other = (ConfigTest7)object; | |||||
final ConfigTestTypedConfigProp other = (ConfigTestTypedConfigProp)object; | |||||
return m_configurations.equals( other.m_configurations ); | return m_configurations.equals( other.m_configurations ); | ||||
} | } | ||||
} | } |
@@ -8,8 +8,6 @@ | |||||
package org.apache.myrmidon.components.configurer; | package org.apache.myrmidon.components.configurer; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
/** | /** | ||||
* Simple class to test typed adder. | * Simple class to test typed adder. | ||||
@@ -17,7 +15,7 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
public class ConfigTest6 | |||||
public class ConfigTestTypedProp | |||||
{ | { | ||||
private ArrayList m_roles = new ArrayList(); | private ArrayList m_roles = new ArrayList(); | ||||
@@ -28,7 +26,7 @@ public class ConfigTest6 | |||||
public boolean equals( final Object object ) | public boolean equals( final Object object ) | ||||
{ | { | ||||
final ConfigTest6 other = (ConfigTest6)object; | |||||
final ConfigTestTypedProp other = (ConfigTestTypedProp)object; | |||||
return m_roles.equals( other.m_roles ); | return m_roles.equals( other.m_roles ); | ||||
} | } | ||||
} | } |
@@ -13,16 +13,12 @@ import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.components.AbstractComponentTest; | import org.apache.myrmidon.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.components.workspace.DefaultTaskContext; | import org.apache.myrmidon.components.workspace.DefaultTaskContext; | ||||
import org.apache.myrmidon.framework.DataType; | import org.apache.myrmidon.framework.DataType; | ||||
import org.apache.myrmidon.interfaces.configurer.Configurer; | 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.RoleInfo; | ||||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||||
/** | /** | ||||
* Test cases for the default configurer and related classes. | * Test cases for the default configurer and related classes. | ||||
@@ -37,7 +33,6 @@ public class DefaultConfigurerTest | |||||
private Configurer m_configurer; | private Configurer m_configurer; | ||||
private DefaultTaskContext m_context; | private DefaultTaskContext m_context; | ||||
private Context m_adaptor; | |||||
public DefaultConfigurerTest( String name ) | public DefaultConfigurerTest( String name ) | ||||
{ | { | ||||
@@ -59,7 +54,6 @@ public class DefaultConfigurerTest | |||||
m_context = new DefaultTaskContext(); | m_context = new DefaultTaskContext(); | ||||
final File baseDir = new File( "." ).getAbsoluteFile(); | final File baseDir = new File( "." ).getAbsoluteFile(); | ||||
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | ||||
m_adaptor = new TaskContextAdapter( m_context ); | |||||
} | } | ||||
/** | /** | ||||
@@ -75,13 +69,13 @@ public class DefaultConfigurerTest | |||||
final String value2 = "some other value"; | final String value2 = "some other value"; | ||||
config.setAttribute( "prop", value2 ); | config.setAttribute( "prop", value2 ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( value1 ); | expected.setSomeProp( value1 ); | ||||
expected.addProp( value2 ); | expected.addProp( value2 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -99,18 +93,15 @@ public class DefaultConfigurerTest | |||||
config.setAttribute( "integer-prop", "-401" ); | config.setAttribute( "integer-prop", "-401" ); | ||||
// Register the converter | // 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 | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest10 expected = new ConfigTest10(); | |||||
final ConfigTestPrimConvert expected = new ConfigTestPrimConvert(); | |||||
expected.setIntProp( 90 ); | expected.setIntProp( 90 ); | ||||
expected.setIntegerProp( new Integer(-401) ); | expected.setIntegerProp( new Integer(-401) ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -126,12 +117,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "unknown", "some value" ); | config.setAttribute( "unknown", "some value" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -158,17 +149,17 @@ public class DefaultConfigurerTest | |||||
child2.setAttribute( "some-prop", value2 ); | child2.setAttribute( "some-prop", value2 ); | ||||
config.addChild( child2 ); | config.addChild( child2 ); | ||||
final ConfigTest2 test = new ConfigTest2(); | |||||
final ConfigTestObjectProps test = new ConfigTestObjectProps(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest2 expected = new ConfigTest2(); | |||||
ConfigTest1 elem = new ConfigTest1(); | |||||
final ConfigTestObjectProps expected = new ConfigTestObjectProps(); | |||||
ConfigTestStringProps elem = new ConfigTestStringProps(); | |||||
elem.setSomeProp( value1 ); | elem.setSomeProp( value1 ); | ||||
expected.setProp( elem ); | expected.setProp( elem ); | ||||
elem = new ConfigTest1(); | |||||
elem = new ConfigTestStringProps(); | |||||
elem.setSomeProp( value2 ); | elem.setSomeProp( value2 ); | ||||
expected.addAnotherProp( elem ); | expected.addAnotherProp( elem ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -185,12 +176,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" ); | final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -211,13 +202,13 @@ public class DefaultConfigurerTest | |||||
final String value1 = "some value"; | final String value1 = "some value"; | ||||
config.setValue( value1 ); | config.setValue( value1 ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // Check result | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.addContent( value1 ); | expected.addContent( value1 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -232,12 +223,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setValue( "some value" ); | config.setValue( "some value" ); | ||||
final ConfigTest2 test = new ConfigTest2(); | |||||
final ConfigTestObjectProps test = new ConfigTestObjectProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -257,15 +248,15 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "prop", "some ${prop-a} value" ); | config.setAttribute( "prop", "some ${prop-a} value" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
m_context.setProperty( "prop-a", "other" ); | m_context.setProperty( "prop-a", "other" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.addProp( "some other value" ); | expected.addProp( "some other value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -279,15 +270,15 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "prop-a" ); | config.setAttribute( "some-prop-ref", "prop-a" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( "some value" ); | expected.setSomeProp( "some value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -303,15 +294,15 @@ public class DefaultConfigurerTest | |||||
elem.setAttribute( "id", "prop-a" ); | elem.setAttribute( "id", "prop-a" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
m_context.setProperty( "prop-a", "some value" ); | m_context.setProperty( "prop-a", "some value" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( "some value" ); | expected.setSomeProp( "some value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -329,12 +320,12 @@ public class DefaultConfigurerTest | |||||
elem.setAttribute( "extra-attr", "some value" ); | elem.setAttribute( "extra-attr", "some value" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -347,6 +338,57 @@ public class DefaultConfigurerTest | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 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 | * Tests whether an object with a non-iterface typed adder causes an | ||||
* exception. | * exception. | ||||
@@ -362,7 +404,7 @@ public class DefaultConfigurerTest | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -386,12 +428,12 @@ public class DefaultConfigurerTest | |||||
// Setup test data | // Setup test data | ||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
final ConfigTest5 test = new ConfigTest5(); | |||||
final ConfigTestMultiTypedAdder test = new ConfigTestMultiTypedAdder(); | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
@@ -399,7 +441,7 @@ public class DefaultConfigurerTest | |||||
final String[] messages = { | final String[] messages = { | ||||
REZ.getString( "bad-configure-element.error", "test" ), | REZ.getString( "bad-configure-element.error", "test" ), | ||||
REZ.getString( "multiple-adder-methods-for-element.error", | REZ.getString( "multiple-adder-methods-for-element.error", | ||||
ConfigTest5.class.getName(), | |||||
ConfigTestMultiTypedAdder.class.getName(), | |||||
"") | "") | ||||
}; | }; | ||||
assertSameMessage( messages, ce ); | assertSameMessage( messages, ce ); | ||||
@@ -419,24 +461,75 @@ public class DefaultConfigurerTest | |||||
config.addChild( child1 ); | config.addChild( child1 ); | ||||
config.addChild( child2 ); | 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 | // 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 MyType1() ); | ||||
expected.add( new MyType2() ); | expected.add( new MyType2() ); | ||||
assertEquals( expected, test ); | 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. | * Tests to see if typed adder can be used via an attribute. | ||||
*/ | */ | ||||
@@ -448,19 +541,17 @@ public class DefaultConfigurerTest | |||||
config.setAttribute( "my-role1", "some value" ); | config.setAttribute( "my-role1", "some value" ); | ||||
// Set up the converter and role | // 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 | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check result | // 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 ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -477,12 +568,12 @@ public class DefaultConfigurerTest | |||||
config.addChild( child1 ); | config.addChild( child1 ); | ||||
config.addChild( child2 ); | config.addChild( child2 ); | ||||
final ConfigTest7 test = new ConfigTest7(); | |||||
final ConfigTestTypedConfigProp test = new ConfigTestTypedConfigProp(); | |||||
// Configure the object | // 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( child1 ); | ||||
expected.add( child2 ); | expected.add( child2 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -501,12 +592,12 @@ public class DefaultConfigurerTest | |||||
config.addChild( child1 ); | config.addChild( child1 ); | ||||
config.addChild( child2 ); | config.addChild( child2 ); | ||||
final ConfigTest8 test = new ConfigTest8(); | |||||
final ConfigTestConfigProps test = new ConfigTestConfigProps(); | |||||
// Configure the object | // 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( child1 ); | ||||
expected.addConfig( child2 ); | expected.addConfig( child2 ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -521,12 +612,12 @@ public class DefaultConfigurerTest | |||||
// Setup test data | // Setup test data | ||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
final ConfigTest9 test = new ConfigTest9(); | |||||
final ConfigTestConfigurable test = new ConfigTestConfigurable(); | |||||
// Configure the object | // 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 ); | expected.configure( config ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
@@ -541,22 +632,22 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "${id}" ); | 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( "id", "prop-a" ); | ||||
m_context.setProperty( "prop-a", "some indirect value" ); | m_context.setProperty( "prop-a", "some indirect value" ); | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Check the configured object | // Check the configured object | ||||
final ConfigTest1 expected = new ConfigTest1(); | |||||
final ConfigTestStringProps expected = new ConfigTestStringProps(); | |||||
expected.setSomeProp( "some indirect value" ); | expected.setSomeProp( "some indirect value" ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
} | } | ||||
/** | /** | ||||
* Test an unknown reference. | |||||
* Tests an unknown reference. | |||||
*/ | */ | ||||
public void testUnknownReference() | public void testUnknownReference() | ||||
throws Exception | throws Exception | ||||
@@ -565,12 +656,12 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "unknown-prop" ); | config.setAttribute( "some-prop-ref", "unknown-prop" ); | ||||
final ConfigTest1 test = new ConfigTest1(); | |||||
final ConfigTestStringProps test = new ConfigTestStringProps(); | |||||
// Configure the object | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -593,14 +684,14 @@ public class DefaultConfigurerTest | |||||
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | final DefaultConfiguration config = new DefaultConfiguration( "test", "test" ); | ||||
config.setAttribute( "some-prop-ref", "prop-a" ); | 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 | // Configure the object | ||||
try | try | ||||
{ | { | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -609,8 +700,7 @@ public class DefaultConfigurerTest | |||||
REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ), | REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ), | ||||
REZ.getString( "mismatch-ref-types.error", | REZ.getString( "mismatch-ref-types.error", | ||||
"prop-a", | "prop-a", | ||||
String.class.getName(), | |||||
ConfigTest2.class.getName() ) | |||||
"some-prop" ) | |||||
}; | }; | ||||
assertSameMessage( messages, e ); | assertSameMessage( messages, e ); | ||||
} | } | ||||
@@ -631,19 +721,17 @@ public class DefaultConfigurerTest | |||||
config.addChild( child ); | config.addChild( child ); | ||||
// Add role mapping, and add to reference to context | // 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( "id", new MyType1() ); | ||||
m_context.setProperty( "id2", new MyType2() ); | m_context.setProperty( "id2", new MyType2() ); | ||||
final ConfigTest6 test = new ConfigTest6(); | |||||
final ConfigTestTypedProp test = new ConfigTestTypedProp(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Compare against expected value | // Compare against expected value | ||||
final ConfigTest6 expected = new ConfigTest6(); | |||||
final ConfigTestTypedProp expected = new ConfigTestTypedProp(); | |||||
expected.add( new MyType1() ); | expected.add( new MyType1() ); | ||||
expected.add( new MyType2() ); | expected.add( new MyType2() ); | ||||
assertEquals( expected, test ); | assertEquals( expected, test ); | ||||
@@ -660,12 +748,12 @@ public class DefaultConfigurerTest | |||||
elem.setAttribute( "not-a-prop", "not-a-value" ); | elem.setAttribute( "not-a-prop", "not-a-value" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest2 test = new ConfigTest2(); | |||||
final ConfigTestObjectProps test = new ConfigTestObjectProps(); | |||||
try | try | ||||
{ | { | ||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
fail(); | fail(); | ||||
} | } | ||||
catch( ConfigurationException e ) | catch( ConfigurationException e ) | ||||
@@ -693,16 +781,16 @@ public class DefaultConfigurerTest | |||||
elem = new DefaultConfiguration( "prop3", "test" ); | elem = new DefaultConfiguration( "prop3", "test" ); | ||||
config.addChild( elem ); | config.addChild( elem ); | ||||
final ConfigTest3 test = new ConfigTest3(); | |||||
final ConfigTestMultiSetter test = new ConfigTestMultiSetter(); | |||||
// Configure the object | // Configure the object | ||||
m_configurer.configure( test, config, m_adaptor ); | |||||
m_configurer.configure( test, config, m_context ); | |||||
// Test expected value | // 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 ); | assertEquals( expected, test ); | ||||
} | } | ||||
} | } |
@@ -0,0 +1,33 @@ | |||||
/* | |||||
* 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:adammurdoch@apache.org">Adam Murdoch</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
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 ); | |||||
} | |||||
} |
@@ -9,24 +9,24 @@ package org.apache.myrmidon.components.configurer; | |||||
import org.apache.aut.converter.AbstractConverter; | import org.apache.aut.converter.AbstractConverter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.avalon.framework.context.Context; | |||||
/** | /** | ||||
* Converts from a string to a {@link MyRole1} implementation. | |||||
* Converts from Object to MyRole1. | |||||
* | * | ||||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | ||||
* @version $Revision$ $Date$ | |||||
*/ | */ | ||||
public class StringToMyRole1Converter | |||||
public class ObjectToMyRole1Converter | |||||
extends AbstractConverter | extends AbstractConverter | ||||
{ | { | ||||
public StringToMyRole1Converter() | |||||
public ObjectToMyRole1Converter() | |||||
{ | { | ||||
super( String.class, MyRole1.class ); | |||||
super( Object.class, MyRole1.class ); | |||||
} | } | ||||
protected Object convert( Object original, Object context ) | protected Object convert( Object original, Object context ) | ||||
throws ConverterException | throws ConverterException | ||||
{ | { | ||||
return new MyType1(); | |||||
return new MyRole1Adaptor( original ); | |||||
} | } | ||||
} | } |
@@ -7,21 +7,19 @@ | |||||
*/ | */ | ||||
package org.apache.myrmidon.components.deployer; | 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.components.AbstractComponentTest; | ||||
import org.apache.myrmidon.framework.DataType; | 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.ConverterDefinition; | ||||
import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | ||||
import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | 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.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.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. | * Test cases for the default deployer. | ||||
@@ -37,7 +35,7 @@ public class DefaultDeployerTest | |||||
private Deployer m_deployer; | private Deployer m_deployer; | ||||
private RoleManager m_roleManager; | private RoleManager m_roleManager; | ||||
private MasterConverter m_converter; | |||||
private Converter m_converter; | |||||
public DefaultDeployerTest( final String name ) | public DefaultDeployerTest( final String name ) | ||||
{ | { | ||||
@@ -52,7 +50,7 @@ public class DefaultDeployerTest | |||||
{ | { | ||||
super.setUp(); | super.setUp(); | ||||
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE ); | 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 | // Add some core roles | ||||
m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | ||||
@@ -9,7 +9,6 @@ package org.apache.myrmidon.components.deployer; | |||||
import org.apache.aut.converter.Converter; | import org.apache.aut.converter.Converter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.avalon.framework.context.Context; | |||||
/** | /** | ||||
* A test converter. | * A test converter. | ||||
@@ -88,7 +88,7 @@ public class Script extends AbstractTask | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
addBeans( getContext().getPropertys() ); | |||||
addBeans( getContext().getProperties() ); | |||||
//In Ant2 there is no difference between properties and references | //In Ant2 there is no difference between properties and references | ||||
//addBeans( getProject().getReferences() ); | //addBeans( getProject().getReferences() ); | ||||
@@ -617,7 +617,7 @@ public class JUnitTask extends AbstractTask | |||||
// Create a temporary file to pass the Ant properties to the forked test | // Create a temporary file to pass the Ant properties to the forked test | ||||
File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" ); | File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" ); | ||||
cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() ); | cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() ); | ||||
Map p = getContext().getPropertys(); | |||||
Map p = getContext().getProperties(); | |||||
Properties props = new Properties(); | Properties props = new Properties(); | ||||
for( Iterator enum = p.keySet().iterator(); enum.hasNext(); ) | for( Iterator enum = p.keySet().iterator(); enum.hasNext(); ) | ||||
{ | { | ||||
@@ -663,7 +663,7 @@ public class JUnitTask extends AbstractTask | |||||
private int executeInVM( JUnitTest test ) | private int executeInVM( JUnitTest test ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
test.setProperties( getContext().getPropertys() ); | |||||
test.setProperties( getContext().getProperties() ); | |||||
if( dir != null ) | if( dir != null ) | ||||
{ | { | ||||
getLogger().warn( "dir attribute ignored if running in the same VM" ); | getLogger().warn( "dir attribute ignored if running in the same VM" ); | ||||
@@ -7,7 +7,6 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.types.converters; | 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.AbstractConverter; | ||||
import org.apache.aut.converter.ConverterException; | import org.apache.aut.converter.ConverterException; | ||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||