donaldp 2002/10/01 18:16:50
Modified: info/src/java/org/apache/avalon/framework/tools/infobuilder
InfoCreator.java LegacyBlockInfoCreator.java
Resources.properties SerializedInfoCreator.java
XMLInfoCreator.java componentinfo.dtd
Log:
Start to integrate in building of ServiceInfo objects.
Revision Changes Path
1.2 +22 -8
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/InfoCreator.java
Index: InfoCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/InfoCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InfoCreator.java 31 Aug 2002 08:17:01 -0000 1.1
+++ InfoCreator.java 2 Oct 2002 01:16:49 -0000 1.2
@@ -8,13 +8,15 @@
package org.apache.avalon.framework.tools.infobuilder;
import org.apache.avalon.framework.info.ComponentInfo;
+import org.apache.avalon.framework.info.ServiceInfo;
import java.io.InputStream;
/**
- * Simple interface used to create {@link
org.apache.avalon.framework.info.ComponentInfo}
- * from stream. This abstraction was primarily created so
- * that the ComponentInfo could be built from non-XML
- * sources and no XML classes need be in the classpath.
+ * 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$ $Date$
@@ -22,14 +24,26 @@
public interface InfoCreator
{
/**
- * Create a {@link org.apache.avalon.framework.info.ComponentInfo} from stream
+ * 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
org.apache.avalon.framework.info.ComponentInfo}
- * @throws Exception
+ * @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.3 +20 -1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoCreator.java
Index: LegacyBlockInfoCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/LegacyBlockInfoCreator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LegacyBlockInfoCreator.java 29 Sep 2002 04:13:47 -0000 1.2
+++ LegacyBlockInfoCreator.java 2 Oct 2002 01:16:49 -0000 1.3
@@ -22,6 +22,7 @@
import org.apache.avalon.framework.info.LoggerDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
import org.apache.avalon.framework.info.Attribute;
+import org.apache.avalon.framework.info.ServiceInfo;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.xml.sax.InputSource;
@@ -57,6 +58,24 @@
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 );
}
/**
1.4 +1 -0
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 14 Sep 2002 04:22:25 -0000 1.3
+++ Resources.properties 2 Oct 2002 01:16:49 -0000 1.4
@@ -1,5 +1,6 @@
builder.redundent-key.notice=Warning: ComponentInfo for class {0} redundently
specifies key name "{1}" in dependency when it is identical to the name of service. It
is recomended that the <key/> section be elided.
builder.creating-info.notice=Creating a ComponentInfo for class "{0}".
+builder.creating-service-info.notice=Creating a ServiceInfo for class "{0}".
builder.created-info.notice=Constructed ComponentInfo object for class {0}.
ComponentInfo contains {1} services, {2} dependencies, {3} context entrys and {4}
loggers.
builder.bad-toplevel-element.error=Error the component implemented by "{0}" has an
invalid element at top level of component info descriptor. Expected: "component-info".
Actual: "{1}"
builder.missing-info.error=Unable to locate resource from which to load info for
component implemented by class "{0}".
1.2 +12 -3
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/SerializedInfoCreator.java
Index: SerializedInfoCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/SerializedInfoCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SerializedInfoCreator.java 31 Aug 2002 08:17:01 -0000 1.1
+++ SerializedInfoCreator.java 2 Oct 2002 01:16:49 -0000 1.2
@@ -8,12 +8,13 @@
package org.apache.avalon.framework.tools.infobuilder;
import org.apache.avalon.framework.info.ComponentInfo;
+import org.apache.avalon.framework.info.ServiceInfo;
import java.io.InputStream;
import java.io.ObjectInputStream;
/**
- * Create {@link org.apache.avalon.framework.info.ComponentInfo} from stream made
up of
- * serialized object.
+ * 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$ $Date$
@@ -27,5 +28,13 @@
{
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.11 +195 -41
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoCreator.java
Index: XMLInfoCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/XMLInfoCreator.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XMLInfoCreator.java 29 Sep 2002 04:13:47 -0000 1.10
+++ XMLInfoCreator.java 2 Oct 2002 01:16:49 -0000 1.11
@@ -23,6 +23,9 @@
import org.apache.avalon.framework.info.LoggerDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
import org.apache.avalon.framework.info.Attribute;
+import org.apache.avalon.framework.info.ServiceInfo;
+import org.apache.avalon.framework.info.MethodDescriptor;
+import org.apache.avalon.framework.info.ParameterDescriptor;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.xml.sax.InputSource;
@@ -56,7 +59,24 @@
{
final InputSource input = new InputSource( inputStream );
final Configuration configuration = ConfigurationBuilder.build( input );
- return build( implementationKey, configuration );
+ 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 );
}
/**
@@ -68,8 +88,8 @@
* @return the created ComponentInfo
* @throws ConfigurationException if an error occurs
*/
- private ComponentInfo build( final String classname,
- final Configuration info )
+ private ComponentInfo buildComponentInfo( final String classname,
+ final Configuration info )
throws Exception
{
if( getLogger().isDebugEnabled() )
@@ -124,7 +144,141 @@
}
/**
- * A utility method to build an array of {@link LoggerDescriptor} objects
+ * 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
@@ -147,7 +301,7 @@
}
/**
- * A utility method to build a {@link LoggerDescriptor}
+ * A utility method to buildComponentInfo a {@link LoggerDescriptor}
* object from specified configuraiton.
*
* @param logger the Logger configuration
@@ -158,12 +312,12 @@
throws ConfigurationException
{
final String name = logger.getAttribute( "name", "" );
- final Attribute[] tags = buildTags( logger );
- return new LoggerDescriptor( name, tags );
+ final Attribute[] attributes = buildAttributes( logger );
+ return new LoggerDescriptor( name, attributes );
}
/**
- * A utility method to build an array of {@link DependencyDescriptor}
+ * 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)
@@ -189,7 +343,7 @@
}
/**
- * A utility method to build a {@link DependencyDescriptor}
+ * A utility method to buildComponentInfo a {@link DependencyDescriptor}
* object from specified configuraiton.
*
* @param classname The classname of Component (used for logging purposes)
@@ -206,7 +360,7 @@
final boolean optional =
dependency.getAttributeAsBoolean( "optional", false );
- final Attribute[] tags = buildTags( dependency );
+ final Attribute[] attributes = buildAttributes( dependency );
String key = dependency.getAttribute( "key", null );
@@ -229,11 +383,11 @@
}
}
- return new DependencyDescriptor( key, implementationKey, optional, tags );
+ return new DependencyDescriptor( key, implementationKey, optional,
attributes );
}
/**
- * A utility method to build a {@link ContextDescriptor}
+ * A utility method to buildComponentInfo a {@link ContextDescriptor}
* object from specified configuraiton.
*
* @param context the dependency configuration
@@ -246,20 +400,20 @@
final EntryDescriptor[] entrys =
buildEntrys( context.getChildren( "entry" ) );
- final Attribute[] tags = buildTags( context );
+ final Attribute[] attributes = buildAttributes( context );
final String type =
context.getAttribute( "type",
Context.class.getName() );
- return new ContextDescriptor( type, entrys, tags );
+ return new ContextDescriptor( type, entrys, attributes );
}
/**
- * A utility method to build an array of {@link EntryDescriptor}
+ * A utility method to buildComponentInfo an array of {@link EntryDescriptor}
* objects from specified configuraiton.
*
- * @param entrySet the set of entrys to build
+ * @param entrySet the set of entrys to buildComponentInfo
* @return the created {@link EntryDescriptor}s
* @throws ConfigurationException if an error occurs
*/
@@ -291,13 +445,13 @@
final String type = config.getAttribute( "type" );
final boolean optional =
config.getAttributeAsBoolean( "optional", false );
- final Attribute[] tags = buildTags( config );
+ final Attribute[] attributes = buildAttributes( config );
- return new EntryDescriptor( key, type, optional, tags );
+ return new EntryDescriptor( key, type, optional, attributes );
}
/**
- * A utility method to build an array of {@link ServiceDescriptor}
+ * A utility method to buildComponentInfo an array of {@link ServiceDescriptor}
* objects from specified configuraiton.
*
* @param servicesSet the services configuration
@@ -320,7 +474,7 @@
}
/**
- * A utility method to build a {@link ServiceDescriptor}
+ * A utility method to buildComponentInfo a {@link ServiceDescriptor}
* object from specified configuraiton data.
*
* @param service the service Configuration
@@ -331,40 +485,40 @@
throws ConfigurationException
{
final String implementationKey = service.getAttribute( "type" );
- final Attribute[] tags = buildTags( service );
- return new ServiceDescriptor( implementationKey, tags );
+ final Attribute[] attributes = buildAttributes( service );
+ return new ServiceDescriptor( implementationKey, attributes );
}
/**
- * Build up a list of tags from specific config tree.
+ * Build up a list of attributes from specific config tree.
*
- * @param config the tags config
- * @return the set of tags
+ * @param config the attributes config
+ * @return the set of attributes
*/
- private Attribute[] buildTags( final Configuration config )
+ private Attribute[] buildAttributes( final Configuration config )
throws ConfigurationException
{
- final ArrayList tags = new ArrayList();
+ final ArrayList attributes = new ArrayList();
- final Configuration[] tagConfigs = config.getChildren( "tag" );
- for( int i = 0; i < tagConfigs.length; i++ )
+ final Configuration[] attributeConfigs = config.getChildren( "attribute" );
+ for( int i = 0; i < attributeConfigs.length; i++ )
{
- final Configuration tagConfig = tagConfigs[ i ];
- final Attribute tag = buildTag( tagConfig );
- tags.add( tag );
+ final Configuration attributeConfig = attributeConfigs[ i ];
+ final Attribute attribute = buildAttribute( attributeConfig );
+ attributes.add( attribute );
}
- return (Attribute[])tags.toArray( new Attribute[ tags.size() ] );
+ return (Attribute[])attributes.toArray( new Attribute[ attributes.size() ]
);
}
/**
- * Build a tag from a specific configuration.
+ * Build a attribute from a specific configuration.
*
- * @param config the configuration to build tag from
+ * @param config the configuration to buildComponentInfo attribute from
* @return the new Attribute
- * @throws ConfigurationException if unable to build tag due to malformed xml
+ * @throws ConfigurationException if unable to buildComponentInfo attribute due
to malformed xml
*/
- private Attribute buildTag( Configuration config )
+ private Attribute buildAttribute( Configuration config )
throws ConfigurationException
{
final String name = config.getAttribute( "name" );
@@ -394,7 +548,7 @@
}
/**
- * A utility method to build a {@link ComponentDescriptor}
+ * A utility method to buildComponentInfo a {@link ComponentDescriptor}
* object from specified configuraiton data and classname.
*
* @param config the Component Configuration
@@ -406,8 +560,8 @@
{
final String name = config.getAttribute( "name", null );
final String type = config.getAttribute( "type" );
- final Attribute[] tags = buildTags( config );
+ final Attribute[] attributes = buildAttributes( config );
- return new ComponentDescriptor( name, type, tags );
+ return new ComponentDescriptor( name, type, attributes );
}
}
1.10 +38 -10
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/componentinfo.dtd
Index: componentinfo.dtd
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/infobuilder/componentinfo.dtd,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- componentinfo.dtd 13 Sep 2002 15:42:12 -0000 1.9
+++ componentinfo.dtd 2 Oct 2002 01:16:49 -0000 1.10
@@ -34,13 +34,21 @@
-->
<!--
+The service-info is the document root for service info file, it defines:
+
+service the specifc details about this service
+methods the methods declared by this service
+-->
+<!ELEMENT service-info (service, methods?)>
+
+<!--
The component element describes the component, it defines:
name the human readable name of component type. Must be a string
containing alphanumeric characters, '.', '_' and starting
with a letter.
-->
-<!ELEMENT component (tags?)>
+<!ELEMENT component (attributes?)>
<!ATTLIST component name CDATA #REQUIRED
type CDATA #REQUIRED >
@@ -48,9 +56,9 @@
The logger element defines the loggers that are available to component.
The element has one attribute specifying name of Logger. It contains:
-tags Optional tags about logger
+attributes Optional attributes about logger
-->
-<!ELEMENT logger (tag*) >
+<!ELEMENT logger (attribute*) >
<!ATTLIST logger name CDATA #IMPLIED >
<!--
@@ -59,9 +67,9 @@
It contains:
entrys Key value pairs that component uses
-tags Optional tags about service
+attributes Optional attributes about service
-->
-<!ELEMENT context (entry*,tag*) >
+<!ELEMENT context (entry*,attribute*) >
<!ATTLIST context type CDATA #IMPLIED >
<!--
@@ -73,9 +81,9 @@
It contains:
-tag Optional tags about service
+attribute Optional attributes about service
-->
-<!ELEMENT service (tag*) >
+<!ELEMENT service (attribute*) >
<!ATTLIST service type CDATA #REQUIRED >
<!--
@@ -85,7 +93,7 @@
key the key used to lookup service. If not provided it defaults
to the value specified in the name attribute of service element
-->
-<!ELEMENT dependency (tag*) >
+<!ELEMENT dependency (attribute*) >
<!ATTLIST dependency
key CDATA #IMPLIED
type CDATA #REQUIRED
@@ -109,7 +117,12 @@
<!ELEMENT dependencies (dependency*)>
<!--
-The param element defines an parameter to a tag.
+The methods element contains a list of methods declared by service.
+-->
+<!ELEMENT methods (method*)>
+
+<!--
+The param element defines an parameter to a attribute.
It defines:
name the name of attribute.
@@ -129,7 +142,22 @@
value the value of entry.
optional is entry optional
-->
-<!ELEMENT entry (tag*) >
+<!ELEMENT entry (attribute*) >
+ <!ATTLIST entry
+ key CDATA #REQUIRED
+ type CDATA #REQUIRED
+ optional CDATA #IMPLIED
+ >
+
+<!--
+The method element defines a method.
+It defines:
+
+key the key for entry.
+value the value of entry.
+optional is entry optional
+-->
+<!ELEMENT entry (attribute*) >
<!ATTLIST entry
key CDATA #REQUIRED
type CDATA #REQUIRED
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>