mcconnell 2002/12/17 01:56:20
Modified: meta/src/java/org/apache/avalon/meta/info
ContextDescriptor.java ExtensionDescriptor.java
meta/src/java/org/apache/avalon/meta/info/builder
XMLTypeCreator.java
Log:
Updates meta info builder to support simplified declaration patterns.
Revision Changes Path
1.2 +5 -10
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/ContextDescriptor.java
Index: ContextDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/ContextDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContextDescriptor.java 24 Nov 2002 12:58:26 -0000 1.1
+++ ContextDescriptor.java 17 Dec 2002 09:56:20 -0000 1.2
@@ -71,7 +71,7 @@
*/
public class ContextDescriptor extends Descriptor
{
- private final String m_type;
+ private final ReferenceDescriptor m_type;
private final EntryDescriptor[] m_entries;
/**
@@ -79,7 +79,7 @@
* @param type the classname of the context class
* @param entries the set of entries required within the context
*/
- public ContextDescriptor( final String type,
+ public ContextDescriptor( final ReferenceDescriptor type,
final EntryDescriptor[] entries )
{
this( type, entries, null );
@@ -93,7 +93,7 @@
* @exception NullPointerException if type or entries argument is null
* @exception IllegalArgumentException if the classname format is invalid
*/
- public ContextDescriptor( final String type,
+ public ContextDescriptor( final ReferenceDescriptor type,
final EntryDescriptor[] entries,
final Properties attributes )
throws NullPointerException, IllegalArgumentException
@@ -110,11 +110,6 @@
throw new NullPointerException( "entries" );
}
- if( type.indexOf( "/" ) > -1 )
- {
- throw new IllegalArgumentException( "classname: " + type );
- }
-
m_type = type;
m_entries = entries;
}
@@ -124,7 +119,7 @@
*
* @return the type of Context class.
*/
- public String getType()
+ public ReferenceDescriptor getType()
{
return m_type;
}
1.2 +4 -28
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/ExtensionDescriptor.java
Index: ExtensionDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/ExtensionDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExtensionDescriptor.java 24 Nov 2002 12:58:26 -0000 1.1
+++ ExtensionDescriptor.java 17 Dec 2002 09:56:20 -0000 1.2
@@ -61,11 +61,6 @@
public final class ExtensionDescriptor extends Descriptor
{
/**
- * The name of the lifecycle phase.
- */
- private final String m_name;
-
- /**
* The interface that represents the client view of the lifecycle phase.
*/
private final ReferenceDescriptor m_reference;
@@ -77,39 +72,31 @@
/**
* Constructor an extension descriptor without attributes.
- * @param name the extension name
* @param reference a version interface reference
* @param context the context criteria associated with the extension
* @exception NullPointerException if the name, reference or context parameters
are null
*/
- public ExtensionDescriptor( final String name,
- final ContextDescriptor context,
+ public ExtensionDescriptor( final ContextDescriptor context,
final ReferenceDescriptor reference )
throws NullPointerException
{
- this( name, reference, context, null );
+ this( reference, context, null );
}
/**
* Constructor a phase descriptor with attributes.
- * @param name the extension name
* @param reference a version interface reference
* @param context the context criteria associated with the extension
* @param attributes a set of attributes to associate with the extension
* @exception NullPointerException if the name, reference or context parameters
are null
*/
- public ExtensionDescriptor( final String name,
- final ReferenceDescriptor reference,
+ public ExtensionDescriptor( final ReferenceDescriptor reference,
final ContextDescriptor context,
final Properties attributes )
throws NullPointerException
{
super( attributes );
- if( null == name )
- {
- throw new NullPointerException( "name" );
- }
if( null == reference )
{
throw new NullPointerException( "reference" );
@@ -119,19 +106,8 @@
throw new NullPointerException( "context" );
}
- m_name = name;
m_reference = reference;
m_context = context;
- }
-
- /**
- * Return the name of the lifecycle extension.
- *
- * @return the name the lifecycle phase.
- */
- public String getName()
- {
- return m_name;
}
/**
1.3 +117 -36
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
Index: XMLTypeCreator.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLTypeCreator.java 26 Nov 2002 17:12:14 -0000 1.2
+++ XMLTypeCreator.java 17 Dec 2002 09:56:20 -0000 1.3
@@ -183,19 +183,44 @@
Configuration[] phases = config.getChildren( "stage" );
for( int i = 0; i < phases.length; i++ )
{
- Configuration phase = phases[ i ];
- ReferenceDescriptor reference =
- buildReferenceDescriptor( phase.getChild( "reference" ) );
- final Properties attributes =
- buildAttributes( phase.getChild( "attributes" ) );
- list.add( new StageDescriptor( reference, attributes ) );
+ StageDescriptor stage = buildPhase( phases[i] );
+ list.add( stage );
}
return (StageDescriptor[])list.toArray( new StageDescriptor[ 0 ] );
}
/**
+ * Utility function to create a set of phase descriptor from a configuration.
+ * @param config a configuration containing 0..n phase elements
+ * @return an array of phase descriptors
+ * @exception Exception if a build error occurs
+ */
+ protected StageDescriptor buildPhase( Configuration config ) throws Exception
+ {
+ ReferenceDescriptor reference;
+ if( config.getAttribute( "type", null ) != null )
+ {
+ reference = createReference( config.getAttribute( "type" ) );
+ }
+ else
+ {
+ //
+ // use the old method
+ //
+
+ Configuration ref = config.getChild( "reference" );
+ reference = buildReferenceDescriptor( ref );
+ }
+
+ final Properties attributes =
+ buildAttributes( config.getChild( "attributes" ) );
+ return new StageDescriptor( reference, attributes );
+ }
+
+
+ /**
* A utility method to build a {@link ReferenceDescriptor}
- * object from specified configuraiton data.
+ * object from specified configuration data.
*
* @param service the service Configuration
* @return the created ReferenceDescriptor
@@ -204,7 +229,7 @@
protected ReferenceDescriptor buildReferenceDescriptor( final Configuration
service )
throws ConfigurationException
{
- final String type = service.getAttribute( "type" );
+ final String type = service.getAttribute("type");
final String versionString = service.getAttribute( "version", "1.0" );
final Version version = buildVersion( versionString );
return new ReferenceDescriptor( type, version );
@@ -288,27 +313,39 @@
final Configuration dependency )
throws ConfigurationException
{
- //
- // try both merlin and containerkit variants for this attribute
- //
-
- Configuration serviceRef = serviceRef = dependency.getChild( "reference" );
- final ReferenceDescriptor service =
- buildReferenceDescriptor( serviceRef );
+ String role;
+ ReferenceDescriptor reference;
+ if( dependency.getAttribute( "type", null ) != null )
+ {
+ reference = createReference( dependency.getAttribute( "type" ) );
+ role = dependency.getAttribute( "role", null );
+ }
+ else
+ {
+ //
+ // use the old method
+ //
+
+ Configuration serviceRef = dependency.getChild( "reference" );
+ reference = buildReferenceDescriptor( serviceRef );
+ role = dependency.getChild( "role" ).getValue( null );
+ }
+
final boolean optional =
- dependency.getAttributeAsBoolean( "optional", false );
+ dependency.getAttributeAsBoolean( "optional", false );
final Properties attributes =
buildAttributes( dependency.getChild( "attributes" ) );
- String role = dependency.getChild( "role" ).getValue( null );
- //default to name of service if role unspecified
+ //
+ // default to name of service if role unspecified
+ //
if( null == role )
{
- role = service.getClassname();
+ role = reference.getClassname();
}
- return new DependencyDescriptor( role, service, optional, attributes );
+ return new DependencyDescriptor( role, reference, optional, attributes );
}
/**
@@ -328,16 +365,15 @@
final Properties attributes =
buildAttributes( context.getChild( "attributes" ) );
- final String type =
- context.getAttribute( "type",
- Context.class.getName() );
+ final ReferenceDescriptor type =
+ createReference( context.getAttribute( "type", Context.class.getName() )
);
return new ContextDescriptor( type, entrys, attributes );
}
/**
* A utility method to build an array of {@link EntryDescriptor}
- * objects from specified configuraiton.
+ * objects from specified configuration.
*
* @param entrySet the set of entrys to build
* @return the created {@link EntryDescriptor}s
@@ -409,11 +445,20 @@
protected ServiceDescriptor buildService( final Configuration service )
throws ConfigurationException
{
- Configuration serviceRef = service.getChild( "reference" );
- final ReferenceDescriptor designator = buildReferenceDescriptor( serviceRef
);
+ ReferenceDescriptor reference;
+ if( service.getAttribute( "type", null ) != null )
+ {
+ reference = createReference( service.getAttribute( "type" ) );
+ }
+ else
+ {
+ Configuration serviceRef = service.getChild( "reference" );
+ reference = buildReferenceDescriptor( serviceRef );
+ }
+
final Properties attributes =
buildAttributes( service.getChild( "attributes" ) );
- return new ServiceDescriptor( designator, attributes );
+ return new ServiceDescriptor( reference, attributes );
}
/**
@@ -449,15 +494,51 @@
Configuration[] extensions = config.getChildren( "extension" );
for( int i = 0; i < extensions.length; i++ )
{
- Configuration extension = extensions[ i ];
- final String name = extension.getChild( "name" ).getValue();
- ReferenceDescriptor reference =
- buildReferenceDescriptor( extension.getChild( "reference" ) );
- ContextDescriptor context = buildContext( extension.getChild( "context"
) );
- final Properties attributes =
- buildAttributes( extension.getChild( "attributes" ) );
- list.add( new ExtensionDescriptor( name, reference, context, attributes
) );
+ list.add( buildExtension( extensions[i] ) );
}
return (ExtensionDescriptor[])list.toArray( new ExtensionDescriptor[ 0 ] );
+ }
+
+ /**
+ * Utility function to create an extension descriptor from a configuration.
+ * @param config a configuration containing the extension definition
+ * @return the extension descriptor
+ * @exception Exception if a build error occurs
+ */
+ protected ExtensionDescriptor buildExtension( Configuration config ) throws
Exception
+ {
+ ReferenceDescriptor reference;
+ if( config.getAttribute( "type", null ) != null )
+ {
+ reference = createReference( config.getAttribute( "type" ) );
+ }
+ else
+ {
+ reference =
+ buildReferenceDescriptor( config.getChild( "reference" ) );
+ }
+
+ ContextDescriptor context = buildContext( config.getChild( "context" ) );
+ final Properties attributes =
+ buildAttributes( config.getChild( "attributes" ) );
+ return new ExtensionDescriptor( reference, context, attributes );
+ }
+
+ public ReferenceDescriptor createReference( String path )
+ {
+ final String type;
+ final Version version;
+ int index = path.indexOf(":");
+ if( index > -1 )
+ {
+ type = path.substring( 0, index );
+ version = buildVersion( path.substring( index + 1 ) );
+ }
+ else
+ {
+ type = path;
+ version = buildVersion( "1.0" );
+ }
+ return new ReferenceDescriptor( type, version );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>