donaldp 2002/06/29 23:23:31
Modified: container/src/java/org/apache/myrmidon/components/embeddor
DefaultEmbeddor.java
container/src/java/org/apache/myrmidon/components/executor
DefaultExecutionFrame.java
container/src/java/org/apache/myrmidon/components/type
DefaultTypeManager.java Resources.properties
container/src/java/org/apache/myrmidon/interfaces/type
TypeManager.java
container/src/test/org/apache/myrmidon/components
AbstractComponentTest.java
container/src/test/org/apache/myrmidon/components/service/test
InstantiatingServiceManagerTestCase.java
container/src/test/org/apache/myrmidon/components/type/test
DefaultTypeManagerTestCase.java
Added: container/src/test/org/apache/myrmidon/components/type/test
DefaultRoleManagerTestCase.java
Removed: container/src/java/org/apache/myrmidon/components/role
DefaultRoleManager.java Resources.properties
container/src/test/org/apache/myrmidon/components/role/test
DefaultRoleManagerTestCase.java
Log:
Merge TypeManager/RoleManager implementations.
Revision Changes Path
1.108 +3 -5
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
Index: DefaultEmbeddor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- DefaultEmbeddor.java 27 Jun 2002 23:39:47 -0000 1.107
+++ DefaultEmbeddor.java 30 Jun 2002 06:23:30 -0000 1.108
@@ -33,7 +33,6 @@
import org.apache.myrmidon.api.metadata.ModelElement;
import org.apache.myrmidon.components.executor.DefaultExecutionFrame;
import org.apache.myrmidon.components.property.DefaultPropertyStore;
-import org.apache.myrmidon.components.role.DefaultRoleManager;
import org.apache.myrmidon.components.service.InstantiatingServiceManager;
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.components.workspace.DefaultWorkspace;
@@ -182,11 +181,10 @@
m_rootProps = new DefaultPropertyStore();
ContainerUtil.service( m_rootProps, m_serviceManager );
- final RoleManager roleManager = new DefaultRoleManager();
- m_typeManager = new DefaultTypeManager( null, roleManager );
+ m_typeManager = new DefaultTypeManager();
m_serviceManager.registerService( new String[]{RoleManager.ROLE,
RoleRegistry.ROLE},
- roleManager );
+ m_typeManager );
m_serviceManager.registerService( new String[]{TypeManager.ROLE,
TypeRegistry.ROLE},
m_typeManager );
m_serviceManager.registerService( new String[]{PropertyStore.ROLE},
1.23 +4 -9
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/executor/DefaultExecutionFrame.java
Index: DefaultExecutionFrame.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/executor/DefaultExecutionFrame.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- DefaultExecutionFrame.java 24 Jun 2002 01:50:01 -0000 1.22
+++ DefaultExecutionFrame.java 30 Jun 2002 06:23:30 -0000 1.23
@@ -14,7 +14,6 @@
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.components.workspace.DefaultTaskContext;
-import org.apache.myrmidon.components.role.DefaultRoleManager;
import org.apache.myrmidon.interfaces.event.TaskEventManager;
import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
import org.apache.myrmidon.interfaces.property.PropertyStore;
@@ -135,11 +134,8 @@
final PropertyStore basePS = (PropertyStore)lookup(
PropertyStore.ROLE );
final PropertyStore ps = basePS.createChildStore();
- final RoleManager baseRM = (RoleManager)lookup( RoleManager.ROLE
);
- final RoleManager rm = new DefaultRoleManager( baseRM );
-
final TypeManager baseTM = (TypeManager)lookup( TypeManager.ROLE
);
- final TypeManager tm = baseTM.getChildTypeManager( rm );
+ final TypeManager tm = baseTM.getChildTypeManager();
final AntServiceKernel baseSK = (AntServiceKernel)lookup(
AntServiceKernel.ROLE );
final AntServiceKernel sk = baseSK.createChild();
@@ -148,9 +144,8 @@
dsm.put( PropertyStore.ROLE, ps );
dsm.put( AntServiceKernel.ROLE, sk );
- dsm.put( RoleManager.ROLE, rm );
- dsm.put( RoleRegistry.ROLE, rm );
-
+ dsm.put( RoleManager.ROLE, tm );
+ dsm.put( RoleRegistry.ROLE, tm );
dsm.put( TypeManager.ROLE, tm );
dsm.put( TypeRegistry.ROLE, tm );
1.30 +91 -9
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java
Index: DefaultTypeManager.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DefaultTypeManager.java 21 Jun 2002 08:05:35 -0000 1.29
+++ DefaultTypeManager.java 30 Jun 2002 06:23:30 -0000 1.30
@@ -12,6 +12,8 @@
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
+import org.apache.myrmidon.interfaces.role.RoleException;
+import org.apache.myrmidon.interfaces.role.RoleRegistry;
import org.apache.myrmidon.interfaces.type.TypeException;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
@@ -25,7 +27,7 @@
* @version $Revision$ $Date$
*/
public class DefaultTypeManager
- implements TypeRegistry, TypeManager
+ implements TypeRegistry, TypeManager, RoleManager, RoleRegistry
{
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultTypeManager.class );
@@ -33,20 +35,27 @@
///Parent type manager to inherit values from.
private final DefaultTypeManager m_parent;
+ /** Map from role name -> RoleInfo. */
+ private final HashMap m_nameMap = new HashMap();
+
+ /** Map from role impl class -> RoleInfo. */
+ private final HashMap m_typeMap = new HashMap();
+
///Maps role Class to NamespaceAwareTypeFactory.
private final HashMap m_roleMap = new HashMap();
- private RoleManager m_roleManager;
+ public DefaultTypeManager()
+ {
+ this( null );
+ }
/**
* Create a chained DefaultTypeManager which wraps a parent TypeManager.
* @param parent The parent TypeManager - unknown types are delegated to
the parent.
*/
- public DefaultTypeManager( final DefaultTypeManager parent,
- final RoleManager roleManager )
+ public DefaultTypeManager( final DefaultTypeManager parent )
{
m_parent = parent;
- m_roleManager = roleManager;
}
/**
@@ -81,9 +90,82 @@
return createFactory( roleName );
}
- public TypeManager getChildTypeManager( RoleManager roleManager )
+ public TypeManager getChildTypeManager()
+ {
+ return new DefaultTypeManager( this );
+ }
+
+
+ /**
+ * Find role based on role type.
+ *
+ * @param classname the role type.
+ * @return the role, or null if the role cannot be found.
+ */
+ public RoleInfo getRoleByInterface( final String classname )
+ {
+ final RoleInfo role = (RoleInfo)m_typeMap.get( classname );
+
+ if( null == role && null != m_parent )
+ {
+ return m_parent.getRoleByInterface( classname );
+ }
+
+ return role;
+ }
+
+ /**
+ * Find role based on name.
+ *
+ * @param name the role name
+ * @return the role, or null if the role cannot be found.
+ */
+ public RoleInfo getRoleByShortName( final String name )
+ {
+ final RoleInfo role = (RoleInfo)m_nameMap.get( name );
+
+ if( null == role && null != m_parent )
+ {
+ return m_parent.getRoleByShortName( name );
+ }
+
+ return role;
+ }
+
+ /**
+ * Adds a role definition.
+ */
+ public void addRole( final RoleInfo role ) throws RoleException
{
- return new DefaultTypeManager( this, roleManager );
+ // Check for duplicate role names
+ final String roleName = role.getShortName();
+ RoleInfo oldRole = (RoleInfo)m_nameMap.get( roleName );
+ if( null != oldRole && !oldRole.equals( role ) )
+ {
+ final String message = REZ.getString( "duplicate-role.error",
roleName );
+ throw new RoleException( message );
+ }
+
+ // Check for duplicate implementation classes
+ final Class roleImplClass = role.getImplementationClass();
+ if( roleImplClass != null )
+ {
+ final String classname = roleImplClass.getName();
+ oldRole = (RoleInfo)m_typeMap.get( classname );
+ if( null != oldRole && !oldRole.equals( role ) )
+ {
+ final String message =
+ REZ.getString( "duplicate-type.error", classname );
+ throw new RoleException( message );
+ }
+ }
+
+ // Add the role to the maps
+ m_nameMap.put( roleName, role );
+ if( roleImplClass != null )
+ {
+ m_typeMap.put( roleImplClass.getName(), role );
+ }
}
/**
@@ -116,7 +198,7 @@
else
{
// Lookup the role type
- final RoleInfo role = m_roleManager.getRoleByInterface( roleName
);
+ final RoleInfo role = getRoleByInterface( roleName );
if( role == null )
{
final String message = REZ.getString( "unknown-role.error",
roleName );
1.8 +2 -0
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/type/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/type/Resources.properties,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Resources.properties 25 Jun 2002 07:29:25 -0000 1.7
+++ Resources.properties 30 Jun 2002 06:23:30 -0000 1.8
@@ -1,5 +1,7 @@
# DefaultTypeManager
unknown-role.error=Cannot create a type factory for unknown role {0}.
+duplicate-type.error=Duplicate roles with implementation class "{0}".
+duplicate-role.error=Duplicate roles with name "{0}".
# MultiSourceTypeFactory
no-instantiate.error=Unable to instantiate ({0}).
1.16 +2 -4
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeManager.java
Index: TypeManager.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TypeManager.java 21 Jun 2002 02:59:52 -0000 1.15
+++ TypeManager.java 30 Jun 2002 06:23:30 -0000 1.16
@@ -7,8 +7,6 @@
*/
package org.apache.myrmidon.interfaces.type;
-import org.apache.myrmidon.interfaces.role.RoleManager;
-
/**
* This interface is used to lookup type factories.
*
@@ -36,5 +34,5 @@
TypeFactory getFactory( String roleName )
throws TypeException;
- TypeManager getChildTypeManager( RoleManager roleManager );
+ TypeManager getChildTypeManager();
}
1.50 +4 -10
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/AbstractComponentTest.java
Index: AbstractComponentTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/AbstractComponentTest.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- AbstractComponentTest.java 27 Jun 2002 23:32:27 -0000 1.49
+++ AbstractComponentTest.java 30 Jun 2002 06:23:30 -0000 1.50
@@ -35,7 +35,6 @@
import org.apache.myrmidon.components.property.DefaultNameValidatorManager;
import org.apache.myrmidon.components.property.DefaultPropertyResolver;
import org.apache.myrmidon.components.property.DefaultPropertyStore;
-import org.apache.myrmidon.components.role.DefaultRoleManager;
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.interfaces.builder.ModelBuilder;
import org.apache.myrmidon.interfaces.configurer.Configurer;
@@ -91,16 +90,11 @@
m_serviceManager.put( ConverterRegistry.ROLE, component );
components.add( component );
- final RoleManager roleManager =
- (RoleManager)createComponent( RoleManager.ROLE,
DefaultRoleManager.class );
- component = roleManager;
- m_serviceManager.put( RoleManager.ROLE, component );
- m_serviceManager.put( RoleRegistry.ROLE, component );
- components.add( component );
-
- component = new DefaultTypeManager( null, roleManager );
+ component = new DefaultTypeManager();
m_serviceManager.put( TypeManager.ROLE, component );
m_serviceManager.put( TypeRegistry.ROLE, component );
+ m_serviceManager.put( RoleManager.ROLE, component );
+ m_serviceManager.put( RoleRegistry.ROLE, component );
components.add( component );
component = createComponent( Configurer.ROLE,
DefaultConfigurer.class );
1.12 +3 -3
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/service/test/InstantiatingServiceManagerTestCase.java
Index: InstantiatingServiceManagerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/service/test/InstantiatingServiceManagerTestCase.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- InstantiatingServiceManagerTestCase.java 16 Jun 2002 04:15:27 -0000
1.11
+++ InstantiatingServiceManagerTestCase.java 30 Jun 2002 06:23:31 -0000
1.12
@@ -11,7 +11,7 @@
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.myrmidon.components.AbstractComponentTest;
-import org.apache.myrmidon.components.role.DefaultRoleManager;
+import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.components.service.InstantiatingServiceManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
@@ -46,7 +46,7 @@
m_serviceManager = new InstantiatingServiceManager( getLogger(), new
DefaultContext() );
m_serviceManager.enableLogging( getLogger() );
- final DefaultRoleManager roleManager = new DefaultRoleManager();
+ final DefaultTypeManager roleManager = new DefaultTypeManager();
m_serviceManager.registerService( new String[] { RoleManager.ROLE,
RoleRegistry.ROLE
}, roleManager );
roleManager.addRole( new RoleInfo( "test-service", TestService.class
) );
1.9 +34 -43
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultTypeManagerTestCase.java
Index: DefaultTypeManagerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultTypeManagerTestCase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultTypeManagerTestCase.java 21 Jun 2002 08:05:35 -0000 1.8
+++ DefaultTypeManagerTestCase.java 30 Jun 2002 06:23:31 -0000 1.9
@@ -16,7 +16,6 @@
import org.apache.myrmidon.interfaces.type.TypeManager;
import org.apache.myrmidon.interfaces.type.TypeRegistry;
import org.apache.myrmidon.interfaces.role.RoleInfo;
-import org.apache.myrmidon.interfaces.role.RoleManager;
/**
* Test cases for the DefaultTypeManager
@@ -41,7 +40,8 @@
private static final Class TYPE_CLASS1 = TestType1.class;
private static final Class TYPE_CLASS2 = TestType2.class;
- private DefaultTypeManager m_typeManager;
+ private TypeManager m_typeManager;
+ private TypeRegistry m_typeRegistry;
public DefaultTypeManagerTestCase( String name )
{
@@ -52,10 +52,8 @@
{
super.setUp();
registerRole( new RoleInfo( TestRole.ROLE, TestRole.class ) );
-
- final RoleManager roleManager =
- (RoleManager)getServiceManager().lookup( RoleManager.ROLE );
- m_typeManager = new DefaultTypeManager( null, roleManager );
+ m_typeRegistry = (TypeRegistry)getServiceManager().lookup(
TypeRegistry.ROLE );
+ m_typeManager = (TypeManager)getServiceManager().lookup(
TypeManager.ROLE );
}
public void testRegister() throws Exception
@@ -64,7 +62,7 @@
assertCantCreate( m_typeManager, TEST_ROLE, TYPE_NAME1 );
// Register a type with no namespace
- registerType( m_typeManager, TEST_ROLE, null, TYPE_NAME1,
TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, null, TYPE_NAME1,
TYPE_CLASS1 );
// Lookup the type with the shortname
assertCreate( m_typeManager, TEST_ROLE, TYPE_NAME1, TYPE_CLASS1 );
@@ -79,7 +77,7 @@
assertCantCreate( m_typeManager, TEST_ROLE, qname );
// Register a type under a namespace
- registerType( m_typeManager, TEST_ROLE, TEST_NAMESPACE, TYPE_NAME1,
TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, TEST_NAMESPACE, TYPE_NAME1,
TYPE_CLASS1 );
// Lookup the type with the shortName and qname.
assertCreate( m_typeManager, TEST_ROLE, TYPE_NAME1, TYPE_CLASS1 );
@@ -113,13 +111,13 @@
// Register Type1 with no namespace,
// and try to look it up with a namespace - can't be found.
qname = makeQName( TEST_NAMESPACE, TYPE_NAME1 );
- registerType( m_typeManager, TEST_ROLE, null, TYPE_NAME1,
TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, null, TYPE_NAME1,
TYPE_CLASS1 );
assertCantCreate( m_typeManager, TEST_ROLE, qname );
// Register Type2 with a namespace,
// and try to look it up with a different namespace - cant' be found.
qname = makeQName( TEST_NAMESPACE, TYPE_NAME2 );
- registerType( m_typeManager, TEST_ROLE, "another-namespace",
TYPE_NAME2, TYPE_CLASS2 );
+ registerType( m_typeRegistry, TEST_ROLE, "another-namespace",
TYPE_NAME2, TYPE_CLASS2 );
assertCantCreate( m_typeManager, TEST_ROLE, qname );
}
@@ -129,8 +127,8 @@
final String ns2 = "ns2";
// Register Type1 and Type2 with same name under different
namespaces.
- registerType( m_typeManager, TEST_ROLE, ns1, TYPE_NAME1, TYPE_CLASS1
);
- registerType( m_typeManager, TEST_ROLE, ns2, TYPE_NAME1, TYPE_CLASS2
);
+ registerType( m_typeRegistry, TEST_ROLE, ns1, TYPE_NAME1,
TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, ns2, TYPE_NAME1,
TYPE_CLASS2 );
// Check that we can create using the qnames.
assertCreate( m_typeManager, TEST_ROLE, makeQName( ns1, TYPE_NAME1
), TYPE_CLASS1 );
@@ -144,9 +142,10 @@
public void testChildIndependence() throws Exception
{
- DefaultTypeManager parent = m_typeManager;
- DefaultTypeManager child1 = createChild( parent );
- DefaultTypeManager child2 = createChild( parent );
+ DefaultTypeManager child1 =
+ (DefaultTypeManager)m_typeManager.getChildTypeManager();
+ DefaultTypeManager child2 =
+ (DefaultTypeManager)m_typeManager.getChildTypeManager();
final String typeName = "test-type";
@@ -169,8 +168,8 @@
public void testInheritance() throws Exception
{
- DefaultTypeManager parent = m_typeManager;
- DefaultTypeManager child = createChild( parent );
+ final DefaultTypeManager child =
+ (DefaultTypeManager)m_typeManager.getChildTypeManager();
assertCantCreate( child, TEST_ROLE, TYPE_NAME1 );
assertCantCreate( child, TEST_ROLE, TYPE_NAME2 );
@@ -178,7 +177,7 @@
// Register name1 with parent -> type1 and
// check that the child inherits the type.
String typeName = TYPE_NAME1;
- registerType( parent, TEST_ROLE, null, typeName, TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, null, typeName, TYPE_CLASS1
);
assertCreate( child, TEST_ROLE, typeName, TYPE_CLASS1 );
// Now register name1 with child -> type2 and make sure
// that parent registration is overridden.
@@ -190,14 +189,14 @@
typeName = TYPE_NAME2;
registerType( child, TEST_ROLE, null, typeName, TYPE_CLASS1 );
assertCreate( child, TEST_ROLE, typeName, TYPE_CLASS1 );
- registerType( parent, TEST_ROLE, null, typeName, TYPE_CLASS2 );
+ registerType( m_typeRegistry, TEST_ROLE, null, typeName, TYPE_CLASS2
);
assertCreate( child, TEST_ROLE, typeName, TYPE_CLASS1 );
}
public void testInheritanceQName() throws Exception
{
- DefaultTypeManager parent = m_typeManager;
- DefaultTypeManager child = createChild( parent );
+ final DefaultTypeManager child =
+ (DefaultTypeManager)m_typeManager.getChildTypeManager();
assertCantCreate( child, TEST_ROLE, TYPE_NAME1 );
assertCantCreate( child, TEST_ROLE, TYPE_NAME2 );
@@ -206,7 +205,7 @@
// check that the child inherits the type.
String typeName = TYPE_NAME1;
String qname = makeQName( TEST_NAMESPACE, typeName );
- registerType( parent, TEST_ROLE, TEST_NAMESPACE, typeName,
TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, TEST_NAMESPACE, typeName,
TYPE_CLASS1 );
assertCreate( child, TEST_ROLE, qname, TYPE_CLASS1 );
// Now register name1 with child -> type2 and make sure
// that parent registration is overridden.
@@ -219,14 +218,14 @@
qname = makeQName( TEST_NAMESPACE, typeName );
registerType( child, TEST_ROLE, TEST_NAMESPACE, typeName,
TYPE_CLASS1 );
assertCreate( child, TEST_ROLE, qname, TYPE_CLASS1 );
- registerType( parent, TEST_ROLE, TEST_NAMESPACE, typeName,
TYPE_CLASS2 );
+ registerType( m_typeRegistry, TEST_ROLE, TEST_NAMESPACE, typeName,
TYPE_CLASS2 );
assertCreate( child, TEST_ROLE, qname, TYPE_CLASS1 );
}
public void testInheritanceNS() throws Exception
{
- DefaultTypeManager parent = m_typeManager;
- DefaultTypeManager child = createChild( parent );
+ final DefaultTypeManager child =
+ (DefaultTypeManager)m_typeManager.getChildTypeManager();
final String nsParent = "parent";
final String nsChild = "child";
@@ -240,7 +239,7 @@
// Register type1 with the parent, and make sure it's accessible
// in the child, both qualified and not.
- registerType( parent, TEST_ROLE, nsParent, typeName, TYPE_CLASS1 );
+ registerType( m_typeRegistry, TEST_ROLE, nsParent, typeName,
TYPE_CLASS1 );
assertCreate( child, TEST_ROLE, typeName, TYPE_CLASS1 );
assertCreate( child, TEST_ROLE, parentQName, TYPE_CLASS1 );
assertCantCreate( child, TEST_ROLE, childQName );
@@ -257,14 +256,15 @@
public void testDeepInheritance() throws Exception
{
- DefaultTypeManager grandparent = m_typeManager;
- DefaultTypeManager parent = createChild( grandparent);
- DefaultTypeManager child = createChild( parent);
+ final DefaultTypeManager parent =
+ (DefaultTypeManager)m_typeManager.getChildTypeManager();
+ final DefaultTypeManager child =
+ (DefaultTypeManager)parent.getChildTypeManager();
assertCantCreate( child, TEST_ROLE, TYPE_NAME1 );
// Register with grandparent, and check available.
- registerType( grandparent, TEST_ROLE, null, TYPE_NAME1, TYPE_CLASS1
);
+ registerType( m_typeRegistry, TEST_ROLE, null, TYPE_NAME1,
TYPE_CLASS1 );
assertCreate( child, TEST_ROLE, TYPE_NAME1, TYPE_CLASS1 );
// Register with parent, should override grandparent.
@@ -286,7 +286,7 @@
factory.addNameClassMapping( TYPE_NAME2, groupClass );
// Register the factory
- m_typeManager.registerTypes( TEST_ROLE, groupNs, factory );
+ m_typeRegistry.registerTypes( TEST_ROLE, groupNs, factory );
// Check that the types are available.
assertCreate( m_typeManager, TEST_ROLE, TYPE_NAME1, groupClass );
@@ -294,7 +294,7 @@
makeQName( groupNs, TYPE_NAME1), groupClass );
// Now register a single type over these registrations
- registerType( m_typeManager, TEST_ROLE, individualNs,
+ registerType( m_typeRegistry, TEST_ROLE, individualNs,
TYPE_NAME1, individualClass );
// With shortname only, should get individually registered type
(more specific)
@@ -312,7 +312,7 @@
// Test that ambiguity is OK between individual and library type
registrations
// (Individual wins)
// Register a type individually under the group Namespace.
- registerType( m_typeManager, TEST_ROLE, groupNs, TYPE_NAME2,
individualClass );
+ registerType( m_typeRegistry, TEST_ROLE, groupNs, TYPE_NAME2,
individualClass );
// This type should be available both FQ and shortname.
assertCreate( m_typeManager, TEST_ROLE, TYPE_NAME2, individualClass
);
assertCreate( m_typeManager, TEST_ROLE,
@@ -395,13 +395,4 @@
assertSameMessage( errorMessage, te );
}
}
-
- private DefaultTypeManager createChild( final DefaultTypeManager parent )
- throws Exception
- {
- final RoleManager roleManager =
- (RoleManager)getServiceManager().lookup( RoleManager.ROLE );
- return (DefaultTypeManager)parent.getChildTypeManager( roleManager );
- }
-
}
1.1
jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultRoleManagerTestCase.java
Index: DefaultRoleManagerTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.components.type.test;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractContainerTestCase;
import org.apache.myrmidon.components.type.DefaultTypeManager;
import org.apache.myrmidon.api.Task;
import org.apache.myrmidon.interfaces.role.RoleException;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.role.RoleManager;
/**
* Test cases for the DefaultRoleManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/06/30 06:23:31 $
*/
public class DefaultRoleManagerTestCase
extends AbstractContainerTestCase
{
private static final Resources REZ = getResourcesForTested(
DefaultRoleManagerTestCase.class );
private DefaultTypeManager m_roleManager;
public DefaultRoleManagerTestCase( String name )
{
super( name );
}
protected void setUp() throws Exception
{
super.setUp();
m_roleManager = new DefaultTypeManager();
}
/**
* Tests looking up a role by name, shorthand and type.
*/
public void testLookup() throws Exception
{
final String roleName = "role-name";
final Class roleType = Task.class;
final RoleInfo origRole = new RoleInfo( roleName, roleType );
m_roleManager.addRole( origRole );
// Lookup the role
RoleInfo role = m_roleManager.getRoleByShortName( roleName );
assertTrue( origRole.equals( role ) );
// Lookup the role by type
role = m_roleManager.getRoleByInterface( roleType.getName() );
assertTrue( origRole.equals( role ) );
// Lookup an unknown role
RoleInfo unknownRole = m_roleManager.getRoleByShortName( "unknown" );
assertNull( unknownRole );
// Lookup an unknown role
unknownRole = m_roleManager.getRoleByInterface( "unknown" );
assertNull( unknownRole );
}
/**
* Tests inheriting roles from parent role manager.
*/
public void testParent() throws Exception
{
final String roleName = "role-name";
final Class roleType = Task.class;
final RoleInfo origRole = new RoleInfo( roleName, roleType );
m_roleManager.addRole( origRole );
final RoleManager roleManager = new DefaultTypeManager( m_roleManager
);
// Lookup by name
RoleInfo roleInfo = roleManager.getRoleByShortName( roleName );
assertSame( origRole, roleInfo );
// Lookup by type
roleInfo = roleManager.getRoleByInterface( roleType.getName() );
assertSame( origRole, roleInfo );
}
/**
* Tests overriding a role in a child role manager.
*/
public void testOverrideName() throws Exception
{
final String roleName = "role-name";
final Class roleType = Task.class;
// Add original role
final RoleInfo origRole = new RoleInfo( roleName, roleType );
m_roleManager.addRole( origRole );
// Override role
final DefaultTypeManager roleManager = new DefaultTypeManager(
m_roleManager );
final RoleInfo overrideNameRole = new RoleInfo( roleName );
roleManager.addRole( overrideNameRole );
final RoleInfo overrideTypeRole = new RoleInfo( "another-role",
roleType );
roleManager.addRole( overrideTypeRole );
// Lookup role by name
RoleInfo roleInfo = roleManager.getRoleByShortName( roleName );
assertSame( overrideNameRole, roleInfo );
// Lookup role by type
roleInfo = roleManager.getRoleByInterface( roleType.getName() );
assertSame( overrideTypeRole, roleInfo );
}
/**
* Tests adding duplicate roles.
*/
public void testDuplicate() throws Exception
{
final String roleName = "role-name";
final Class roleType = Task.class;
final RoleInfo origRole = new RoleInfo( roleName, roleType );
m_roleManager.addRole( origRole );
// Duplicate role name
try
{
m_roleManager.addRole( new RoleInfo( roleName ) );
fail();
}
catch( RoleException exc )
{
final String message = REZ.getString( "duplicate-role.error",
roleName );
assertSameMessage( message, exc );
}
// Duplicate implementation class
try
{
m_roleManager.addRole( new RoleInfo( null, roleType ) );
fail();
}
catch( RoleException exc )
{
final String message = REZ.getString( "duplicate-type.error",
roleType.getName() );
assertSameMessage( message, exc );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>