donaldp 2002/11/11 16:12:22
Modified: info/src/java/org/apache/avalon/framework/tools/infobuilder
InfoBuilder.java
Added: info/src/java/org/apache/avalon/framework/tools/infobuilder
InfoReader.java LegacyBlockInfoReader.java
SerializedInfoReader.java XMLInfoReader.java
Removed: info/src/java/org/apache/avalon/framework/tools/infobuilder
InfoCreator.java LegacyBlockInfoCreator.java
SerializedInfoCreator.java XMLInfoCreator.java
Log:
Rename InfoCreator to InfoReader
Revision Changes Path
1.3 +16 -16
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/InfoBuilder.java
Index: InfoBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/InfoBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InfoBuilder.java 4 Oct 2002 05:54:02 -0000 1.2
+++ InfoBuilder.java 12 Nov 2002 00:12:22 -0000 1.3
@@ -30,9 +30,9 @@
private static final Resources REZ =
ResourceManager.getPackageResources( InfoBuilder.class );
- private final InfoCreator m_xmlInfoCreator = createXMLInfoCreator();
- private final InfoCreator m_serialInfoCreator = new SerializedInfoCreator();
- private final InfoCreator m_legacyInfoCreator = createLegacyInfoCreator();
+ private final InfoReader m_xmlInfoCreator = createXMLInfoCreator();
+ private final InfoReader m_serialInfoCreator = new SerializedInfoReader();
+ private final InfoReader m_legacyInfoCreator = createLegacyInfoCreator();
/**
* Setup logging for all subcomponents
@@ -210,7 +210,7 @@
throw new Exception( message );
}
- final InfoCreator xmlInfoCreator = getXMLInfoCreator( classname );
+ final InfoReader xmlInfoCreator = getXMLInfoCreator( classname );
return xmlInfoCreator.createComponentInfo( classname, inputStream );
}
@@ -287,7 +287,7 @@
throw new Exception( message );
}
- final InfoCreator xmlInfoCreator = getXMLInfoCreator( classname );
+ final InfoReader xmlInfoCreator = getXMLInfoCreator( classname );
return xmlInfoCreator.createServiceInfo( classname, inputStream );
}
@@ -295,9 +295,9 @@
* Utility to get xml info builder, else throw
* an exception if missing descriptor.
*
- * @return the InfoCreator
+ * @return the InfoReader
*/
- private InfoCreator getXMLInfoCreator( final String classname )
+ private InfoReader getXMLInfoCreator( final String classname )
throws Exception
{
if( null != m_xmlInfoCreator )
@@ -314,16 +314,16 @@
}
/**
- * Utility to get {@link XMLInfoCreator} if XML files are on
+ * Utility to get {@link XMLInfoReader} if XML files are on
* ClassPath.
*
- * @return the XML {@link InfoCreator}
+ * @return the XML {@link InfoReader}
*/
- private static InfoCreator createXMLInfoCreator()
+ private static InfoReader createXMLInfoCreator()
{
try
{
- return new XMLInfoCreator();
+ return new XMLInfoReader();
}
catch( final Exception e )
{
@@ -334,16 +334,16 @@
}
/**
- * Utility to get {@link LegacyBlockInfoCreator} if XML files are on
+ * Utility to get {@link LegacyBlockInfoReader} if XML files are on
* ClassPath.
*
- * @return the Legacy {@link InfoCreator}
+ * @return the Legacy {@link InfoReader}
*/
- private static InfoCreator createLegacyInfoCreator()
+ private static InfoReader createLegacyInfoCreator()
{
try
{
- return new LegacyBlockInfoCreator();
+ return new LegacyBlockInfoReader();
}
catch( final Exception e )
{
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/InfoReader.java
Index: InfoReader.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.avalon.framework.tools.infobuilder;
import java.io.InputStream;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ServiceInfo;
/**
* Simple interface used to create {@link ComponentInfo}
* or {@link ServiceInfo} objects from a stream. This
* abstraction was primarily created so that the Info objesct
* could be built from non-XML sources and no XML classes need
* be in the classpath.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 00:12:22 $
*/
public interface InfoReader
{
/**
* Create a {@link ComponentInfo} from stream
*
* @param implementationKey the name of component type that we are looking up
* @param inputStream the stream that the resource is loaded from
* @return the newly created {@link ComponentInfo}
* @throws Exception if unable to create info
*/
ComponentInfo createComponentInfo( String implementationKey,
InputStream inputStream )
throws Exception;
/**
* Create a {@link ServiceInfo} from stream
*
* @param implementationKey the name of service type that we are looking up
* @param inputStream the stream that the resource is loaded from
* @return the newly created {@link ServiceInfo}
* @throws Exception if unable to create info
*/
ServiceInfo createServiceInfo( String implementationKey,
InputStream inputStream )
throws Exception;
}
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoReader.java
Index: LegacyBlockInfoReader.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.avalon.framework.tools.infobuilder;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.info.Attribute;
import org.apache.avalon.framework.info.ComponentDescriptor;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ContextDescriptor;
import org.apache.avalon.framework.info.DependencyDescriptor;
import org.apache.avalon.framework.info.EntryDescriptor;
import org.apache.avalon.framework.info.LoggerDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
import org.apache.avalon.framework.info.ServiceInfo;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.xml.sax.InputSource;
/**
* A LegacyBlockInfoReader is responsible for building {@link ComponentInfo}
* objects from <a href="http://jakarta.apache.org/avalon/phoenix">Phoenixs</a>
* BlockInfo descriptors. The format for descriptor is specified in the
* <a href="package-summary.html#external">package summary</a>.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 00:12:22 $
*/
public final class LegacyBlockInfoReader
extends AbstractLogEnabled
implements InfoReader
{
private static final Resources REZ =
ResourceManager.getPackageResources( LegacyBlockInfoReader.class );
/**
* Create a {@link ComponentInfo} object for specified
* classname, loaded from specified {@link InputStream}.
*
* @param implementationKey The classname of Component
* @param inputStream the InputStream to load ComponentInfo from
* @return the created ComponentInfo
* @throws ConfigurationException if an error occurs
*/
public ComponentInfo createComponentInfo( final String implementationKey,
final InputStream inputStream )
throws Exception
{
final InputSource input = new InputSource( inputStream );
final Configuration configuration = ConfigurationBuilder.build( input );
return build( implementationKey, configuration );
}
/**
* Create a {@link ServiceInfo} from stream
*
* @param implementationKey the name of service type that we are looking up
* @param inputStream the stream that the resource is loaded from
* @return the newly created {@link ServiceInfo}
* @throws Exception if unable to create info
* @todo Implement me!
*/
public ServiceInfo createServiceInfo( final String implementationKey,
final InputStream inputStream )
throws Exception
{
final String message =
"Currently unsupported. Should process mxinfo files here...";
throw new Exception( message );
}
/**
* Create a {@link ComponentInfo} object for specified classname from
* specified configuration data.
*
* @param classname The classname of Component
* @param info the ComponentInfo configuration
* @return the created ComponentInfo
* @throws ConfigurationException if an error occurs
*/
private ComponentInfo build( final String classname,
final Configuration info )
throws Exception
{
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "builder.creating-info.notice",
classname );
getLogger().debug( message );
}
final String topLevelName = info.getName();
if( !topLevelName.equals( "blockinfo" ) )
{
final String message =
REZ.getString( "legacy.bad-toplevel-element.error",
classname,
topLevelName );
throw new ConfigurationException( message );
}
Configuration configuration = null;
configuration = info.getChild( "block" );
final ComponentDescriptor descriptor =
buildComponentDescriptor( classname, configuration );
final String implementationKey = descriptor.getImplementationKey();
final ServiceDescriptor[] services = buildServices( info );
configuration = info.getChild( "dependencies" );
final DependencyDescriptor[] dependencies =
buildDependencies( implementationKey, configuration );
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "legacy.created-info.notice",
classname,
new Integer( services.length ),
new Integer( dependencies.length ) );
getLogger().debug( message );
}
return new ComponentInfo( descriptor,
new LoggerDescriptor[ 0 ],
buildPhoenixContext(),
services,
dependencies );
}
/**
* A utility method to build a descriptor for Phoenixs BlockContext
* object,
*
* @return the a descriptor for Phoenixs BlockContext object,
*/
private ContextDescriptor buildPhoenixContext()
{
return new ContextDescriptor( "org.apache.avalon.phoenix.BlockContext",
new EntryDescriptor[ 0 ],
new Attribute[ 0 ] );
}
/**
* A utility method to build an array of {@link DependencyDescriptor}
* objects from specified configuration and classname.
*
* @param classname The classname of Component (used for logging purposes)
* @param configuration the dependencies configuration
* @return the created DependencyDescriptor
* @throws ConfigurationException if an error occurs
*/
private DependencyDescriptor[] buildDependencies( final String classname,
final Configuration
configuration )
throws ConfigurationException
{
final Configuration[] elements = configuration.getChildren( "dependency" );
final ArrayList dependencies = new ArrayList();
for( int i = 0; i < elements.length; i++ )
{
final DependencyDescriptor dependency =
buildDependency( classname, elements[ i ] );
dependencies.add( dependency );
}
return (DependencyDescriptor[])dependencies.toArray( new
DependencyDescriptor[ 0 ] );
}
/**
* A utility method to build a {@link DependencyDescriptor}
* object from specified configuraiton.
*
* @param classname The classname of Component (used for logging purposes)
* @param dependency the dependency configuration
* @return the created DependencyDescriptor
* @throws ConfigurationException if an error occurs
*/
private DependencyDescriptor buildDependency( final String classname,
final Configuration dependency )
throws ConfigurationException
{
final String implementationKey =
dependency.getChild( "service" ).getAttribute( "name" );
String key = dependency.getChild( "role" ).getValue( null );
//default to name of service if key unspecified
if( null == key )
{
key = implementationKey;
}
else
{
//If key is specified and it is the same as
//service name then warn that it is redundent.
if( key.equals( implementationKey ) )
{
final String message =
REZ.getString( "builder.redundent-key.notice",
classname,
key );
getLogger().warn( message );
}
}
return new DependencyDescriptor( key,
implementationKey,
false,
new Attribute[ 0 ] );
}
/**
* A utility method to build an array of {@link ServiceDescriptor}
* objects from specified configuraiton.
*
* @param info the services configuration
* @return the created ServiceDescriptor
* @throws ConfigurationException if an error occurs
*/
private ServiceDescriptor[] buildServices( final Configuration info )
throws ConfigurationException
{
final ArrayList services = new ArrayList();
Configuration[] elements = info.getChild( "services" ).getChildren(
"service" );
for( int i = 0; i < elements.length; i++ )
{
final ServiceDescriptor service = buildService( elements[ i ], false );
services.add( service );
}
elements = info.getChild( "management-access-points" ).getChildren(
"service" );
for( int i = 0; i < elements.length; i++ )
{
final ServiceDescriptor service = buildService( elements[ i ], true );
services.add( service );
}
return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[ 0 ] );
}
/**
* A utility method to build a {@link ServiceDescriptor}
* object from specified configuraiton data.
*
* @param service the service Configuration
* @return the created ServiceDescriptor
* @throws ConfigurationException if an error occurs
*/
private ServiceDescriptor buildService( final Configuration service,
final boolean isManagement )
throws ConfigurationException
{
final String implementationKey = service.getAttribute( "name" );
final String version = service.getAttribute( "version", null );
final ArrayList attributeSet = new ArrayList();
if( null != version )
{
final Attribute attribute =
createSimpleAttribute( "avalon", "version", version );
attributeSet.add( attribute );
}
if( isManagement )
{
final Attribute mxAttribute =
createSimpleAttribute( "phoenix", "mx", "true" );
attributeSet.add( mxAttribute );
}
final Attribute[] attributes = (Attribute[])attributeSet.toArray( new
Attribute[ attributeSet.size() ] );
return new ServiceDescriptor( implementationKey, attributes );
}
/**
* A utility method to build a {@link ComponentDescriptor}
* object from specified configuraiton data and classname.
*
* @param config the Component Configuration
* @return the created ComponentDescriptor
* @throws ConfigurationException if an error occurs
*/
private ComponentDescriptor buildComponentDescriptor( final String classname,
final Configuration config
)
throws ConfigurationException
{
final String version = config.getChild( "version" ).getValue();
final String schemaType = config.getChild( "schema-type" ).getValue( null );
final ArrayList attributeSet = new ArrayList();
final Attribute attribute = createSimpleAttribute( "avalon", "version",
version );
attributeSet.add( attribute );
if( null != schemaType )
{
final Attribute schemaAttribute =
createSimpleAttribute( "phoenix", "schema-type", schemaType );
attributeSet.add( schemaAttribute );
}
final Attribute[] attributes = (Attribute[])attributeSet.toArray( new
Attribute[ attributeSet.size() ] );
return new ComponentDescriptor( classname, attributes );
}
/**
* Helper method to create simple attributes with one parameter.
*
* @param name the name of the parameter
* @param value the value of the parameter
* @param attributeName the name of the attribute
* @return
*/
private Attribute createSimpleAttribute( final String attributeName,
final String name,
final String value )
{
final Properties parameters = new Properties();
parameters.setProperty( name, value );
return new Attribute( attributeName, parameters );
}
}
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/SerializedInfoReader.java
Index: SerializedInfoReader.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.avalon.framework.tools.infobuilder;
import java.io.InputStream;
import java.io.ObjectInputStream;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ServiceInfo;
/**
* Create {@link ComponentInfo} and {@link ServiceInfo} objects
* from stream made up of serialized object.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 00:12:22 $
*/
public class SerializedInfoReader
implements InfoReader
{
public ComponentInfo createComponentInfo( final String implementationKey,
final InputStream inputStream )
throws Exception
{
final ObjectInputStream ois = new ObjectInputStream( inputStream );
return (ComponentInfo)ois.readObject();
}
public ServiceInfo createServiceInfo( String implementationKey,
InputStream inputStream )
throws Exception
{
final ObjectInputStream ois = new ObjectInputStream( inputStream );
return (ServiceInfo)ois.readObject();
}
}
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoReader.java
Index: XMLInfoReader.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.avalon.framework.tools.infobuilder;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
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.info.Attribute;
import org.apache.avalon.framework.info.ComponentDescriptor;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ContextDescriptor;
import org.apache.avalon.framework.info.DependencyDescriptor;
import org.apache.avalon.framework.info.EntryDescriptor;
import org.apache.avalon.framework.info.LoggerDescriptor;
import org.apache.avalon.framework.info.MethodDescriptor;
import org.apache.avalon.framework.info.ParameterDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
import org.apache.avalon.framework.info.ServiceInfo;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.xml.sax.InputSource;
/**
* A XMLInfoReader is responsible for building {@link ComponentInfo}
* objects from Configuration objects. The format for Configuration object
* is specified in the <a href="package-summary.html#external">package summary</a>.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 00:12:22 $
*/
public final class XMLInfoReader
extends AbstractLogEnabled
implements InfoReader
{
private static final Resources REZ =
ResourceManager.getPackageResources( XMLInfoReader.class );
/**
* Create a {@link ComponentInfo} object for specified
* classname, loaded from specified {@link InputStream}.
*
* @param implementationKey The classname of Component
* @param inputStream the InputStream to load ComponentInfo from
* @return the created ComponentInfo
* @throws ConfigurationException if an error occurs
*/
public ComponentInfo createComponentInfo( final String implementationKey,
final InputStream inputStream )
throws Exception
{
final InputSource input = new InputSource( inputStream );
final Configuration configuration = ConfigurationBuilder.build( input );
return buildComponentInfo( implementationKey, configuration );
}
/**
* Create a {@link ServiceInfo} from stream
*
* @param implementationKey the name of service type that we are looking up
* @param inputStream the stream that the resource is loaded from
* @return the newly created {@link ServiceInfo}
* @throws Exception if unable to create info
*/
public ServiceInfo createServiceInfo( String implementationKey,
InputStream inputStream )
throws Exception
{
final InputSource input = new InputSource( inputStream );
final Configuration configuration = ConfigurationBuilder.build( input );
return buildServiceInfo( implementationKey, configuration );
}
/**
* Create a {@link ComponentInfo} object for specified classname from
* specified configuration data.
*
* @param classname The classname of Component
* @param info the ComponentInfo configuration
* @return the created ComponentInfo
* @throws ConfigurationException if an error occurs
*/
private ComponentInfo buildComponentInfo( final String classname,
final Configuration info )
throws Exception
{
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "builder.creating-info.notice",
classname );
getLogger().debug( message );
}
final String topLevelName = info.getName();
if( !topLevelName.equals( "component-info" ) )
{
final String message =
REZ.getString( "builder.bad-toplevel-element.error",
classname,
topLevelName );
throw new ConfigurationException( message );
}
Configuration configuration = null;
configuration = info.getChild( "component" );
final ComponentDescriptor descriptor = buildComponentDescriptor(
configuration );
final String implementationKey = descriptor.getImplementationKey();
configuration = info.getChild( "loggers" );
final LoggerDescriptor[] loggers = buildLoggers( configuration );
configuration = info.getChild( "context" );
final ContextDescriptor context = buildContext( configuration );
configuration = info.getChild( "services" );
final ServiceDescriptor[] services = buildServices( configuration );
configuration = info.getChild( "dependencies" );
final DependencyDescriptor[] dependencies =
buildDependencies( implementationKey, configuration );
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "builder.created-info.notice",
implementationKey,
new Integer( services.length ),
new Integer( dependencies.length ),
new Integer( context.getEntrys().length ),
new Integer( loggers.length ) );
getLogger().debug( message );
}
return new ComponentInfo( descriptor, loggers, context, services,
dependencies );
}
/**
* Create a {@link ServiceInfo} object for specified classname from
* specified configuration data.
*
* @param classname The classname of Service
* @param info the ServiceInfo configuration
* @return the created ServiceInfo
* @throws ConfigurationException if an error occurs
*/
private ServiceInfo buildServiceInfo( final String classname,
final Configuration info )
throws Exception
{
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "builder.creating-service-info.notice",
classname );
getLogger().debug( message );
}
final String topLevelName = info.getName();
if( !topLevelName.equals( "service-info" ) )
{
final String message =
REZ.getString( "builder.bad-toplevel-element.error",
classname,
topLevelName );
throw new ConfigurationException( message );
}
Configuration configuration = null;
configuration = info.getChild( "service" );
final ServiceDescriptor descriptor = buildService( configuration );
final String implementationKey = descriptor.getImplementationKey();
configuration = info.getChild( "methods" );
final MethodDescriptor[] methods = buildMethods( configuration );
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "builder.created-info.notice",
implementationKey,
new Integer( methods.length ) );
getLogger().debug( message );
}
return new ServiceInfo( descriptor, methods );
}
/**
* A utility method to build an array of {@link MethodDescriptor} objects
* from specified configuraiton.
*
* @param configuration the loggers configuration
* @return the created MethodDescriptors
* @throws ConfigurationException if an error occurs
*/
private MethodDescriptor[] buildMethods( final Configuration configuration )
throws ConfigurationException
{
final Configuration[] elements = configuration.getChildren( "method" );
final ArrayList methods = new ArrayList();
for( int i = 0; i < elements.length; i++ )
{
final MethodDescriptor method = buildMethod( elements[ i ] );
methods.add( method );
}
return (MethodDescriptor[])methods.toArray( new MethodDescriptor[
methods.size() ] );
}
/**
* A utility method to build a {@link MethodDescriptor}
* object from specified configuraiton.
*
* @param method the Method configuration
* @return the created MethodDescriptor
* @throws ConfigurationException if an error occurs
*/
private MethodDescriptor buildMethod( Configuration method )
throws ConfigurationException
{
final String name = method.getAttribute( "name" );
final String type = method.getAttribute( "return-type" );
final ParameterDescriptor[] parameters = buildMethodParameters( method );
final Attribute[] attributes = buildAttributes( method );
return new MethodDescriptor( name, type, parameters, attributes );
}
/**
* A utility method to build an array of {@link ParameterDescriptor} objects
* from specified configuraiton.
*
* @param configuration the methods configuration
* @return the created ParameterDescriptors
* @throws ConfigurationException if an error occurs
*/
private ParameterDescriptor[] buildMethodParameters( final Configuration
configuration )
throws ConfigurationException
{
final Configuration[] elements = configuration.getChildren( "parameter" );
final ArrayList params = new ArrayList();
for( int i = 0; i < elements.length; i++ )
{
final ParameterDescriptor param =
buildMethodParameter( elements[ i ] );
params.add( param );
}
return (ParameterDescriptor[])params.toArray( new ParameterDescriptor[
params.size() ] );
}
/**
* A utility method to build a {@link ParameterDescriptor}
* object from specified configuraiton.
*
* @param param the Parameter configuration
* @return the created ParameterDescriptor
* @throws ConfigurationException if an error occurs
*/
private ParameterDescriptor buildMethodParameter( Configuration param )
throws ConfigurationException
{
final String type = param.getAttribute( "type" );
final Attribute[] attributes = buildAttributes( param );
return new ParameterDescriptor( type, attributes );
}
/**
* A utility method to buildComponentInfo an array of {@link LoggerDescriptor}
objects
* from specified configuraiton.
*
* @param configuration the loggers configuration
* @return the created LoggerDescriptor
* @throws ConfigurationException if an error occurs
*/
private LoggerDescriptor[] buildLoggers( final Configuration configuration )
throws ConfigurationException
{
final Configuration[] elements = configuration.getChildren( "logger" );
final ArrayList loggers = new ArrayList();
for( int i = 0; i < elements.length; i++ )
{
final LoggerDescriptor logger = buildLogger( elements[ i ] );
loggers.add( logger );
}
return (LoggerDescriptor[])loggers.toArray( new LoggerDescriptor[
loggers.size() ] );
}
/**
* A utility method to buildComponentInfo a {@link LoggerDescriptor}
* object from specified configuraiton.
*
* @param logger the Logger configuration
* @return the created LoggerDescriptor
* @throws ConfigurationException if an error occurs
*/
private LoggerDescriptor buildLogger( Configuration logger )
throws ConfigurationException
{
final String name = logger.getAttribute( "name", "" );
final Attribute[] attributes = buildAttributes( logger );
return new LoggerDescriptor( name, attributes );
}
/**
* A utility method to buildComponentInfo an array of {@link
DependencyDescriptor}
* objects from specified configuration and classname.
*
* @param classname The classname of Component (used for logging purposes)
* @param configuration the dependencies configuration
* @return the created DependencyDescriptor
* @throws ConfigurationException if an error occurs
*/
private DependencyDescriptor[] buildDependencies( final String classname,
final Configuration
configuration )
throws ConfigurationException
{
final Configuration[] elements = configuration.getChildren( "dependency" );
final ArrayList dependencies = new ArrayList();
for( int i = 0; i < elements.length; i++ )
{
final DependencyDescriptor dependency =
buildDependency( classname, elements[ i ] );
dependencies.add( dependency );
}
return (DependencyDescriptor[])dependencies.toArray( new
DependencyDescriptor[ 0 ] );
}
/**
* A utility method to buildComponentInfo a {@link DependencyDescriptor}
* object from specified configuraiton.
*
* @param classname The classname of Component (used for logging purposes)
* @param dependency the dependency configuration
* @return the created DependencyDescriptor
* @throws ConfigurationException if an error occurs
*/
private DependencyDescriptor buildDependency( final String classname,
final Configuration dependency )
throws ConfigurationException
{
final String implementationKey =
dependency.getAttribute( "type" );
final boolean optional =
dependency.getAttributeAsBoolean( "optional", false );
final Attribute[] attributes = buildAttributes( dependency );
String key = dependency.getAttribute( "key", null );
//default to name of service if key unspecified
if( null == key )
{
key = implementationKey;
}
else
{
//If key is specified and it is the same as
//service name then warn that it is redundent.
if( key.equals( implementationKey ) )
{
final String message =
REZ.getString( "builder.redundent-key.notice",
classname,
key );
getLogger().warn( message );
}
}
return new DependencyDescriptor( key, implementationKey, optional,
attributes );
}
/**
* A utility method to buildComponentInfo a {@link ContextDescriptor}
* object from specified configuraiton.
*
* @param context the dependency configuration
* @return the created ContextDescriptor
* @throws ConfigurationException if an error occurs
*/
private ContextDescriptor buildContext( final Configuration context )
throws ConfigurationException
{
final EntryDescriptor[] entrys =
buildEntrys( context.getChildren( "entry" ) );
final Attribute[] attributes = buildAttributes( context );
final String type =
context.getAttribute( "type",
Context.class.getName() );
return new ContextDescriptor( type, entrys, attributes );
}
/**
* A utility method to buildComponentInfo an array of {@link EntryDescriptor}
* objects from specified configuraiton.
*
* @param entrySet the set of entrys to buildComponentInfo
* @return the created {@link EntryDescriptor}s
* @throws ConfigurationException if an error occurs
*/
private EntryDescriptor[] buildEntrys( final Configuration[] entrySet )
throws ConfigurationException
{
final ArrayList entrys = new ArrayList();
for( int i = 0; i < entrySet.length; i++ )
{
final EntryDescriptor service = buildEntry( entrySet[ i ] );
entrys.add( service );
}
return (EntryDescriptor[])entrys.toArray( new EntryDescriptor[ entrys.size()
] );
}
/**
* Create a {@link EntryDescriptor} from configuration.
*
* @param config the configuration
* @return the created {@link EntryDescriptor}
* @throws ConfigurationException if an error occurs
*/
private EntryDescriptor buildEntry( final Configuration config )
throws ConfigurationException
{
final String key = config.getAttribute( "key" );
final String type = config.getAttribute( "type" );
final boolean optional =
config.getAttributeAsBoolean( "optional", false );
final Attribute[] attributes = buildAttributes( config );
return new EntryDescriptor( key, type, optional, attributes );
}
/**
* A utility method to buildComponentInfo an array of {@link ServiceDescriptor}
* objects from specified configuraiton.
*
* @param servicesSet the services configuration
* @return the created ServiceDescriptor
* @throws ConfigurationException if an error occurs
*/
private ServiceDescriptor[] buildServices( final Configuration servicesSet )
throws ConfigurationException
{
final Configuration[] elements = servicesSet.getChildren( "service" );
final ArrayList services = new ArrayList();
for( int i = 0; i < elements.length; i++ )
{
final ServiceDescriptor service = buildService( elements[ i ] );
services.add( service );
}
return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[ 0 ] );
}
/**
* A utility method to buildComponentInfo a {@link ServiceDescriptor}
* object from specified configuraiton data.
*
* @param service the service Configuration
* @return the created ServiceDescriptor
* @throws ConfigurationException if an error occurs
*/
private ServiceDescriptor buildService( final Configuration service )
throws ConfigurationException
{
final String implementationKey = service.getAttribute( "type" );
final Attribute[] attributes = buildAttributes( service );
return new ServiceDescriptor( implementationKey, attributes );
}
/**
* Build up a list of attributes from specific config tree.
*
* @param config the attributes config
* @return the set of attributes
*/
private Attribute[] buildAttributes( final Configuration config )
throws ConfigurationException
{
final ArrayList attributes = new ArrayList();
final Configuration[] attributeConfigs = config.getChildren( "attribute" );
for( int i = 0; i < attributeConfigs.length; i++ )
{
final Configuration attributeConfig = attributeConfigs[ i ];
final Attribute attribute = buildAttribute( attributeConfig );
attributes.add( attribute );
}
return (Attribute[])attributes.toArray( new Attribute[ attributes.size() ] );
}
/**
* Build a attribute from a specific configuration.
*
* @param config the configuration to buildComponentInfo attribute from
* @return the new Attribute
* @throws ConfigurationException if unable to buildComponentInfo attribute due
to malformed xml
*/
private Attribute buildAttribute( Configuration config )
throws ConfigurationException
{
final String name = config.getAttribute( "name" );
final Properties parameters = buildParameters( config );
return new Attribute( name, parameters );
}
/**
* Build up a list of parameters from specific config tree.
*
* @param config the parameters config
* @return the Properties object representing parameters
*/
private Properties buildParameters( final Configuration config )
throws ConfigurationException
{
final Properties parameters = new Properties();
final Configuration[] children = config.getChildren( "param" );
for( int i = 0; i < children.length; i++ )
{
final Configuration child = children[ i ];
final String key = child.getAttribute( "name" );
final String value = child.getAttribute( "value" );
parameters.setProperty( key, value );
}
return parameters;
}
/**
* A utility method to buildComponentInfo a {@link ComponentDescriptor}
* object from specified configuraiton data and classname.
*
* @param config the Component Configuration
* @return the created ComponentDescriptor
* @throws ConfigurationException if an error occurs
*/
private ComponentDescriptor buildComponentDescriptor( final Configuration config
)
throws ConfigurationException
{
final String type = config.getAttribute( "type" );
final Attribute[] attributes = buildAttributes( config );
return new ComponentDescriptor( type, attributes );
}
}
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>