adammurdoch 2002/06/24 00:03:49
Modified: container/src/java/org/apache/myrmidon/components/deployer
DefaultDeployer.java
DefaultTypeLibraryDeployer.java
DescriptorBuilder.java RoleDescriptorBuilder.java
TypeDescriptorBuilder.java
Removed: container/src/java/org/apache/myrmidon/components/deployer
RoleDescriptor.java TypeDescriptor.java
TypelibDescriptor.java
Log:
Clean-up the Deployer internals.
Revision Changes Path
1.51 +87 -13
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
Index: DefaultDeployer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- DefaultDeployer.java 24 Jun 2002 01:50:01 -0000 1.50
+++ DefaultDeployer.java 24 Jun 2002 07:03:48 -0000 1.51
@@ -22,6 +22,8 @@
import org.apache.myrmidon.interfaces.library.Library;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.role.RoleRegistry;
+import org.apache.myrmidon.interfaces.role.RoleInfo;
+import java.util.Arrays;
/**
* This class deploys roles, types and services from a typelib.
@@ -61,22 +63,35 @@
}
/**
- * Returns the deployer for a library, creating the deployer if
- * necessary.
+ * Creates a deployer for a library.
*/
private DefaultTypeLibraryDeployer createDeployer( final Library library
)
throws DeploymentException
{
try
{
- final DefaultTypeLibraryDeployer deployment =
- new DefaultTypeLibraryDeployer( m_roleRegistry,
- m_typeDeployer,
- library.getClassLoader() );
- ContainerUtil.enableLogging( deployment, getLogger() );
- deployment.loadDescriptors( library.getClassPath() );
+ final DefaultTypeLibraryDeployer deployer =
+ new DefaultTypeLibraryDeployer( library.getClassLoader() );
+ ContainerUtil.enableLogging( deployer, getLogger() );
+ deployer.loadDescriptors( library.getClassPath() );
+
+ // Deploy the roles
+ // TODO - need to defer this
+
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ REZ.getString( "url-deploy-roles.notice", Arrays.asList(
library.getClassPath() ) );
+ getLogger().debug( message );
+ }
+
+ final RoleInfo[] roles = deployer.getRoles();
+ for( int i = 0; i < roles.length; i++ )
+ {
+ deployRole( roles[ i ] );
+ }
- return deployment;
+ return deployer;
}
catch( final Exception e )
{
@@ -94,7 +109,19 @@
throws DeploymentException
{
final DefaultTypeLibraryDeployer deployer = createDeployer( library
);
- deployer.deployAll( namespace, context );
+
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ REZ.getString( "url-deploy-types.notice", Arrays.asList(
library.getClassPath() ) );
+ getLogger().debug( message );
+ }
+
+ final TypeDefinition[] types = deployer.getTypes();
+ for( int i = 0; i < types.length; i++ )
+ {
+ deployType( namespace, types[ i ], context );
+ }
}
/**
@@ -103,13 +130,35 @@
*/
public void deployType( final Library library,
final String namespace,
- final String role,
+ final String roleName,
final String typeName,
final TaskContext context )
throws DeploymentException
{
final DefaultTypeLibraryDeployer deployer = createDeployer( library
);
- deployer.deployType( namespace, role, typeName, context );
+ final TypeDefinition[] types = deployer.getTypes();
+ try
+ {
+ // Locate the definition for the type
+ for( int i = 0; i < types.length; i++ )
+ {
+ final TypeDefinition typedef = types[ i ];
+ if( typedef.getRole().equals( roleName )
+ && typedef.getName().equals( typeName ) )
+ {
+ // Found the definition - deploy it. Note that we
+ // keep looking for matching types, and let the type
+ // manager deal with duplicates
+ deployType( namespace, typedef, context );
+ }
+ }
+ }
+ catch( final Exception e )
+ {
+ final String message = REZ.getString( "deploy-type.error",
roleName, typeName );
+ throw new DeploymentException( message, e );
+ }
+
}
/**
@@ -123,12 +172,37 @@
try
{
m_typeDeployer.deployType( namespace, typeDef, context );
+
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ REZ.getString( "register-type.notice",
typeDef.getRole(), typeDef.getName() );
+ getLogger().debug( message );
+ }
}
catch( Exception e )
{
final String message = REZ.getString( "deploy-type.error",
typeDef.getRole(),
typeDef.getName() );
throw new DeploymentException( message, e );
+ }
+ }
+
+ /**
+ * Deploys a role.
+ */
+ private void deployRole( final RoleInfo roleInfo )
+ throws Exception
+ {
+ m_roleRegistry.addRole( roleInfo );
+
+ if( getLogger().isDebugEnabled() )
+ {
+ final String debugMessage =
+ REZ.getString( "register-role.notice",
+ roleInfo.getShortName(),
+ roleInfo.getImplementationClass().getName() );
+ getLogger().debug( debugMessage );
}
}
}
1.14 +30 -191
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultTypeLibraryDeployer.java
Index: DefaultTypeLibraryDeployer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultTypeLibraryDeployer.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultTypeLibraryDeployer.java 24 Jun 2002 01:50:01 -0000 1.13
+++ DefaultTypeLibraryDeployer.java 24 Jun 2002 07:03:48 -0000 1.14
@@ -14,17 +14,11 @@
import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.apache.avalon.excalibur.i18n.ResourceManager;
-import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.myrmidon.interfaces.deployer.DeploymentException;
+import org.apache.myrmidon.interfaces.type.ClassLoaderTypeFactory;
import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
-import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
import org.apache.myrmidon.interfaces.role.RoleInfo;
-import org.apache.myrmidon.interfaces.role.RoleRegistry;
-import org.apache.myrmidon.interfaces.type.ClassLoaderTypeFactory;
-import org.apache.myrmidon.api.TaskContext;
import org.xml.sax.XMLReader;
/**
@@ -39,15 +33,12 @@
class DefaultTypeLibraryDeployer
extends AbstractLogEnabled
{
- private static final Resources REZ =
- ResourceManager.getPackageResources(
DefaultTypeLibraryDeployer.class );
-
private static final String TYPE_DESCRIPTOR_NAME =
"META-INF/ant-types.xml";
private static final String ROLE_DESCRIPTOR_NAME =
"META-INF/ant-roles.xml";
- private final TypeDeployer m_typeDeployer;
private final ClassLoader m_classLoader;
- private TypeDescriptor[] m_descriptors;
+ private TypeDefinition[] m_types;
+ private RoleInfo[] m_roles;
// TODO - create and configure these in DefaultDeployer
private DescriptorBuilder m_roleBuilder = new RoleDescriptorBuilder();
@@ -55,20 +46,14 @@
/** Map from role name -> DefaultTypeFactory for that role. */
private Map m_factories = new HashMap();
- private final RoleRegistry m_roleRegistry;
- public DefaultTypeLibraryDeployer( final RoleRegistry roleRegistry,
- final TypeDeployer typeDeployer,
- final ClassLoader classLoader )
+ public DefaultTypeLibraryDeployer( final ClassLoader classLoader )
{
- m_roleRegistry = roleRegistry;
- m_typeDeployer = typeDeployer;
m_classLoader = classLoader;
}
/**
- * Load the descriptors. Deploys all roles, then loads the descriptors
- * for, but does not deploy, all the types.
+ * Loads the descriptors.
*
* @param searchPath The files containing the descriptors.
*/
@@ -88,24 +73,29 @@
// Build the role descriptors
final ArrayList roleUrls = locateResources( ROLE_DESCRIPTOR_NAME,
searchPath );
- final ArrayList roleDescriptors =
- buildDescriptors( roleUrls, m_roleBuilder, parser, handler );
-
- // Deploy the roles
- // TODO - need to defer this
- final int roleCount = roleDescriptors.size();
- for( int i = 0; i < roleCount; i++ )
- {
- final RoleDescriptor descriptor =
(RoleDescriptor)roleDescriptors.get( i );
- deployRoles( descriptor );
- }
+ final ArrayList roles = buildDefinitions( roleUrls, m_roleBuilder,
parser, handler );
+ m_roles = (RoleInfo[])roles.toArray( new RoleInfo[ roles.size() ] );
// Build the type descriptors
final ArrayList typeUrls = locateResources( TYPE_DESCRIPTOR_NAME,
searchPath );
- final ArrayList typeDescriptors =
- buildDescriptors( typeUrls, m_typeBuilder, parser, handler );
- m_descriptors = (TypeDescriptor[])typeDescriptors.toArray
- ( new TypeDescriptor[ typeDescriptors.size() ] );
+ final ArrayList types = buildDefinitions( typeUrls, m_typeBuilder,
parser, handler );
+ m_types = (TypeDefinition[])types.toArray( new TypeDefinition[
types.size() ] );
+ }
+
+ /**
+ * Returns the role descriptors for this library.
+ */
+ public RoleInfo[] getRoles()
+ {
+ return m_roles;
+ }
+
+ /**
+ * Returns the type descriptors for this library.
+ */
+ public TypeDefinition[] getTypes()
+ {
+ return m_types;
}
/**
@@ -133,84 +123,15 @@
}
/**
- * Deploys everything in the type library.
- */
- public void deployAll( final String namespace, final TaskContext context
)
- throws DeploymentException
- {
- // Deploy types
- for( int i = 0; i < m_descriptors.length; i++ )
- {
- TypeDescriptor descriptor = m_descriptors[ i ];
- deployTypes( namespace, descriptor, context );
- }
- }
-
- /**
- * Deploys a single type in the type library.
- */
- public void deployType( final String namespace,
- final String roleName,
- final String typeName,
- final TaskContext context )
- throws DeploymentException
- {
- try
- {
- // Locate the definition for the type
- for( int i = 0; i < m_descriptors.length; i++ )
- {
- final TypeDescriptor descriptor = m_descriptors[ i ];
- final TypeDefinition[] definitions =
descriptor.getDefinitions();
- for( int j = 0; j < definitions.length; j++ )
- {
- TypeDefinition definition = definitions[ j ];
- if( definition.getRole().equals( roleName )
- && definition.getName().equals( typeName ) )
- {
- // Found the definition - deploy it. Note that we
- // keep looking for matching types, and let the
deployer
- // deal with duplicates
- doDeployType( namespace, definition, context );
- }
- }
- }
- }
- catch( Exception e )
- {
- final String message = REZ.getString( "deploy-type.error",
roleName, typeName );
- throw new DeploymentException( message, e );
- }
- }
-
- /**
- * Deploys a type.
- */
- private void doDeployType( final String namespace,
- final TypeDefinition typeDef,
- final TaskContext context )
- throws Exception
- {
- m_typeDeployer.deployType( namespace, typeDef, context );
-
- if( getLogger().isDebugEnabled() )
- {
- final String message =
- REZ.getString( "register-type.notice", typeDef.getRole(),
typeDef.getName() );
- getLogger().debug( message );
- }
- }
-
- /**
* Builds descriptors.
*/
- private ArrayList buildDescriptors( final ArrayList urls,
+ private ArrayList buildDefinitions( final ArrayList urls,
final DescriptorBuilder builder,
final XMLReader parser,
final SAXConfigurationHandler
handler )
throws Exception
{
- final ArrayList descriptors = new ArrayList();
+ final ArrayList definitions = new ArrayList();
final int size = urls.size();
for( int i = 0; i < size; i++ )
{
@@ -218,12 +139,10 @@
// Parse the file
parser.parse( url );
- final TypelibDescriptor descriptor =
- builder.createDescriptor( handler.getConfiguration(), url,
this );
- descriptors.add( descriptor );
+ builder.parseDescriptor( handler.getConfiguration(), url, this,
definitions );
}
- return descriptors;
+ return definitions;
}
/**
@@ -263,85 +182,5 @@
}
}
return resourceUrls;
- }
-
- /**
- * Deploys the roles from a role descriptor.
- */
- private void deployRoles( final RoleDescriptor descriptor )
- throws DeploymentException
- {
- try
- {
- if( getLogger().isDebugEnabled() )
- {
- final String message =
- REZ.getString( "url-deploy-roles.notice",
descriptor.getUrl() );
- getLogger().debug( message );
- }
-
- final RoleInfo[] definitions = descriptor.getDefinitions();
- for( int i = 0; i < definitions.length; i++ )
- {
- final RoleInfo roleInfo = definitions[ i ];
- deployRole( roleInfo );
- }
- }
- catch( final Exception e )
- {
- final String message = REZ.getString( "deploy-roles.error",
descriptor.getUrl() );
- throw new DeploymentException( message, e );
- }
- }
-
- /**
- * Deploys a role.
- */
- private void deployRole( final RoleInfo roleInfo )
- throws Exception
- {
- m_roleRegistry.addRole( roleInfo );
-
- if( getLogger().isDebugEnabled() )
- {
- final String debugMessage =
- REZ.getString( "register-role.notice",
- roleInfo.getShortName(),
- roleInfo.getImplementationClass().getName() );
- getLogger().debug( debugMessage );
- }
- }
-
- /**
- * Deploys all types from a typelib descriptor.
- */
- private void deployTypes( final String namespace,
- final TypeDescriptor descriptor,
- final TaskContext context )
- throws DeploymentException
- {
- try
- {
- if( getLogger().isDebugEnabled() )
- {
- final String message =
- REZ.getString( "url-deploy-types.notice",
descriptor.getUrl() );
- getLogger().debug( message );
- }
-
- // Deploy all the types
- final TypeDefinition[] definitions = descriptor.getDefinitions();
- for( int i = 0; i < definitions.length; i++ )
- {
- final TypeDefinition definition = definitions[ i ];
- doDeployType( namespace, definition, context );
- }
- }
- catch( final Exception e )
- {
- e.printStackTrace();
- final String message = REZ.getString( "deploy-types.error",
descriptor.getUrl() );
- throw new DeploymentException( message, e );
- }
}
}
1.4 +6 -4
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DescriptorBuilder.java
Index: DescriptorBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DescriptorBuilder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DescriptorBuilder.java 22 May 2002 07:36:22 -0000 1.3
+++ DescriptorBuilder.java 24 Jun 2002 07:03:49 -0000 1.4
@@ -9,6 +9,7 @@
import org.apache.myrmidon.interfaces.deployer.DeploymentException;
import org.apache.avalon.framework.configuration.Configuration;
+import java.util.List;
/**
* Builds a descriptor.
@@ -21,8 +22,9 @@
/**
* Builds a descriptor from a set of configuration.
*/
- TypelibDescriptor createDescriptor( Configuration model,
- String descriptorUrl,
- DefaultTypeLibraryDeployer deployer )
+ void parseDescriptor( Configuration model,
+ String descriptorUrl,
+ DefaultTypeLibraryDeployer deployer,
+ List definitions )
throws DeploymentException;
}
1.11 +7 -10
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/RoleDescriptorBuilder.java
Index: RoleDescriptorBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/RoleDescriptorBuilder.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RoleDescriptorBuilder.java 23 Jun 2002 08:06:39 -0000 1.10
+++ RoleDescriptorBuilder.java 24 Jun 2002 07:03:49 -0000 1.11
@@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.List;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.Version;
@@ -33,9 +34,10 @@
/**
* Builds a descriptor from a set of configuration.
*/
- public TypelibDescriptor createDescriptor( final Configuration model,
- final String url,
- final
DefaultTypeLibraryDeployer deployer )
+ public void parseDescriptor( final Configuration model,
+ final String url,
+ final DefaultTypeLibraryDeployer deployer,
+ final List definitions )
throws DeploymentException
{
try
@@ -50,9 +52,6 @@
throw new DeploymentException( message );
}
- // Assemble the descriptor
- final RoleDescriptor descriptor = new RoleDescriptor( url );
-
// Extract each of the role elements
final Configuration[] types = model.getChildren( "role" );
for( int i = 0; i < types.length; i++ )
@@ -72,10 +71,8 @@
attrMap.remove( "interface" );
final RoleInfo roleInfo = new RoleInfo( shortName, roleType,
attrMap );
- descriptor.addDefinition( roleInfo );
+ definitions.add( roleInfo );
}
-
- return descriptor;
}
catch( final Exception e )
{
1.10 +12 -22
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/TypeDescriptorBuilder.java
Index: TypeDescriptorBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/TypeDescriptorBuilder.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TypeDescriptorBuilder.java 23 Jun 2002 08:06:39 -0000 1.9
+++ TypeDescriptorBuilder.java 24 Jun 2002 07:03:49 -0000 1.10
@@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.List;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.Version;
@@ -35,9 +36,10 @@
/**
* Builds a descriptor from a set of configuration.
*/
- public TypelibDescriptor createDescriptor( final Configuration model,
- final String url,
- final
DefaultTypeLibraryDeployer deployer )
+ public void parseDescriptor( final Configuration model,
+ final String url,
+ final DefaultTypeLibraryDeployer deployer,
+ final List definitions )
throws DeploymentException
{
try
@@ -53,32 +55,20 @@
throw new DeploymentException( message );
}
- // Assemble the descriptor
- final TypeDescriptor descriptor = new TypeDescriptor( url );
-
// Extract each of the types elements
final Configuration[] children = model.getChildren( "types" );
- if( 0 == children.length )
- {
- return descriptor;
- }
- else if( 1 != children.length )
+ if( 1 != children.length )
{
final String message =
REZ.getString( "multi-types-element.error", url );
throw new DeploymentException( message );
}
- else
+ final Configuration[] typeEntries = children[ 0 ].getChildren();
+ for( int i = 0; i < typeEntries.length; i++ )
{
- final Configuration[] typeEntries = children[ 0
].getChildren();
- for( int i = 0; i < typeEntries.length; i++ )
- {
- final Configuration typeEntry = typeEntries[ i ];
- final TypeDefinition typeDef = createTypeDefinition(
typeEntry, deployer );
- descriptor.addDefinition( typeDef );
- }
-
- return descriptor;
+ final Configuration typeEntry = typeEntries[ i ];
+ final TypeDefinition typeDef = createTypeDefinition(
typeEntry, deployer );
+ definitions.add( typeDef );
}
}
catch( Exception e )
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>