Browse Source

Replaced usage of Avalon Context with Myrmidon specific Context:

* Moved read-only property and resolve methods from TaskContext to new Context
  interface.  TaskContext now extends the new Context interface.

* Changed the Configurer methods to use the new Context.  Both implementations
  use the supplied Context to do property resolution.

* Renamed TaskContext.getPropertys() -> getProperties().

* Moved PropertyUtil from configurer to workspace package, as that is now
  the only place it is used.

* Changed PropertyUtil to work with the new Context.

RoleManager:

* A default implementation for a role can now be specified.  Currently
  can only do this programatically.

DefaultMasterConverter:

* Removed MasterConverter interface.  It is now identified by the Converter
  role.

* Now caches the converter instances.

* Changed the converter search algorithm to traverse the *source* class
  hierarchy, including all interfaces.  Chooses the most specialised
  conversion, and fails if there is more than one such choice.

DefaultConfigurer:

* Attempts to convert references, if the type does not match the expected type.

* Changed handling of nested elements, for named adders/setters:
  * If the method type can be mapped to a role, and that role has a default
    implementation, then use that default implementation.
  * Otherwise, if the method type is an interface, fail.
  * Otherwise, create an instance using no-args constructor.

* Changed handling of nested elements, for typed adders/setters:
  * If the method type can be mapped to a role, and the element name is
    a type of that role, then use that role to create the instance.
  * Otherwise, use the type factory for the generic data-type role.
  * Attempt to convert the instance if it is not of the expected type.

* Added a bunch of test cases for new functionality.

* Renamed all the ConfigTest classes to have descriptive names.

Misc:

* Renamed package framework.factorys -> framework.factories.

* Made tests work when fork = false.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271539 13f79535-47bb-0310-9956-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
ed3fafb887
69 changed files with 989 additions and 702 deletions
  1. +2
    -2
      proposal/myrmidon/build.xml
  2. +1
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java
  3. +47
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/api/Context.java
  4. +1
    -28
      proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java
  5. +10
    -11
      proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java
  6. +88
    -55
      proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java
  7. +0
    -37
      proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/PropertyException.java
  8. +4
    -7
      proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/Resources.properties
  9. +85
    -46
      proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java
  10. +4
    -6
      proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/Resources.properties
  11. +1
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  12. +2
    -2
      proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  13. +2
    -4
      proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java
  14. +5
    -5
      proposal/myrmidon/src/java/org/apache/myrmidon/components/type/MultiSourceTypeFactory.java
  15. +11
    -45
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
  16. +3
    -3
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  17. +24
    -30
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/PropertyUtil.java
  18. +5
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/Resources.properties
  19. +6
    -10
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java
  20. +1
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/ExecManagerFactory.java
  21. +0
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/Resources.properties
  22. +1
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/VfsManagerFactory.java
  23. +1
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/Configurer.java
  24. +0
    -50
      proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/TaskContextAdapter.java
  25. +0
    -22
      proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/converter/MasterConverter.java
  26. +27
    -10
      proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java
  27. +1
    -1
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
  28. +2
    -2
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  29. +0
    -1
      proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java
  30. +2
    -2
      proposal/myrmidon/src/manifest/core-services.xml
  31. +3
    -0
      proposal/myrmidon/src/test/org/apache/myrmidon/AbstractProjectTest.java
  32. +25
    -2
      proposal/myrmidon/src/test/org/apache/myrmidon/components/AbstractComponentTest.java
  33. +1
    -2
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest4.java
  34. +2
    -3
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestConfigProps.java
  35. +4
    -6
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestConfigurable.java
  36. +32
    -0
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestInterfaceProp.java
  37. +7
    -7
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestMultiSetter.java
  38. +3
    -5
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestMultiTypedAdder.java
  39. +5
    -5
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestObjectProps.java
  40. +4
    -4
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestPrimConvert.java
  41. +5
    -3
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestStringProps.java
  42. +2
    -3
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestTypedConfigProp.java
  43. +2
    -4
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestTypedProp.java
  44. +184
    -96
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java
  45. +33
    -0
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/MyRole1Adaptor.java
  46. +6
    -6
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ObjectToMyRole1Converter.java
  47. +7
    -9
      proposal/myrmidon/src/test/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java
  48. +0
    -1
      proposal/myrmidon/src/test/org/apache/myrmidon/components/deployer/TestConverter1.java
  49. +3
    -0
      proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractProjectTest.java
  50. +25
    -2
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
  51. +1
    -2
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest4.java
  52. +2
    -3
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestConfigProps.java
  53. +4
    -6
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestConfigurable.java
  54. +32
    -0
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestInterfaceProp.java
  55. +7
    -7
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestMultiSetter.java
  56. +3
    -5
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestMultiTypedAdder.java
  57. +5
    -5
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestObjectProps.java
  58. +4
    -4
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestPrimConvert.java
  59. +5
    -3
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestStringProps.java
  60. +2
    -3
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestTypedConfigProp.java
  61. +2
    -4
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestTypedProp.java
  62. +184
    -96
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java
  63. +33
    -0
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/MyRole1Adaptor.java
  64. +6
    -6
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ObjectToMyRole1Converter.java
  65. +7
    -9
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java
  66. +0
    -1
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/TestConverter1.java
  67. +1
    -1
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/Script.java
  68. +2
    -2
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  69. +0
    -1
      proposal/myrmidon/src/todo/org/apache/tools/ant/types/converters/StringToPathConverter.java

+ 2
- 2
proposal/myrmidon/build.xml View File

@@ -455,11 +455,11 @@ Legal:
</jar>

<junit printsummary="on"
fork="true">
fork="false">
<formatter type="brief" usefile="false"/>
<classpath>
<fileset dir="${test.working.dir}/dist/bin/lib" includes="**/*.jar"/>
<fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar, **/*.atl"/>
<fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar, **/*.atl" excludes="crimson.jar"/>
</classpath>
<classpath location="${test.classes}"/>



+ 1
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java View File

@@ -37,8 +37,7 @@ public abstract class AbstractTask
/**
* Execute task.
* This method is called to perform actual work associated with task.
* It is called after Task has been Configured and Initialized and before
* beig Disposed (If task implements appropriate interfaces).
* It is called after Task has been configured.
*
* @exception TaskException if an error occurs
*/


+ 47
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/api/Context.java View File

@@ -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();

}

+ 1
- 28
proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java View File

@@ -8,7 +8,6 @@
package org.apache.myrmidon.api;

import java.io.File;
import java.util.Map;
import org.apache.avalon.framework.Enum;

/**
@@ -21,6 +20,7 @@ import org.apache.avalon.framework.Enum;
* @version $Revision$ $Date$
*/
public interface TaskContext
extends Context
{
//these values are used when setting properties to indicate the scope at
//which properties are set
@@ -72,33 +72,6 @@ public interface TaskContext
File resolveFile( String filename )
throws TaskException;

/**
* Resolve a value according to the context.
* This involves evaluating the string and thus removing
* ${} sequences according to the rules specified at
* ............
*
* @param value the value to resolve
* @return the resolved value
*/
Object resolveValue( String value )
throws TaskException;

/**
* Retrieve property for name.
*
* @param name the name of property
* @return the value of property
*/
Object getProperty( String name );

/**
* Retrieve a copy of all the properties accessible via context.
*
* @return the map of all property names to values
*/
Map getPropertys();

/**
* Set property value in current context.
*


+ 10
- 11
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java View File

@@ -10,20 +10,21 @@ package org.apache.myrmidon.components.configurer;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.api.Context;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.MasterConverter;

/**
* Class used to configure tasks.
@@ -41,12 +42,12 @@ public class ClassicConfigurer
private static final boolean DEBUG = false;

///Converter to use for converting between values
private MasterConverter m_converter;
private Converter m_converter;

public void service( final ServiceManager serviceManager )
throws ServiceException
{
m_converter = (MasterConverter)serviceManager.lookup( MasterConverter.ROLE );
m_converter = (Converter)serviceManager.lookup( Converter.ROLE );
}

/**
@@ -216,16 +217,14 @@ public class ClassicConfigurer
{
try
{
final Object objectValue =
PropertyUtil.resolveProperty( value, context, false );

final Object objectValue = context.resolveValue( value );
setValue( object, objectValue, methods, context );
}
catch( final PropertyException pe )
catch( final TaskException te )
{
final String message =
REZ.getString( "bad-property-resolve.error", value );
throw new ConfigurationException( message, pe );
throw new ConfigurationException( message, te );
}
}



+ 88
- 55
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java View File

@@ -9,22 +9,21 @@ package org.apache.myrmidon.components.configurer;

import java.util.HashMap;
import java.util.Map;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Resolvable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.api.Context;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.TypeFactory;
@@ -44,7 +43,7 @@ public class DefaultConfigurer
ResourceManager.getPackageResources( DefaultConfigurer.class );

///Converter to use for converting between values
private MasterConverter m_converter;
private Converter m_converter;

//TypeManager to use to create types in typed adders
private TypeManager m_typeManager;
@@ -59,7 +58,7 @@ public class DefaultConfigurer
public void service( final ServiceManager serviceManager )
throws ServiceException
{
m_converter = (MasterConverter)serviceManager.lookup( MasterConverter.ROLE );
m_converter = (Converter)serviceManager.lookup( Converter.ROLE );
m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE );
m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE );
}
@@ -140,7 +139,7 @@ public class DefaultConfigurer
{
final String message =
REZ.getString( "no-such-attribute.error", elemName, name );
throw new ReportableConfigurationException( message, nspe );
throw new ReportableConfigurationException( message );
}
catch( final Exception ce )
{
@@ -187,7 +186,7 @@ public class DefaultConfigurer
{
final String message =
REZ.getString( "no-such-element.error", elemName, name );
throw new ReportableConfigurationException( message, nspe );
throw new ReportableConfigurationException( message );
}
catch( final ReportableConfigurationException ce )
{
@@ -349,26 +348,29 @@ public class DefaultConfigurer
= getConfigurerFromName( state.getConfigurer(), name, false );

// Resolve any props in the id
Object id = PropertyUtil.resolveProperty( unresolvedId, context, false );
String id = context.resolveValue( unresolvedId ).toString();

// Locate the referenced object
Object ref = null;
try
{
ref = context.get( id );
}
catch( final ContextException e )
Object ref = context.getProperty( id );
if( ref == null )
{
final String message = REZ.getString( "unknown-reference.error", id );
throw new ConfigurationException( message, e );
throw new ConfigurationException( message );
}

// Check the types
// Convert the object, if necessary
final Class type = childConfigurer.getType();
if( !type.isInstance( ref ) )
{
final String message = REZ.getString( "mismatch-ref-types.error", id, type.getName(), ref.getClass().getName() );
throw new ConfigurationException( message );
try
{
ref = m_converter.convert( type, ref, context );
}
catch( ConverterException e )
{
final String message = REZ.getString( "mismatch-ref-types.error", id, name );
throw new ConfigurationException( message, e );
}
}

// Set the child element
@@ -408,17 +410,14 @@ public class DefaultConfigurer
throws Exception
{
// Resolve property references in the attribute value
Object objValue = PropertyUtil.resolveProperty( value, context, false );
Object objValue = context.resolveValue( value );

// Convert the value to the appropriate type

Object converterContext = context;
if( context instanceof Resolvable )
final Class type = setter.getType();
if( ! type.isInstance( objValue ) )
{
converterContext = ( (Resolvable)context ).resolve( context );
objValue = m_converter.convert( type, objValue, context );
}
final Class clazz = setter.getType();
objValue = m_converter.convert( clazz, objValue, converterContext );

// Set the value
setter.addValue( state, objValue );
@@ -451,27 +450,38 @@ public class DefaultConfigurer
{
final String name = element.getName();
final Class type = childConfigurer.getType();
Object child = childConfigurer.createValue( state );

if( null == child && Configuration.class == type )
if( Configuration.class == type )
{
//special case where you have add...(Configuration)
return element;
}
else if( null == child )

// Create an instance
Object child = childConfigurer.createValue( state );
if( null == child )
{
// Create an instance
if( type.isInterface() )
if( childConfigurer == state.getConfigurer().getTypedProperty() )
{
child = createdTypedObject( name, type );
// Typed property
child = createTypedObject( name, type );
}
else
{
child = createObject( type );
// Named property
child = createNamedObject( type );
}
}

// Configure the object
configureObject( child, element, context );

// Convert the object, if necessary
if( ! type.isInstance( child ) )
{
child = m_converter.convert( type, child, context );
}

return child;
}

@@ -521,38 +531,61 @@ 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
{
// 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 );
}

/**


+ 0
- 37
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/PropertyException.java View File

@@ -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 );
}
}


+ 4
- 7
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/Resources.properties View File

@@ -1,6 +1,6 @@
create-object.error=Could not create an object of class {0}.
extra-config-for-ref.error=A reference element can only include an "id" attribute.
mismatch-ref-types.error=Mismatched type for reference "{0}". Was expecting an object of type {1}, instead found an object of type {2}.
mismatch-ref-types.error=Could not convert reference "{0}" to the type expected for property "{1}".
incompatible-element-types.error=Incompatible creator and adder/setter methods found in class {0} for property "{1}".
multiple-adder-methods-for-element.error=Multiple add{1}() or set{1}() methods found in class {0}.
multiple-creator-methods-for-element.error=Multiple {1}() methods found in class {0}.
@@ -9,16 +9,13 @@ 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.
too-many-values.error=Too many values for this property.
no-complex-type.error=Can not get complex type for non-primitive type {0}.
no-such-attribute.error=Attribute "{1}" is not allowed for element <{0}>.
no-such-attribute.error=Attribute "{1}" is not supported for element <{0}>.
bad-set-attribute.error=Could not set attribute "{1}" for element <{0}>.
bad-set-class-attribute.error=Could not set attribute "{0}" for object of class {1}.
no-such-element.error=Nested <{1}> elements are not allowed for element <{0}>.
no-content.error=Text content is not allowed in element <{0}>.
no-such-element.error=Nested <{1}> elements are not supported for element <{0}>.
no-content.error=Text content is not supported in element <{0}>.
bad-set-content.error=Could not set text content for element <{0}>.
typed-adder-non-interface.error=The typed adder for class "{0}" must have a single parameter that is an interface rather than {1} which defines a class.
create-typed-object.error=Could not create an object of type "{0}" of class {1}.
unknown-reference.error=Could not find referenced object "{0}".
bad-configure-element.error=Could not configure element <{0}>.

prop.mismatched-braces.error=Malformed property with mismatched }'s.
prop.missing-value.error=Unable to find "{0}" to expand during property resolution.

+ 85
- 46
proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java View File

@@ -7,6 +7,9 @@
*/
package org.apache.myrmidon.components.converter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
@@ -16,7 +19,6 @@ import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
@@ -29,16 +31,17 @@ import org.apache.myrmidon.interfaces.type.TypeManager;
*/
public class DefaultMasterConverter
extends AbstractLogEnabled
implements MasterConverter, Serviceable
implements Converter, Serviceable
{
private final static Resources REZ =
ResourceManager.getPackageResources( DefaultMasterConverter.class );

private final static boolean DEBUG = false;

private ConverterRegistry m_registry;
private TypeFactory m_factory;

/** Map from converter name to Converter. */
private Map m_converters = new HashMap();

/**
* Retrieve relevent services needed to deploy.
*
@@ -83,73 +86,109 @@ public class DefaultMasterConverter
return original;
}

if( DEBUG )
{
final String message =
REZ.getString( "converter-lookup.notice",
originalClass.getName(),
destination.getName() );
getLogger().debug( message );
}

//Searching inheritance hierarchy for converter
final String name = getConverterName( originalClass, destination );

try
{
//TODO: Start caching converters instead of repeatedly instantiating em.
final Converter converter = (Converter)m_factory.create( name );
// Search inheritance hierarchy for converter
final String name = getConverterName( originalClass, destination );

if( DEBUG )
// Create the converter
Converter converter = (Converter)m_converters.get( name );
if( converter == null )
{
final String message = REZ.getString( "found-converter.notice", converter );
getLogger().debug( message );
converter = (Converter)m_factory.create( name );
m_converters.put( name, converter );
}

// Convert
final Object object = converter.convert( destination, original, context );
if( destination.isInstance( object ) )
{
return object;
}
else
{
final String message =
REZ.getString( "bad-return-type.error",
name,
object,
destination.getName() );
throw new ConverterException( message );
}

final String message =
REZ.getString( "bad-return-type.error",
object.getClass().getName(),
destination.getName() );
throw new ConverterException( message );
}
catch( final TypeException te )
catch( final Exception e )
{
final String message = REZ.getString( "bad-typemanager.error" );
throw new ConverterException( message, te );
final String message = REZ.getString( "convert.error",
originalClass.getName(),
destination.getName() );
throw new ConverterException( message, e );
}
}

/**
* Determine the name of the converter to use to convert between
* original and destination classes.
*/
private String getConverterName( final Class originalClass,
final Class destination )
throws ConverterException
{
//TODO: Maybe we should search the source classes hierarchy aswell
for( Class clazz = destination;
clazz != null;
clazz = clazz.getSuperclass() )
//TODO: Maybe we should search the destination classes hierarchy as well

// Recursively iterate over the super-types of the original class,
// looking for a converter from source type -> destination type.
// If more than one is found, choose the most specialised.

Class match = null;
String converterName = null;
ArrayList queue = new ArrayList();
queue.add( originalClass );

while( ! queue.isEmpty() )
{
final String name =
m_registry.getConverterName( originalClass.getName(),
clazz.getName() );
if( name != null )
Class clazz = (Class)queue.remove( 0 );

// Add superclass and all interfaces
if( clazz.getSuperclass() != null )
{
queue.add( clazz.getSuperclass() );
}
final Class[] interfaces = clazz.getInterfaces();
for( int i = 0; i < interfaces.length; i++ )
{
queue.add( interfaces[i ] );
}

// Check if we can convert from current class to destination
final String name = m_registry.getConverterName( clazz.getName(),
destination.getName() );
if( name == null )
{
continue;
}

// Choose the more specialised source class
if( match == null || match.isAssignableFrom( clazz ) )
{
return name;
match = clazz;
converterName = name;
}
else if( clazz.isAssignableFrom( clazz ) )
{
continue;
}
else
{
// Duplicate
final String message = REZ.getString( "ambiguous-converter.error" );
throw new ConverterException( message );
}
}

// TODO - should cache the (src, dest) -> converter mapping
if( match != null )
{
return converterName;
}

final String message =
REZ.getString( "no-converter.error",
originalClass.getName(),
destination.getName() );
// Could not find a converter
final String message = REZ.getString( "no-converter.error" );
throw new ConverterException( message );
}
}

+ 4
- 6
proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/Resources.properties View File

@@ -1,7 +1,5 @@
converter-lookup.notice=Looking for converter from {0} to {1}.
found-converter.notice=Found Converter: {0}.

no-converter-factory.error=Unable to retrieve Converter factory from TypeManager.
no-converter.error=Unable to find converter for {0} to {1} conversion.
convert.error=Could not convert from {0} to {1}.
no-converter.error=Could not find an appropriate converter.
bad-typemanager.error=Badly configured TypeManager missing converter definition.
bad-return-type.error=The TypeManager for {0} returned "{1}" which is not of the expected type {2}.
bad-return-type.error=Converter {0} returned an object of type {1} which is assignable to the expected type {2}.
ambiguous-converter.error=More than one converter available for this conversion.

+ 1
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java View File

@@ -261,7 +261,7 @@ public class DefaultDeployer
final String name = roleDef.getShortHand();
final String role = roleDef.getRoleName();
final Class type = deployment.getClassLoader().loadClass( role );
final RoleInfo roleInfo = new RoleInfo( role, name, type );
final RoleInfo roleInfo = new RoleInfo( role, name, type, null );
m_roleManager.addRole( roleInfo );

if( getLogger().isDebugEnabled() )


+ 2
- 2
proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java View File

@@ -12,6 +12,7 @@ import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.aut.converter.Converter;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.ExtensionFileFilter;
@@ -29,7 +30,6 @@ import org.apache.myrmidon.interfaces.aspect.AspectManager;
import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.deployer.DeploymentException;
import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
@@ -246,7 +246,7 @@ public class DefaultEmbeddor
// Create the components
createComponent( ConverterRegistry.class, PREFIX + "converter.DefaultConverterRegistry" );
createComponent( ExtensionManager.class, PREFIX + "extensions.DefaultExtensionManager" );
createComponent( MasterConverter.class, PREFIX + "converter.DefaultMasterConverter" );
createComponent( Converter.class, PREFIX + "converter.DefaultMasterConverter" );
createComponent( Configurer.class, PREFIX + "configurer.DefaultConfigurer" );
createComponent( TypeManager.class, PREFIX + "type.DefaultTypeManager" );
createComponent( RoleManager.class, PREFIX + "role.DefaultRoleManager" );


+ 2
- 4
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java View File

@@ -13,9 +13,9 @@ import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.myrmidon.api.Task;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
@@ -24,7 +24,6 @@ import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
import org.apache.myrmidon.interfaces.executor.Executor;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;

/**
* The basic executor that just executes the tasks.
@@ -103,8 +102,7 @@ public class DefaultExecutor
{
try
{
final TaskContextAdapter context = new TaskContextAdapter( taskContext );
m_configurer.configure( task, taskModel, context );
m_configurer.configure( task, taskModel, taskContext );
}
catch( final Throwable throwable )
{


+ 5
- 5
proposal/myrmidon/src/java/org/apache/myrmidon/components/type/MultiSourceTypeFactory.java View File

@@ -14,7 +14,7 @@ import org.apache.myrmidon.interfaces.type.TypeException;
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>
* @version $Revision$ $Date$
@@ -29,9 +29,9 @@ public class MultiSourceTypeFactory
private final MultiSourceTypeFactory m_parent;

///Map of name->factory list
private final HashMap m_factorys = new HashMap();
private final HashMap m_factories = new HashMap();

///Type expected to be created from factorys
///Type expected to be created from factories
private final Class m_type;

public MultiSourceTypeFactory( final Class type )
@@ -51,7 +51,7 @@ public class MultiSourceTypeFactory
*/
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 )
{
return (TypeFactory)m_factorys.get( name );
return (TypeFactory)m_factories.get( name );
}
}

+ 11
- 45
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java View File

@@ -13,14 +13,10 @@ import java.util.Map;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.components.configurer.PropertyException;
import org.apache.myrmidon.components.configurer.PropertyUtil;
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;

/**
* Default implementation of TaskContext.
@@ -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 );
if( null != data )
@@ -96,10 +87,10 @@ public class DefaultTaskContext
if( null == m_parent )
{
// There was no parent, and no data
throw new ContextException( "Unable to locate " + key );
return null;
}

return m_parent.getProperty( key.toString() );
return m_parent.getProperty( key );
}

/**
@@ -109,15 +100,7 @@ public class DefaultTaskContext
*/
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()
{
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
{
final TaskContextAdapter context = new TaskContextAdapter( this );

final Object object =
PropertyUtil.resolveProperty( value, context, false );
PropertyUtil.resolveProperty( value, this, false );

if( null == object )
{
@@ -218,10 +191,10 @@ public class DefaultTaskContext

return object;
}
catch( final PropertyException pe )
catch( final TaskException te )
{
final String message = REZ.getString( "bad-resolve.error", value );
throw new TaskException( message, pe );
throw new TaskException( message, te );
}
}

@@ -233,14 +206,7 @@ public class DefaultTaskContext
*/
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
*/
public Map getPropertys()
public Map getProperties()
{
return null;
}


+ 3
- 3
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java View File

@@ -59,7 +59,7 @@ public class DefaultWorkspace
private ServiceManager m_serviceManager;
private Parameters m_parameters;
private TaskContext m_baseContext;
private HashMap m_entrys = new HashMap();
private HashMap m_entries = new HashMap();
private TypeManager m_typeManager;
private Deployer m_deployer;
private Hierarchy m_hierarchy;
@@ -279,7 +279,7 @@ public class DefaultWorkspace
private ProjectEntry getProjectEntry( final Project project )
throws TaskException
{
ProjectEntry entry = (ProjectEntry)m_entrys.get( project );
ProjectEntry entry = (ProjectEntry)m_entries.get( project );

if( null == entry )
{
@@ -287,7 +287,7 @@ public class DefaultWorkspace
{
final ExecutionFrame frame = createExecutionFrame( project );
entry = new ProjectEntry( project, frame );
m_entrys.put( project, entry );
m_entries.put( project, entry );
}
catch( Exception e )
{


proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/PropertyUtil.java → proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/PropertyUtil.java View File

@@ -5,15 +5,15 @@
* version 1.1, a copy of which has been included with this distribution in
* 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.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>
* @version $Revision$ $Date$
@@ -33,14 +33,14 @@ public final class PropertyUtil
*
* @param property the property to resolve
* @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
* @exception PropertyException if an error occurs
* @exception TaskException if an error occurs
*/
public static Object resolveProperty( final String property,
final Context context,
final boolean ignoreUndefined )
throws PropertyException
throws TaskException
{
int start = findBeginning( property, 0 );
if( -1 == start )
@@ -94,14 +94,14 @@ public final class PropertyUtil
*
* @param property the property to resolve
* @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
* @exception PropertyException if an error occurs
* @exception TaskException if an error occurs
*/
public static Object recursiveResolveProperty( final String property,
final Context context,
final boolean ignoreUndefined )
throws PropertyException
throws TaskException
{
int start = findBeginning( property, 0 );
if( -1 == start )
@@ -156,21 +156,21 @@ public final class PropertyUtil
}

private static int findEnding( final String property, final int currentPosition )
throws PropertyException
throws TaskException
{
//TODO: Check if it is commented out
final int index = property.indexOf( '}', currentPosition );
if( -1 == index )
{
final String message = REZ.getString( "prop.mismatched-braces.error" );
throw new PropertyException( message );
throw new TaskException( message );
}

return index;
}

private static int findNestedEnding( final String property, final int currentPosition )
throws PropertyException
throws TaskException
{
final int length = property.length();
final int start = currentPosition + 2;
@@ -204,42 +204,36 @@ public final class PropertyUtil
}

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.
* 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 context the Context
* @param ignoreUndefined true if undefined variables are ignored
* @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,
final Context context,
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 );
}
}


+ 5
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/Resources.properties View File

@@ -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.
bad-resolve.error=Unable to resolve value "{0}".
bad-find-service.error=Could not find service "{0}".
bad-service-class.error=Find service "{0}" but it was of type {1} where it was expected to be of type {2}.
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.

+ 6
- 10
proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java View File

@@ -7,6 +7,8 @@
*/
package org.apache.myrmidon.framework;

import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration;
@@ -14,15 +16,11 @@ import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.executor.Executor;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;

/**
* This is the class that Task writers should extend to provide custom tasks.
@@ -37,7 +35,7 @@ public abstract class AbstractContainerTask
ResourceManager.getPackageResources( AbstractContainerTask.class );

///For converting own attributes
private MasterConverter m_converter;
private Converter m_converter;

///For configuring own sub-elements
private Configurer m_configurer;
@@ -55,7 +53,7 @@ public abstract class AbstractContainerTask
{
super.contextualize( context );
m_configurer = (Configurer)getService( Configurer.class );
m_converter = (MasterConverter)getService( MasterConverter.class );
m_converter = (Converter)getService( Converter.class );
m_executor = (Executor)getService( Executor.class );
}

@@ -91,8 +89,7 @@ public abstract class AbstractContainerTask
protected final void configure( final Object object, final Configuration element )
throws ConfigurationException
{
final TaskContextAdapter context = new TaskContextAdapter( getContext() );
getConfigurer().configure( object, element, context );
getConfigurer().configure( object, element, getContext() );
}

/**
@@ -106,8 +103,7 @@ public abstract class AbstractContainerTask
protected final void configure( final Object object, final String name, final String value )
throws ConfigurationException
{
final TaskContextAdapter context = new TaskContextAdapter( getContext() );
getConfigurer().configure( object, name, value, context );
getConfigurer().configure( object, name, value, getContext() );
}

/**


proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/ExecManagerFactory.java → proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/ExecManagerFactory.java View File

@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.framework.factorys;
package org.apache.myrmidon.framework.factories;

import java.io.File;
import org.apache.aut.nativelib.ExecException;

proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/Resources.properties → proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/Resources.properties View File


proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/VfsManagerFactory.java → proposal/myrmidon/src/java/org/apache/myrmidon/framework/factories/VfsManagerFactory.java View File

@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* 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.impl.DefaultFileSystemManager;

+ 1
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/Configurer.java View File

@@ -9,7 +9,7 @@ package org.apache.myrmidon.interfaces.configurer;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.context.Context;
import org.apache.myrmidon.api.Context;

/**
* Class used to configure tasks.


+ 0
- 50
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/TaskContextAdapter.java View File

@@ -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 );
}
}
}

+ 0
- 22
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/converter/MasterConverter.java View File

@@ -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();
}

+ 27
- 10
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java View File

@@ -20,6 +20,7 @@ public final class RoleInfo
private final String m_name;
private final String m_shorthand;
private final Class m_type;
private final String m_defaultType;

/**
* Creates a role definition.
@@ -28,9 +29,7 @@ public final class RoleInfo
*/
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 )
{
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 )
{
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 )
{
m_name = type.getName();
this( type.getName(), shorthand, type, null );
}

/**
* Creates a role definition.
*/
public RoleInfo( final String name,
final String shorthand,
final Class type,
final String defaultType )
{
m_name = name;
m_shorthand = shorthand;
m_type = type;
m_defaultType = defaultType;
}

/**
@@ -127,4 +134,14 @@ public final class RoleInfo
{
return m_type;
}

/**
* Returns the name of the default implementation of this role.
*
* @return The default type name, or null if this role has no default type.
*/
public String getDefaultType()
{
return m_defaultType;
}
}

+ 1
- 1
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Script.java View File

@@ -88,7 +88,7 @@ public class Script extends AbstractTask
{
try
{
addBeans( getContext().getPropertys() );
addBeans( getContext().getProperties() );
//In Ant2 there is no difference between properties and references
//addBeans( getProject().getReferences() );



+ 2
- 2
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -617,7 +617,7 @@ public class JUnitTask extends AbstractTask
// Create a temporary file to pass the Ant properties to the forked test
File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" );
cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() );
Map p = getContext().getPropertys();
Map p = getContext().getProperties();
Properties props = new Properties();
for( Iterator enum = p.keySet().iterator(); enum.hasNext(); )
{
@@ -663,7 +663,7 @@ public class JUnitTask extends AbstractTask
private int executeInVM( JUnitTest test )
throws TaskException
{
test.setProperties( getContext().getPropertys() );
test.setProperties( getContext().getProperties() );
if( dir != null )
{
getLogger().warn( "dir attribute ignored if running in the same VM" );


+ 0
- 1
proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java View File

@@ -7,7 +7,6 @@
*/
package org.apache.tools.ant.types.converters;

import org.apache.avalon.framework.context.Context;
import org.apache.aut.converter.AbstractConverter;
import org.apache.aut.converter.ConverterException;
import org.apache.tools.ant.types.Path;


+ 2
- 2
proposal/myrmidon/src/manifest/core-services.xml View File

@@ -1,6 +1,6 @@
<services version="1.0">
<exec-manager factory="org.apache.myrmidon.framework.factorys.ExecManagerFactory"/>
<file-system-manager factory="org.apache.myrmidon.framework.factorys.VfsManagerFactory">
<exec-manager factory="org.apache.myrmidon.framework.factories.ExecManagerFactory"/>
<file-system-manager factory="org.apache.myrmidon.framework.factories.VfsManagerFactory">
<provider scheme="zip" classname="org.apache.aut.vfs.provider.zip.ZipFileSystemProvider"/>
<provider scheme="jar" classname="org.apache.aut.vfs.provider.zip.ZipFileSystemProvider"/>
<provider scheme="smb" classname="org.apache.aut.vfs.provider.smb.SmbFileSystemProvider"/>


+ 3
- 0
proposal/myrmidon/src/test/org/apache/myrmidon/AbstractProjectTest.java View File

@@ -50,6 +50,9 @@ public class AbstractProjectTest
{
if( m_embeddor == null )
{
// Need to set the context classloader - The default embeddor uses it
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );

final Logger logger = createLogger();
m_embeddor = new DefaultEmbeddor();
m_embeddor.enableLogging( logger );


+ 25
- 2
proposal/myrmidon/src/test/org/apache/myrmidon/components/AbstractComponentTest.java View File

@@ -29,9 +29,9 @@ import org.apache.myrmidon.components.role.DefaultRoleManager;
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
import org.apache.myrmidon.interfaces.type.TypeException;
@@ -83,7 +83,7 @@ public abstract class AbstractComponentTest
List components = new ArrayList();

Object component = new DefaultMasterConverter();
m_serviceManager.put( MasterConverter.ROLE, component );
m_serviceManager.put( Converter.ROLE, component );
components.add( component );

component = new DefaultConverterRegistry();
@@ -138,6 +138,29 @@ 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.


+ 1
- 2
proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest4.java View File

@@ -7,8 +7,7 @@
*/
package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import junit.framework.AssertionFailedError;


/**
* Simple class to test typed adder.


proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest8.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestConfigProps.java View File

@@ -8,7 +8,6 @@
package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import junit.framework.AssertionFailedError;
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>
* @version $Revision$ $Date$
*/
public class ConfigTest8
public class ConfigTestConfigProps
{
private ArrayList m_configurations = new ArrayList();

@@ -28,7 +27,7 @@ public class ConfigTest8

public boolean equals( final Object object )
{
final ConfigTest8 other = (ConfigTest8)object;
final ConfigTestConfigProps other = (ConfigTestConfigProps)object;
return m_configurations.equals( other.m_configurations );
}
}

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest9.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestConfigurable.java View File

@@ -7,19 +7,17 @@
*/
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.Configuration;
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>
* @version $Revision$ $Date$
*/
public class ConfigTest9
public class ConfigTestConfigurable
implements Configurable
{
private Configuration m_configuration;
@@ -32,7 +30,7 @@ public class ConfigTest9

public boolean equals( final Object object )
{
final ConfigTest9 other = (ConfigTest9)object;
final ConfigTestConfigurable other = (ConfigTestConfigurable)object;
return m_configuration == other.m_configuration;
}
}

+ 32
- 0
proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestInterfaceProp.java View File

@@ -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 );
}
}

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest3.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestMultiSetter.java View File

@@ -15,15 +15,15 @@ import junit.framework.AssertionFailedError;
*
* @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();

public boolean equals( Object obj )
{
ConfigTest3 test = (ConfigTest3)obj;
ConfigTestMultiSetter test = (ConfigTestMultiSetter)obj;
if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) )
{
return false;
@@ -48,7 +48,7 @@ public class ConfigTest3
throw new AssertionFailedError();
}

public void setProp1( final ConfigTest1 value )
public void setProp1( final ConfigTestStringProps value )
{
m_prop1 = value;
}
@@ -62,7 +62,7 @@ public class ConfigTest3
throw new AssertionFailedError();
}

public void setProp2( final ConfigTest1 value )
public void setProp2( final ConfigTestStringProps value )
{
m_prop2 = value;
}
@@ -76,7 +76,7 @@ public class ConfigTest3
throw new AssertionFailedError();
}

public void addProp3( final ConfigTest1 value )
public void addProp3( final ConfigTestStringProps value )
{
m_prop3.add( value );
}

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest5.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestMultiTypedAdder.java View File

@@ -7,17 +7,15 @@
*/
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>
* @version $Revision$ $Date$
*/
public class ConfigTest5
public class ConfigTestMultiTypedAdder
{
public void add( final MyRole1 role1 )
{

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest2.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestObjectProps.java View File

@@ -15,14 +15,14 @@ import java.util.List;
*
* @author Adam Murdoch
*/
public class ConfigTest2
public class ConfigTestObjectProps
{
ConfigTest1 m_prop;
ConfigTestStringProps m_prop;
List m_propList = new ArrayList();

public boolean equals( Object obj )
{
ConfigTest2 test = (ConfigTest2)obj;
ConfigTestObjectProps test = (ConfigTestObjectProps)obj;
if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) )
{
return false;
@@ -34,12 +34,12 @@ public class ConfigTest2
return true;
}

public void setProp( final ConfigTest1 test )
public void setProp( final ConfigTestStringProps test )
{
m_prop = test;
}

public void addAnotherProp( final ConfigTest1 test )
public void addAnotherProp( final ConfigTestStringProps test )
{
m_propList.add( test );
}

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest10.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestPrimConvert.java View File

@@ -14,24 +14,24 @@ import org.apache.myrmidon.components.AbstractComponentTest;
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*/
public class ConfigTest10
public class ConfigTestPrimConvert
{
private int m_intProp;
private Integer m_integerProp;

public void setIntProp( int intProp )
public void setIntProp( final int intProp )
{
m_intProp = intProp;
}

public void setIntegerProp( Integer integerProp )
public void setIntegerProp( final Integer integerProp )
{
m_integerProp = integerProp;
}

public boolean equals( Object obj )
{
ConfigTest10 test = (ConfigTest10)obj;
ConfigTestPrimConvert test = (ConfigTestPrimConvert)obj;
if( m_intProp != test.m_intProp )
{
return false;

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest1.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestStringProps.java View File

@@ -9,13 +9,15 @@ package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import java.util.List;
import org.apache.myrmidon.framework.DataType;

/**
* A simple test class.
* A simple test class with string properties.
*
* @author Adam Murdoch
*/
public class ConfigTest1
public class ConfigTestStringProps
implements DataType
{
private String m_someProp;
private List m_propList = new ArrayList();
@@ -23,7 +25,7 @@ public class ConfigTest1

public boolean equals( final Object obj )
{
final ConfigTest1 test = (ConfigTest1)obj;
final ConfigTestStringProps test = (ConfigTestStringProps)obj;
if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) )
{
return false;

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest7.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestTypedConfigProp.java View File

@@ -8,7 +8,6 @@
package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import junit.framework.AssertionFailedError;
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>
* @version $Revision$ $Date$
*/
public class ConfigTest7
public class ConfigTestTypedConfigProp
{
private ArrayList m_configurations = new ArrayList();

@@ -28,7 +27,7 @@ public class ConfigTest7

public boolean equals( final Object object )
{
final ConfigTest7 other = (ConfigTest7)object;
final ConfigTestTypedConfigProp other = (ConfigTestTypedConfigProp)object;
return m_configurations.equals( other.m_configurations );
}
}

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest6.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTestTypedProp.java View File

@@ -8,8 +8,6 @@
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.
@@ -17,7 +15,7 @@ import org.apache.avalon.framework.configuration.Configuration;
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision$ $Date$
*/
public class ConfigTest6
public class ConfigTestTypedProp
{
private ArrayList m_roles = new ArrayList();

@@ -28,7 +26,7 @@ public class ConfigTest6

public boolean equals( final Object object )
{
final ConfigTest6 other = (ConfigTest6)object;
final ConfigTestTypedProp other = (ConfigTestTypedProp)object;
return m_roles.equals( other.m_roles );
}
}

+ 184
- 96
proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java View File

@@ -13,16 +13,12 @@ import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.context.Context;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.components.AbstractComponentTest;
import org.apache.myrmidon.components.workspace.DefaultTaskContext;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;

/**
* Test cases for the default configurer and related classes.
@@ -37,7 +33,6 @@ public class DefaultConfigurerTest

private Configurer m_configurer;
private DefaultTaskContext m_context;
private Context m_adaptor;

public DefaultConfigurerTest( String name )
{
@@ -59,7 +54,6 @@ public class DefaultConfigurerTest
m_context = new DefaultTaskContext();
final File baseDir = new File( "." ).getAbsoluteFile();
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
m_adaptor = new TaskContextAdapter( m_context );
}

/**
@@ -75,13 +69,13 @@ public class DefaultConfigurerTest
final String value2 = "some other value";
config.setAttribute( "prop", value2 );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( value1 );
expected.addProp( value2 );
assertEquals( expected, test );
@@ -99,18 +93,15 @@ public class DefaultConfigurerTest
config.setAttribute( "integer-prop", "-401" );

// Register the converter
final Class converterClass = StringToIntegerConverter.class;
final Class sourceClass = String.class;
final Class destClass = Integer.class;
registerConverter( converterClass, sourceClass, destClass );
registerConverter( StringToIntegerConverter.class, String.class, Integer.class );

final ConfigTest10 test = new ConfigTest10();
final ConfigTestPrimConvert test = new ConfigTestPrimConvert();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest10 expected = new ConfigTest10();
final ConfigTestPrimConvert expected = new ConfigTestPrimConvert();
expected.setIntProp( 90 );
expected.setIntegerProp( new Integer(-401) );
assertEquals( expected, test );
@@ -126,12 +117,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "unknown", "some value" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -158,17 +149,17 @@ public class DefaultConfigurerTest
child2.setAttribute( "some-prop", value2 );
config.addChild( child2 );

final ConfigTest2 test = new ConfigTest2();
final ConfigTestObjectProps test = new ConfigTestObjectProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest2 expected = new ConfigTest2();
ConfigTest1 elem = new ConfigTest1();
final ConfigTestObjectProps expected = new ConfigTestObjectProps();
ConfigTestStringProps elem = new ConfigTestStringProps();
elem.setSomeProp( value1 );
expected.setProp( elem );
elem = new ConfigTest1();
elem = new ConfigTestStringProps();
elem.setSomeProp( value2 );
expected.addAnotherProp( elem );
assertEquals( expected, test );
@@ -185,12 +176,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" );
config.addChild( elem );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -211,13 +202,13 @@ public class DefaultConfigurerTest
final String value1 = "some value";
config.setValue( value1 );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.addContent( value1 );
assertEquals( expected, test );
}
@@ -232,12 +223,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setValue( "some value" );

final ConfigTest2 test = new ConfigTest2();
final ConfigTestObjectProps test = new ConfigTestObjectProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -257,15 +248,15 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "prop", "some ${prop-a} value" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", "other" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.addProp( "some other value" );
assertEquals( expected, test );
}
@@ -279,15 +270,15 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "prop-a" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", "some value" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some value" );
assertEquals( expected, test );
}
@@ -303,15 +294,15 @@ public class DefaultConfigurerTest
elem.setAttribute( "id", "prop-a" );
config.addChild( elem );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", "some value" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some value" );
assertEquals( expected, test );
}
@@ -329,12 +320,12 @@ public class DefaultConfigurerTest
elem.setAttribute( "extra-attr", "some value" );
config.addChild( elem );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -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
* exception.
@@ -362,7 +404,7 @@ public class DefaultConfigurerTest
try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -386,12 +428,12 @@ public class DefaultConfigurerTest
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );

final ConfigTest5 test = new ConfigTest5();
final ConfigTestMultiTypedAdder test = new ConfigTestMultiTypedAdder();

try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -399,7 +441,7 @@ public class DefaultConfigurerTest
final String[] messages = {
REZ.getString( "bad-configure-element.error", "test" ),
REZ.getString( "multiple-adder-methods-for-element.error",
ConfigTest5.class.getName(),
ConfigTestMultiTypedAdder.class.getName(),
"")
};
assertSameMessage( messages, ce );
@@ -419,24 +461,75 @@ public class DefaultConfigurerTest
config.addChild( child1 );
config.addChild( child2 );

final ClassLoader loader = getClass().getClassLoader();
final DefaultTypeFactory factory = new DefaultTypeFactory( loader );
factory.addNameClassMapping( "my-type1", MyType1.class.getName() );
factory.addNameClassMapping( "my-type2", MyType2.class.getName() );
getTypeManager().registerType( DataType.class, "my-type1", factory );
getTypeManager().registerType( DataType.class, "my-type2", factory );
registerType( DataType.class, "my-type1", MyType1.class );
registerType( DataType.class, "my-type2", MyType2.class );

final ConfigTest6 test = new ConfigTest6();
final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest6 expected = new ConfigTest6();
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
expected.add( new MyType2() );
assertEquals( expected, test );
}

/**
* Tests to check that role is used for typed adder.
*/
public void testTypedAdderRole()
throws Exception
{
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
final DefaultConfiguration child1 = new DefaultConfiguration( "my-type1", "test" );
config.addChild( child1 );

// Register incompatible types with the same name, as data-type and myrole1.
registerRole( new RoleInfo( "myrole1", "myrole1", MyRole1.class ) );
registerType( MyRole1.class, "my-type1", MyType1.class );
registerType( DataType.class, "my-type1", StringBuffer.class );

final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_context );

// Check the result
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
assertEquals( expected, test );
}

/**
* Tests conversion with a typed adder.
*/
public void testTypedAdderConversion()
throws Exception
{
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
final DefaultConfiguration child = new DefaultConfiguration( "some-type", "test" );
child.setAttribute( "prop", "some value" );
config.addChild( child );

registerType( DataType.class, "some-type", ConfigTestStringProps.class );
registerConverter( ObjectToMyRole1Converter.class, Object.class, MyRole1.class );

final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_context );

// Check the result
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
final ConfigTestStringProps nested = new ConfigTestStringProps();
nested.addProp( "some value" );
expected.add( new MyRole1Adaptor( nested ) );
assertEquals( expected, test );
}

/**
* Tests to see if typed adder can be used via an attribute.
*/
@@ -448,19 +541,17 @@ public class DefaultConfigurerTest
config.setAttribute( "my-role1", "some value" );

// Set up the converter and role
RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE );
final RoleInfo roleInfo = new RoleInfo("my-role1", MyRole1.class );
roleMgr.addRole( roleInfo );
registerConverter( StringToMyRole1Converter.class, String.class, MyRole1.class );
registerRole( new RoleInfo("my-role1", MyRole1.class ) );
registerConverter( ObjectToMyRole1Converter.class, String.class, MyRole1.class );

final ConfigTest6 test = new ConfigTest6();
final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest6 expected = new ConfigTest6();
expected.add( new MyType1() );
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyRole1Adaptor( "some value" ) );
assertEquals( expected, test );
}

@@ -477,12 +568,12 @@ public class DefaultConfigurerTest
config.addChild( child1 );
config.addChild( child2 );

final ConfigTest7 test = new ConfigTest7();
final ConfigTestTypedConfigProp test = new ConfigTestTypedConfigProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest7 expected = new ConfigTest7();
final ConfigTestTypedConfigProp expected = new ConfigTestTypedConfigProp();
expected.add( child1 );
expected.add( child2 );
assertEquals( expected, test );
@@ -501,12 +592,12 @@ public class DefaultConfigurerTest
config.addChild( child1 );
config.addChild( child2 );

final ConfigTest8 test = new ConfigTest8();
final ConfigTestConfigProps test = new ConfigTestConfigProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest8 expected = new ConfigTest8();
final ConfigTestConfigProps expected = new ConfigTestConfigProps();
expected.addConfig( child1 );
expected.addConfig( child2 );
assertEquals( expected, test );
@@ -521,12 +612,12 @@ public class DefaultConfigurerTest
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );

final ConfigTest9 test = new ConfigTest9();
final ConfigTestConfigurable test = new ConfigTestConfigurable();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest9 expected = new ConfigTest9();
final ConfigTestConfigurable expected = new ConfigTestConfigurable();
expected.configure( config );
assertEquals( expected, test );
}
@@ -541,22 +632,22 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "${id}" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "id", "prop-a" );
m_context.setProperty( "prop-a", "some indirect value" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some indirect value" );
assertEquals( expected, test );
}

/**
* Test an unknown reference.
* Tests an unknown reference.
*/
public void testUnknownReference()
throws Exception
@@ -565,12 +656,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "unknown-prop" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -593,14 +684,14 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "prop-a" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", new ConfigTest2() );
m_context.setProperty( "prop-a", new ConfigTestObjectProps() );

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -609,8 +700,7 @@ public class DefaultConfigurerTest
REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ),
REZ.getString( "mismatch-ref-types.error",
"prop-a",
String.class.getName(),
ConfigTest2.class.getName() )
"some-prop" )
};
assertSameMessage( messages, e );
}
@@ -631,19 +721,17 @@ public class DefaultConfigurerTest
config.addChild( child );

// Add role mapping, and add to reference to context
final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE );
final RoleInfo roleInfo = new RoleInfo( "my-role1", MyRole1.class );
roleMgr.addRole( roleInfo );
registerRole( new RoleInfo( "my-role1", MyRole1.class ) );
m_context.setProperty( "id", new MyType1() );
m_context.setProperty( "id2", new MyType2() );

final ConfigTest6 test = new ConfigTest6();
final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Compare against expected value
final ConfigTest6 expected = new ConfigTest6();
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
expected.add( new MyType2() );
assertEquals( expected, test );
@@ -660,12 +748,12 @@ public class DefaultConfigurerTest
elem.setAttribute( "not-a-prop", "not-a-value" );
config.addChild( elem );

final ConfigTest2 test = new ConfigTest2();
final ConfigTestObjectProps test = new ConfigTestObjectProps();

try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -693,16 +781,16 @@ public class DefaultConfigurerTest
elem = new DefaultConfiguration( "prop3", "test" );
config.addChild( elem );

final ConfigTest3 test = new ConfigTest3();
final ConfigTestMultiSetter test = new ConfigTestMultiSetter();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Test expected value
final ConfigTest3 expected = new ConfigTest3();
expected.setProp1( new ConfigTest1() );
expected.setProp2( new ConfigTest1() );
expected.addProp3( new ConfigTest1() );
final ConfigTestMultiSetter expected = new ConfigTestMultiSetter();
expected.setProp1( new ConfigTestStringProps() );
expected.setProp2( new ConfigTestStringProps() );
expected.addProp3( new ConfigTestStringProps() );
assertEquals( expected, test );
}
}

+ 33
- 0
proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/MyRole1Adaptor.java View File

@@ -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 );
}
}

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/StringToMyRole1Converter.java → proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ObjectToMyRole1Converter.java View File

@@ -9,24 +9,24 @@ package org.apache.myrmidon.components.configurer;

import org.apache.aut.converter.AbstractConverter;
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>
* @version $Revision$ $Date$
*/
public class StringToMyRole1Converter
public class ObjectToMyRole1Converter
extends AbstractConverter
{
public StringToMyRole1Converter()
public ObjectToMyRole1Converter()
{
super( String.class, MyRole1.class );
super( Object.class, MyRole1.class );
}

protected Object convert( Object original, Object context )
throws ConverterException
{
return new MyType1();
return new MyRole1Adaptor( original );
}
}

+ 7
- 9
proposal/myrmidon/src/test/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java View File

@@ -7,21 +7,19 @@
*/
package org.apache.myrmidon.components.deployer;

import java.io.File;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.components.AbstractComponentTest;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.aut.converter.ConverterException;
import org.apache.aut.converter.Converter;
import java.io.File;
import org.apache.myrmidon.interfaces.type.TypeFactory;

/**
* Test cases for the default deployer.
@@ -37,7 +35,7 @@ public class DefaultDeployerTest

private Deployer m_deployer;
private RoleManager m_roleManager;
private MasterConverter m_converter;
private Converter m_converter;

public DefaultDeployerTest( final String name )
{
@@ -52,7 +50,7 @@ public class DefaultDeployerTest
{
super.setUp();
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE );
m_converter = (MasterConverter)getServiceManager().lookup( MasterConverter.ROLE );
m_converter = (Converter)getServiceManager().lookup( Converter.ROLE );

// Add some core roles
m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE );


+ 0
- 1
proposal/myrmidon/src/test/org/apache/myrmidon/components/deployer/TestConverter1.java View File

@@ -9,7 +9,6 @@ package org.apache.myrmidon.components.deployer;

import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.framework.context.Context;

/**
* A test converter.


+ 3
- 0
proposal/myrmidon/src/testcases/org/apache/myrmidon/AbstractProjectTest.java View File

@@ -50,6 +50,9 @@ public class AbstractProjectTest
{
if( m_embeddor == null )
{
// Need to set the context classloader - The default embeddor uses it
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );

final Logger logger = createLogger();
m_embeddor = new DefaultEmbeddor();
m_embeddor.enableLogging( logger );


+ 25
- 2
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java View File

@@ -29,9 +29,9 @@ import org.apache.myrmidon.components.role.DefaultRoleManager;
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
import org.apache.myrmidon.interfaces.type.TypeException;
@@ -83,7 +83,7 @@ public abstract class AbstractComponentTest
List components = new ArrayList();

Object component = new DefaultMasterConverter();
m_serviceManager.put( MasterConverter.ROLE, component );
m_serviceManager.put( Converter.ROLE, component );
components.add( component );

component = new DefaultConverterRegistry();
@@ -138,6 +138,29 @@ 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.


+ 1
- 2
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest4.java View File

@@ -7,8 +7,7 @@
*/
package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import junit.framework.AssertionFailedError;


/**
* Simple class to test typed adder.


proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest8.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestConfigProps.java View File

@@ -8,7 +8,6 @@
package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import junit.framework.AssertionFailedError;
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>
* @version $Revision$ $Date$
*/
public class ConfigTest8
public class ConfigTestConfigProps
{
private ArrayList m_configurations = new ArrayList();

@@ -28,7 +27,7 @@ public class ConfigTest8

public boolean equals( final Object object )
{
final ConfigTest8 other = (ConfigTest8)object;
final ConfigTestConfigProps other = (ConfigTestConfigProps)object;
return m_configurations.equals( other.m_configurations );
}
}

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest9.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestConfigurable.java View File

@@ -7,19 +7,17 @@
*/
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.Configuration;
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>
* @version $Revision$ $Date$
*/
public class ConfigTest9
public class ConfigTestConfigurable
implements Configurable
{
private Configuration m_configuration;
@@ -32,7 +30,7 @@ public class ConfigTest9

public boolean equals( final Object object )
{
final ConfigTest9 other = (ConfigTest9)object;
final ConfigTestConfigurable other = (ConfigTestConfigurable)object;
return m_configuration == other.m_configuration;
}
}

+ 32
- 0
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestInterfaceProp.java View File

@@ -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 );
}
}

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest3.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestMultiSetter.java View File

@@ -15,15 +15,15 @@ import junit.framework.AssertionFailedError;
*
* @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();

public boolean equals( Object obj )
{
ConfigTest3 test = (ConfigTest3)obj;
ConfigTestMultiSetter test = (ConfigTestMultiSetter)obj;
if( !DefaultConfigurerTest.equals( m_prop1, test.m_prop1 ) )
{
return false;
@@ -48,7 +48,7 @@ public class ConfigTest3
throw new AssertionFailedError();
}

public void setProp1( final ConfigTest1 value )
public void setProp1( final ConfigTestStringProps value )
{
m_prop1 = value;
}
@@ -62,7 +62,7 @@ public class ConfigTest3
throw new AssertionFailedError();
}

public void setProp2( final ConfigTest1 value )
public void setProp2( final ConfigTestStringProps value )
{
m_prop2 = value;
}
@@ -76,7 +76,7 @@ public class ConfigTest3
throw new AssertionFailedError();
}

public void addProp3( final ConfigTest1 value )
public void addProp3( final ConfigTestStringProps value )
{
m_prop3.add( value );
}

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest5.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestMultiTypedAdder.java View File

@@ -7,17 +7,15 @@
*/
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>
* @version $Revision$ $Date$
*/
public class ConfigTest5
public class ConfigTestMultiTypedAdder
{
public void add( final MyRole1 role1 )
{

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest2.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestObjectProps.java View File

@@ -15,14 +15,14 @@ import java.util.List;
*
* @author Adam Murdoch
*/
public class ConfigTest2
public class ConfigTestObjectProps
{
ConfigTest1 m_prop;
ConfigTestStringProps m_prop;
List m_propList = new ArrayList();

public boolean equals( Object obj )
{
ConfigTest2 test = (ConfigTest2)obj;
ConfigTestObjectProps test = (ConfigTestObjectProps)obj;
if( !DefaultConfigurerTest.equals( m_prop, test.m_prop ) )
{
return false;
@@ -34,12 +34,12 @@ public class ConfigTest2
return true;
}

public void setProp( final ConfigTest1 test )
public void setProp( final ConfigTestStringProps test )
{
m_prop = test;
}

public void addAnotherProp( final ConfigTest1 test )
public void addAnotherProp( final ConfigTestStringProps test )
{
m_propList.add( test );
}

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest10.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestPrimConvert.java View File

@@ -14,24 +14,24 @@ import org.apache.myrmidon.components.AbstractComponentTest;
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*/
public class ConfigTest10
public class ConfigTestPrimConvert
{
private int m_intProp;
private Integer m_integerProp;

public void setIntProp( int intProp )
public void setIntProp( final int intProp )
{
m_intProp = intProp;
}

public void setIntegerProp( Integer integerProp )
public void setIntegerProp( final Integer integerProp )
{
m_integerProp = integerProp;
}

public boolean equals( Object obj )
{
ConfigTest10 test = (ConfigTest10)obj;
ConfigTestPrimConvert test = (ConfigTestPrimConvert)obj;
if( m_intProp != test.m_intProp )
{
return false;

proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTest1.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestStringProps.java View File

@@ -9,13 +9,15 @@ package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import java.util.List;
import org.apache.myrmidon.framework.DataType;

/**
* A simple test class.
* A simple test class with string properties.
*
* @author Adam Murdoch
*/
public class ConfigTest1
public class ConfigTestStringProps
implements DataType
{
private String m_someProp;
private List m_propList = new ArrayList();
@@ -23,7 +25,7 @@ public class ConfigTest1

public boolean equals( final Object obj )
{
final ConfigTest1 test = (ConfigTest1)obj;
final ConfigTestStringProps test = (ConfigTestStringProps)obj;
if( !DefaultConfigurerTest.equals( m_someProp, test.m_someProp ) )
{
return false;

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest7.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestTypedConfigProp.java View File

@@ -8,7 +8,6 @@
package org.apache.myrmidon.components.configurer;

import java.util.ArrayList;
import junit.framework.AssertionFailedError;
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>
* @version $Revision$ $Date$
*/
public class ConfigTest7
public class ConfigTestTypedConfigProp
{
private ArrayList m_configurations = new ArrayList();

@@ -28,7 +27,7 @@ public class ConfigTest7

public boolean equals( final Object object )
{
final ConfigTest7 other = (ConfigTest7)object;
final ConfigTestTypedConfigProp other = (ConfigTestTypedConfigProp)object;
return m_configurations.equals( other.m_configurations );
}
}

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/ConfigTest6.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ConfigTestTypedProp.java View File

@@ -8,8 +8,6 @@
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.
@@ -17,7 +15,7 @@ import org.apache.avalon.framework.configuration.Configuration;
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision$ $Date$
*/
public class ConfigTest6
public class ConfigTestTypedProp
{
private ArrayList m_roles = new ArrayList();

@@ -28,7 +26,7 @@ public class ConfigTest6

public boolean equals( final Object object )
{
final ConfigTest6 other = (ConfigTest6)object;
final ConfigTestTypedProp other = (ConfigTestTypedProp)object;
return m_roles.equals( other.m_roles );
}
}

+ 184
- 96
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java View File

@@ -13,16 +13,12 @@ import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.context.Context;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.components.AbstractComponentTest;
import org.apache.myrmidon.components.workspace.DefaultTaskContext;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.configurer.Configurer;
import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;

/**
* Test cases for the default configurer and related classes.
@@ -37,7 +33,6 @@ public class DefaultConfigurerTest

private Configurer m_configurer;
private DefaultTaskContext m_context;
private Context m_adaptor;

public DefaultConfigurerTest( String name )
{
@@ -59,7 +54,6 @@ public class DefaultConfigurerTest
m_context = new DefaultTaskContext();
final File baseDir = new File( "." ).getAbsoluteFile();
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
m_adaptor = new TaskContextAdapter( m_context );
}

/**
@@ -75,13 +69,13 @@ public class DefaultConfigurerTest
final String value2 = "some other value";
config.setAttribute( "prop", value2 );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( value1 );
expected.addProp( value2 );
assertEquals( expected, test );
@@ -99,18 +93,15 @@ public class DefaultConfigurerTest
config.setAttribute( "integer-prop", "-401" );

// Register the converter
final Class converterClass = StringToIntegerConverter.class;
final Class sourceClass = String.class;
final Class destClass = Integer.class;
registerConverter( converterClass, sourceClass, destClass );
registerConverter( StringToIntegerConverter.class, String.class, Integer.class );

final ConfigTest10 test = new ConfigTest10();
final ConfigTestPrimConvert test = new ConfigTestPrimConvert();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest10 expected = new ConfigTest10();
final ConfigTestPrimConvert expected = new ConfigTestPrimConvert();
expected.setIntProp( 90 );
expected.setIntegerProp( new Integer(-401) );
assertEquals( expected, test );
@@ -126,12 +117,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "unknown", "some value" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -158,17 +149,17 @@ public class DefaultConfigurerTest
child2.setAttribute( "some-prop", value2 );
config.addChild( child2 );

final ConfigTest2 test = new ConfigTest2();
final ConfigTestObjectProps test = new ConfigTestObjectProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest2 expected = new ConfigTest2();
ConfigTest1 elem = new ConfigTest1();
final ConfigTestObjectProps expected = new ConfigTestObjectProps();
ConfigTestStringProps elem = new ConfigTestStringProps();
elem.setSomeProp( value1 );
expected.setProp( elem );
elem = new ConfigTest1();
elem = new ConfigTestStringProps();
elem.setSomeProp( value2 );
expected.addAnotherProp( elem );
assertEquals( expected, test );
@@ -185,12 +176,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration elem = new DefaultConfiguration( "unknown", "test" );
config.addChild( elem );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -211,13 +202,13 @@ public class DefaultConfigurerTest
final String value1 = "some value";
config.setValue( value1 );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.addContent( value1 );
assertEquals( expected, test );
}
@@ -232,12 +223,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setValue( "some value" );

final ConfigTest2 test = new ConfigTest2();
final ConfigTestObjectProps test = new ConfigTestObjectProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -257,15 +248,15 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "prop", "some ${prop-a} value" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", "other" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.addProp( "some other value" );
assertEquals( expected, test );
}
@@ -279,15 +270,15 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "prop-a" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", "some value" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some value" );
assertEquals( expected, test );
}
@@ -303,15 +294,15 @@ public class DefaultConfigurerTest
elem.setAttribute( "id", "prop-a" );
config.addChild( elem );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", "some value" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some value" );
assertEquals( expected, test );
}
@@ -329,12 +320,12 @@ public class DefaultConfigurerTest
elem.setAttribute( "extra-attr", "some value" );
config.addChild( elem );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -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
* exception.
@@ -362,7 +404,7 @@ public class DefaultConfigurerTest
try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -386,12 +428,12 @@ public class DefaultConfigurerTest
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );

final ConfigTest5 test = new ConfigTest5();
final ConfigTestMultiTypedAdder test = new ConfigTestMultiTypedAdder();

try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( final ConfigurationException ce )
@@ -399,7 +441,7 @@ public class DefaultConfigurerTest
final String[] messages = {
REZ.getString( "bad-configure-element.error", "test" ),
REZ.getString( "multiple-adder-methods-for-element.error",
ConfigTest5.class.getName(),
ConfigTestMultiTypedAdder.class.getName(),
"")
};
assertSameMessage( messages, ce );
@@ -419,24 +461,75 @@ public class DefaultConfigurerTest
config.addChild( child1 );
config.addChild( child2 );

final ClassLoader loader = getClass().getClassLoader();
final DefaultTypeFactory factory = new DefaultTypeFactory( loader );
factory.addNameClassMapping( "my-type1", MyType1.class.getName() );
factory.addNameClassMapping( "my-type2", MyType2.class.getName() );
getTypeManager().registerType( DataType.class, "my-type1", factory );
getTypeManager().registerType( DataType.class, "my-type2", factory );
registerType( DataType.class, "my-type1", MyType1.class );
registerType( DataType.class, "my-type2", MyType2.class );

final ConfigTest6 test = new ConfigTest6();
final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest6 expected = new ConfigTest6();
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
expected.add( new MyType2() );
assertEquals( expected, test );
}

/**
* Tests to check that role is used for typed adder.
*/
public void testTypedAdderRole()
throws Exception
{
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
final DefaultConfiguration child1 = new DefaultConfiguration( "my-type1", "test" );
config.addChild( child1 );

// Register incompatible types with the same name, as data-type and myrole1.
registerRole( new RoleInfo( "myrole1", "myrole1", MyRole1.class ) );
registerType( MyRole1.class, "my-type1", MyType1.class );
registerType( DataType.class, "my-type1", StringBuffer.class );

final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_context );

// Check the result
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
assertEquals( expected, test );
}

/**
* Tests conversion with a typed adder.
*/
public void testTypedAdderConversion()
throws Exception
{
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
final DefaultConfiguration child = new DefaultConfiguration( "some-type", "test" );
child.setAttribute( "prop", "some value" );
config.addChild( child );

registerType( DataType.class, "some-type", ConfigTestStringProps.class );
registerConverter( ObjectToMyRole1Converter.class, Object.class, MyRole1.class );

final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_context );

// Check the result
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
final ConfigTestStringProps nested = new ConfigTestStringProps();
nested.addProp( "some value" );
expected.add( new MyRole1Adaptor( nested ) );
assertEquals( expected, test );
}

/**
* Tests to see if typed adder can be used via an attribute.
*/
@@ -448,19 +541,17 @@ public class DefaultConfigurerTest
config.setAttribute( "my-role1", "some value" );

// Set up the converter and role
RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE );
final RoleInfo roleInfo = new RoleInfo("my-role1", MyRole1.class );
roleMgr.addRole( roleInfo );
registerConverter( StringToMyRole1Converter.class, String.class, MyRole1.class );
registerRole( new RoleInfo("my-role1", MyRole1.class ) );
registerConverter( ObjectToMyRole1Converter.class, String.class, MyRole1.class );

final ConfigTest6 test = new ConfigTest6();
final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check result
final ConfigTest6 expected = new ConfigTest6();
expected.add( new MyType1() );
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyRole1Adaptor( "some value" ) );
assertEquals( expected, test );
}

@@ -477,12 +568,12 @@ public class DefaultConfigurerTest
config.addChild( child1 );
config.addChild( child2 );

final ConfigTest7 test = new ConfigTest7();
final ConfigTestTypedConfigProp test = new ConfigTestTypedConfigProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest7 expected = new ConfigTest7();
final ConfigTestTypedConfigProp expected = new ConfigTestTypedConfigProp();
expected.add( child1 );
expected.add( child2 );
assertEquals( expected, test );
@@ -501,12 +592,12 @@ public class DefaultConfigurerTest
config.addChild( child1 );
config.addChild( child2 );

final ConfigTest8 test = new ConfigTest8();
final ConfigTestConfigProps test = new ConfigTestConfigProps();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest8 expected = new ConfigTest8();
final ConfigTestConfigProps expected = new ConfigTestConfigProps();
expected.addConfig( child1 );
expected.addConfig( child2 );
assertEquals( expected, test );
@@ -521,12 +612,12 @@ public class DefaultConfigurerTest
// Setup test data
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );

final ConfigTest9 test = new ConfigTest9();
final ConfigTestConfigurable test = new ConfigTestConfigurable();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

final ConfigTest9 expected = new ConfigTest9();
final ConfigTestConfigurable expected = new ConfigTestConfigurable();
expected.configure( config );
assertEquals( expected, test );
}
@@ -541,22 +632,22 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "${id}" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "id", "prop-a" );
m_context.setProperty( "prop-a", "some indirect value" );

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Check the configured object
final ConfigTest1 expected = new ConfigTest1();
final ConfigTestStringProps expected = new ConfigTestStringProps();
expected.setSomeProp( "some indirect value" );
assertEquals( expected, test );
}

/**
* Test an unknown reference.
* Tests an unknown reference.
*/
public void testUnknownReference()
throws Exception
@@ -565,12 +656,12 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "unknown-prop" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -593,14 +684,14 @@ public class DefaultConfigurerTest
final DefaultConfiguration config = new DefaultConfiguration( "test", "test" );
config.setAttribute( "some-prop-ref", "prop-a" );

final ConfigTest1 test = new ConfigTest1();
final ConfigTestStringProps test = new ConfigTestStringProps();

m_context.setProperty( "prop-a", new ConfigTest2() );
m_context.setProperty( "prop-a", new ConfigTestObjectProps() );

// Configure the object
try
{
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -609,8 +700,7 @@ public class DefaultConfigurerTest
REZ.getString( "bad-set-attribute.error", "test", "some-prop-ref" ),
REZ.getString( "mismatch-ref-types.error",
"prop-a",
String.class.getName(),
ConfigTest2.class.getName() )
"some-prop" )
};
assertSameMessage( messages, e );
}
@@ -631,19 +721,17 @@ public class DefaultConfigurerTest
config.addChild( child );

// Add role mapping, and add to reference to context
final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( RoleManager.ROLE );
final RoleInfo roleInfo = new RoleInfo( "my-role1", MyRole1.class );
roleMgr.addRole( roleInfo );
registerRole( new RoleInfo( "my-role1", MyRole1.class ) );
m_context.setProperty( "id", new MyType1() );
m_context.setProperty( "id2", new MyType2() );

final ConfigTest6 test = new ConfigTest6();
final ConfigTestTypedProp test = new ConfigTestTypedProp();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Compare against expected value
final ConfigTest6 expected = new ConfigTest6();
final ConfigTestTypedProp expected = new ConfigTestTypedProp();
expected.add( new MyType1() );
expected.add( new MyType2() );
assertEquals( expected, test );
@@ -660,12 +748,12 @@ public class DefaultConfigurerTest
elem.setAttribute( "not-a-prop", "not-a-value" );
config.addChild( elem );

final ConfigTest2 test = new ConfigTest2();
final ConfigTestObjectProps test = new ConfigTestObjectProps();

try
{
// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );
fail();
}
catch( ConfigurationException e )
@@ -693,16 +781,16 @@ public class DefaultConfigurerTest
elem = new DefaultConfiguration( "prop3", "test" );
config.addChild( elem );

final ConfigTest3 test = new ConfigTest3();
final ConfigTestMultiSetter test = new ConfigTestMultiSetter();

// Configure the object
m_configurer.configure( test, config, m_adaptor );
m_configurer.configure( test, config, m_context );

// Test expected value
final ConfigTest3 expected = new ConfigTest3();
expected.setProp1( new ConfigTest1() );
expected.setProp2( new ConfigTest1() );
expected.addProp3( new ConfigTest1() );
final ConfigTestMultiSetter expected = new ConfigTestMultiSetter();
expected.setProp1( new ConfigTestStringProps() );
expected.setProp2( new ConfigTestStringProps() );
expected.addProp3( new ConfigTestStringProps() );
assertEquals( expected, test );
}
}

+ 33
- 0
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/MyRole1Adaptor.java View File

@@ -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 );
}
}

proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/StringToMyRole1Converter.java → proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/ObjectToMyRole1Converter.java View File

@@ -9,24 +9,24 @@ package org.apache.myrmidon.components.configurer;

import org.apache.aut.converter.AbstractConverter;
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>
* @version $Revision$ $Date$
*/
public class StringToMyRole1Converter
public class ObjectToMyRole1Converter
extends AbstractConverter
{
public StringToMyRole1Converter()
public ObjectToMyRole1Converter()
{
super( String.class, MyRole1.class );
super( Object.class, MyRole1.class );
}

protected Object convert( Object original, Object context )
throws ConverterException
{
return new MyType1();
return new MyRole1Adaptor( original );
}
}

+ 7
- 9
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java View File

@@ -7,21 +7,19 @@
*/
package org.apache.myrmidon.components.deployer;

import java.io.File;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.components.AbstractComponentTest;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.interfaces.converter.MasterConverter;
import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.aut.converter.ConverterException;
import org.apache.aut.converter.Converter;
import java.io.File;
import org.apache.myrmidon.interfaces.type.TypeFactory;

/**
* Test cases for the default deployer.
@@ -37,7 +35,7 @@ public class DefaultDeployerTest

private Deployer m_deployer;
private RoleManager m_roleManager;
private MasterConverter m_converter;
private Converter m_converter;

public DefaultDeployerTest( final String name )
{
@@ -52,7 +50,7 @@ public class DefaultDeployerTest
{
super.setUp();
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE );
m_converter = (MasterConverter)getServiceManager().lookup( MasterConverter.ROLE );
m_converter = (Converter)getServiceManager().lookup( Converter.ROLE );

// Add some core roles
m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE );


+ 0
- 1
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/TestConverter1.java View File

@@ -9,7 +9,6 @@ package org.apache.myrmidon.components.deployer;

import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
import org.apache.avalon.framework.context.Context;

/**
* A test converter.


+ 1
- 1
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/Script.java View File

@@ -88,7 +88,7 @@ public class Script extends AbstractTask
{
try
{
addBeans( getContext().getPropertys() );
addBeans( getContext().getProperties() );
//In Ant2 there is no difference between properties and references
//addBeans( getProject().getReferences() );



+ 2
- 2
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -617,7 +617,7 @@ public class JUnitTask extends AbstractTask
// Create a temporary file to pass the Ant properties to the forked test
File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" );
cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() );
Map p = getContext().getPropertys();
Map p = getContext().getProperties();
Properties props = new Properties();
for( Iterator enum = p.keySet().iterator(); enum.hasNext(); )
{
@@ -663,7 +663,7 @@ public class JUnitTask extends AbstractTask
private int executeInVM( JUnitTest test )
throws TaskException
{
test.setProperties( getContext().getPropertys() );
test.setProperties( getContext().getProperties() );
if( dir != null )
{
getLogger().warn( "dir attribute ignored if running in the same VM" );


+ 0
- 1
proposal/myrmidon/src/todo/org/apache/tools/ant/types/converters/StringToPathConverter.java View File

@@ -7,7 +7,6 @@
*/
package org.apache.tools.ant.types.converters;

import org.apache.avalon.framework.context.Context;
import org.apache.aut.converter.AbstractConverter;
import org.apache.aut.converter.ConverterException;
import org.apache.tools.ant.types.Path;


Loading…
Cancel
Save