mcconnell 2003/07/18 01:26:31
Modified: meta/api/src/java/org/apache/avalon/meta/info
ExtensionDescriptor.java StageDescriptor.java
Type.java
meta/api/src/test/org/apache/avalon/meta/info/test
ExtensionDescriptorTestCase.java
StageDescriptorTestCase.java TypeTestCase.java
meta/impl/src/java/org/apache/avalon/meta/info/builder
XMLLegacyCreator.java XMLTypeCreator.java
meta/impl/src/java/org/apache/avalon/meta/info/verifier
TypeVerifier.java
meta/impl/src/java/org/apache/avalon/meta/info/writer
XMLTypeWriter.java
Log:
Simplify the Stage and Extension descriptors to use string keys.
Revision Changes Path
1.5 +34 -33
avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/ExtensionDescriptor.java
Index: ExtensionDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/ExtensionDescriptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExtensionDescriptor.java 12 Jul 2003 13:34:27 -0000 1.4
+++ ExtensionDescriptor.java 18 Jul 2003 08:26:29 -0000 1.5
@@ -61,50 +61,39 @@
public final class ExtensionDescriptor extends Descriptor
{
/**
- * The interface that represents the client view of the lifecycle phase.
+ * The extension identifier.
*/
- private final ReferenceDescriptor m_reference;
+ private final String m_urn;
/**
* Creation of an extension descriptor without attributes.
- * @param classname an interface classname
- * @exception NullPointerException if the classname is null
+ * @param urn the extension identifier
+ * @exception NullPointerException if the urn identifer is null
*/
- public ExtensionDescriptor( final String classname )
+ public ExtensionDescriptor( final String urn )
throws NullPointerException
{
- this( new ReferenceDescriptor( classname ), null );
- }
-
- /**
- * Creation of an extension descriptor without attributes.
- * @param reference an interface reference
- * @exception NullPointerException if the reference is null
- */
- public ExtensionDescriptor( final ReferenceDescriptor reference )
- throws NullPointerException
- {
- this( reference, null );
+ this( urn, null );
}
/**
* Creation of a extension descriptor with attributes.
- * @param reference a version interface reference
+ * @param urn the extension identifier
* @param attributes a set of attributes to associate with the extension
- * @exception NullPointerException if the supplied reference is null
+ * @exception NullPointerException if the supplied urn is null
*/
- public ExtensionDescriptor( final ReferenceDescriptor reference,
+ public ExtensionDescriptor( final String urn,
final Properties attributes )
throws NullPointerException
{
super( attributes );
- if ( null == reference )
+ if ( null == urn )
{
- throw new NullPointerException( "reference" );
+ throw new NullPointerException( "urn" );
}
- m_reference = reference;
+ m_urn = urn;
}
/**
@@ -112,9 +101,9 @@
*
* @return the reference.
*/
- public ReferenceDescriptor getReference()
+ public String getKey()
{
- return m_reference;
+ return m_urn;
}
/**
@@ -123,11 +112,14 @@
*/
public boolean equals(Object other)
{
- boolean isEqual = super.equals(other) && other instanceof
ExtensionDescriptor;
-
- isEqual = isEqual &&
m_reference.equals(((ExtensionDescriptor)other).m_reference);
-
- return isEqual;
+ if( other instanceof ExtensionDescriptor )
+ {
+ if( super.equals( other ) )
+ {
+ return m_urn.equals( ((ExtensionDescriptor)other).m_urn );
+ }
+ }
+ return false;
}
/**
@@ -138,8 +130,17 @@
{
int hash = super.hashCode();
hash >>>= 17;
- hash ^= m_reference.hashCode();
-
+ hash ^= m_urn.hashCode();
return hash;
}
+
+ /**
+ * Return a stringified representation of the instance.
+ * @return the string representation
+ */
+ public String toString()
+ {
+ return "[extension " + getKey() + "]";
+ }
+
}
1.5 +28 -31
avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/StageDescriptor.java
Index: StageDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/StageDescriptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StageDescriptor.java 12 Jul 2003 13:34:27 -0000 1.4
+++ StageDescriptor.java 18 Jul 2003 08:26:29 -0000 1.5
@@ -62,59 +62,48 @@
{
/**
- * The interface that represents the client view of the lifecycle stage.
+ * The stage identifier.
*/
- private final ReferenceDescriptor m_reference;
+ private final String m_urn;
/**
* Constructor a stage descriptor without attributes.
- * @param classname the stage interface classname
+ * @param urn the stage identifier
* @exception NullPointerException if the classname argument is null
*/
- public StageDescriptor( final String classname )
+ public StageDescriptor( final String urn )
throws NullPointerException
{
- this( new ReferenceDescriptor( classname ), null );
- }
-
- /**
- * Constructor a stage descriptor without attributes.
- * @param reference the stage interface
- * @exception NullPointerException if the reference argument is null
- */
- public StageDescriptor( final ReferenceDescriptor reference )
- throws NullPointerException
- {
- this( reference, null );
+ this( urn, null );
}
/**
* Constructor a stage descriptor with attributes.
- * @param reference the stage interface
+ * @param urn the stage identifier
* @param attributes a set of attribute values to associated with the stage
* @exception NullPointerException if the reference argument is null
*/
- public StageDescriptor( final ReferenceDescriptor reference,
+ public StageDescriptor( final String urn,
final Properties attributes )
throws NullPointerException
{
super( attributes );
- if ( null == reference )
+ if ( null == urn )
{
- throw new NullPointerException( "reference" );
+ throw new NullPointerException( "urn" );
}
- m_reference = reference;
+ m_urn = urn;
}
/**
- * Return the version interface reference.
+ * Return the stage identifier.
*
- * @return the version interface reference.
+ * @return the urn identifier
*/
- public ReferenceDescriptor getReference()
+ public String getKey()
{
- return m_reference;
+ return m_urn;
}
/**
@@ -123,7 +112,10 @@
*/
public int hashCode()
{
- return m_reference.hashCode();
+ int hash = super.hashCode();
+ hash >>>= 17;
+ hash ^= m_urn.hashCode();
+ return hash;
}
/**
@@ -132,9 +124,14 @@
*/
public boolean equals(Object other)
{
- boolean isEqual = super.equals(other) && other instanceof StageDescriptor;
- isEqual = isEqual &&
m_reference.equals(((StageDescriptor)other).m_reference);
- return isEqual;
+ if( other instanceof StageDescriptor )
+ {
+ if( super.equals( other ) )
+ {
+ return m_urn.equals( ((StageDescriptor)other).m_urn );
+ }
+ }
+ return false;
}
/**
@@ -143,6 +140,6 @@
*/
public String toString()
{
- return "[stage " + getReference() + "]";
+ return "[stage " + getKey() + "]";
}
}
1.12 +15 -5
avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/Type.java
Index: Type.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/Type.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Type.java 15 Jul 2003 21:26:35 -0000 1.11
+++ Type.java 18 Jul 2003 08:26:29 -0000 1.12
@@ -348,18 +348,28 @@
/**
* Return the extension supporting the supplied stage.
*
- * @param stage the lifecycle stage that this type requires a handler for
+ * @param key the lifecycle stage that this type requires a handler for
* @return a matching extension or null if no matching extension
*/
public ExtensionDescriptor getExtension( StageDescriptor stage )
{
- ReferenceDescriptor reference = stage.getReference();
+ return getExtension( stage.getKey() );
+ }
+
+ /**
+ * Return the extension supporting the supplied stage.
+ *
+ * @param key the lifecycle stage that this type requires a handler for
+ * @return a matching extension or null if no matching extension
+ */
+ public ExtensionDescriptor getExtension( String key )
+ {
ExtensionDescriptor[] extensions = getExtensions();
for ( int i = 0; i < extensions.length; i++ )
{
ExtensionDescriptor extension = extensions[i];
- ReferenceDescriptor ref = extension.getReference();
- if ( reference.matches( ref ) )
+ String ref = extension.getKey();
+ if ( key.equals( ref ) )
{
return extension;
}
1.2 +4 -4
avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/ExtensionDescriptorTestCase.java
Index: ExtensionDescriptorTestCase.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/ExtensionDescriptorTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExtensionDescriptorTestCase.java 11 Jul 2003 16:19:47 -0000 1.1
+++ ExtensionDescriptorTestCase.java 18 Jul 2003 08:26:30 -0000 1.2
@@ -63,7 +63,7 @@
*/
public class ExtensionDescriptorTestCase extends AbstractDescriptorTestCase
{
- private ReferenceDescriptor m_reference;
+ private String m_key;
public ExtensionDescriptorTestCase( String name )
{
@@ -72,12 +72,12 @@
public void setUp()
{
- m_reference = new ReferenceDescriptor(
ExtensionDescriptorTestCase.class.getName(), Version.getVersion("1.0.0") );
+ m_key = ExtensionDescriptorTestCase.class.getName();
}
protected Descriptor getDescriptor()
{
- return new ExtensionDescriptor(m_reference, getProperties());
+ return new ExtensionDescriptor( m_key, getProperties());
}
protected void checkDescriptor(Descriptor desc)
@@ -85,7 +85,7 @@
super.checkDescriptor(desc);
ExtensionDescriptor ext = (ExtensionDescriptor) desc;
- assertEquals(m_reference, ext.getReference());
+ assertEquals( m_key, ext.getKey() );
}
public void testConstructor()
1.2 +4 -4
avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/StageDescriptorTestCase.java
Index: StageDescriptorTestCase.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/StageDescriptorTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StageDescriptorTestCase.java 11 Jul 2003 20:22:55 -0000 1.1
+++ StageDescriptorTestCase.java 18 Jul 2003 08:26:30 -0000 1.2
@@ -61,7 +61,7 @@
*/
public class StageDescriptorTestCase extends AbstractDescriptorTestCase
{
- private ReferenceDescriptor m_reference;
+ private String m_key;
public StageDescriptorTestCase( String name )
{
@@ -70,12 +70,12 @@
protected Descriptor getDescriptor()
{
- return new StageDescriptor(m_reference, getProperties());
+ return new StageDescriptor(m_key, getProperties());
}
public void setUp()
{
- m_reference = new ReferenceDescriptor(
StageDescriptorTestCase.class.getName(), Version.getVersion( "1.2.3" ) );
+ m_key = StageDescriptorTestCase.class.getName();
}
@@ -97,6 +97,6 @@
super.checkDescriptor( desc );
StageDescriptor stage = (StageDescriptor) desc;
- assertEquals( m_reference, stage.getReference() );
+ assertEquals( m_key, stage.getKey() );
}
}
1.3 +5 -3
avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java
Index: TypeTestCase.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TypeTestCase.java 12 Jul 2003 13:12:57 -0000 1.2
+++ TypeTestCase.java 18 Jul 2003 08:26:30 -0000 1.3
@@ -74,6 +74,7 @@
private ExtensionDescriptor[] m_extensions;
private Configuration m_defaults;
private ReferenceDescriptor m_reference;
+ private String m_key;
public TypeTestCase( String name )
{
@@ -83,6 +84,7 @@
public void setUp()
{
m_reference = new ReferenceDescriptor(TypeTestCase.class.getName());
+ m_key = TypeTestCase.class.getName();
m_descriptor = new InfoDescriptor(TypeTestCase.class.getName());
m_loggers = new CategoryDescriptor[] {
new CategoryDescriptor("name", new Properties())
@@ -95,10 +97,10 @@
new DependencyDescriptor("role", m_reference)
};
m_stages = new StageDescriptor[] {
- new StageDescriptor(m_reference)
+ new StageDescriptor( m_key )
};
m_extensions = new ExtensionDescriptor[] {
- new ExtensionDescriptor( m_reference )
+ new ExtensionDescriptor( m_key )
};
m_defaults = new DefaultConfiguration("default");
}
@@ -111,7 +113,7 @@
assertEquals( m_context, type.getContext());
checkArray(m_dependencies, type.getDependencies());
assertEquals(m_dependencies[0],
type.getDependency(m_dependencies[0].getKey()));
- assertEquals(m_extensions[0], type.getExtension(m_stages[0]));
+ assertEquals(m_extensions[0], type.getExtension( m_stages[0].getKey() ) );
checkArray(m_extensions, type.getExtensions());
assertEquals( m_descriptor, type.getInfo() );
assertEquals( m_services[0], type.getService(m_reference));
1.7 +2 -2
avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLLegacyCreator.java
Index: XMLLegacyCreator.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLLegacyCreator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLLegacyCreator.java 15 Jul 2003 21:26:35 -0000 1.6
+++ XMLLegacyCreator.java 18 Jul 2003 08:26:30 -0000 1.7
@@ -163,7 +163,7 @@
final DependencyDescriptor[] dependencies = buildBlockDependencies(
configuration );
configuration = info.getChild( "stages" );
- final StageDescriptor[] phases = buildPhases( configuration );
+ final StageDescriptor[] phases = buildStages( configuration );
configuration = info.getChild( "extensions" );
final ExtensionDescriptor[] extensions = buildExtensions( configuration );
1.7 +43 -17
avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
Index: XMLTypeCreator.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLTypeCreator.java 15 Jul 2003 21:26:35 -0000 1.6
+++ XMLTypeCreator.java 18 Jul 2003 08:26:30 -0000 1.7
@@ -167,7 +167,7 @@
buildDependencies( configuration );
configuration = info.getChild( "stages" );
- final StageDescriptor[] phases = buildPhases( configuration );
+ final StageDescriptor[] phases = buildStages( configuration );
configuration = info.getChild( "extensions" );
final ExtensionDescriptor[] extensions = buildExtensions( configuration );
@@ -183,14 +183,14 @@
* @return an array of phase descriptors
* @exception Exception if a build error occurs
*/
- protected StageDescriptor[] buildPhases( Configuration config )
+ protected StageDescriptor[] buildStages( Configuration config )
throws ConfigurationException
{
ArrayList list = new ArrayList();
- Configuration[] phases = config.getChildren( "stage" );
- for( int i = 0; i < phases.length; i++ )
+ Configuration[] stages = config.getChildren( "stage" );
+ for( int i = 0; i < stages.length; i++ )
{
- StageDescriptor stage = buildPhase( phases[i] );
+ StageDescriptor stage = buildPhase( stages[i] );
list.add( stage );
}
return (StageDescriptor[])list.toArray( new StageDescriptor[ 0 ] );
@@ -205,13 +205,26 @@
protected StageDescriptor buildPhase( Configuration config )
throws ConfigurationException
{
- ReferenceDescriptor reference = buildReferenceDescriptor( config );
- final Properties attributes =
- buildAttributes( config.getChild( "attributes" ) );
- return new StageDescriptor( reference, attributes );
+ if( config.getAttribute( "type", null ) != null )
+ {
+ //
+ // legacy case
+ //
+
+ String key = config.getAttribute( "type" );
+ final Properties attributes =
+ buildAttributes( config.getChild( "attributes" ) );
+ return new StageDescriptor( key, attributes );
+ }
+ else
+ {
+ String key = config.getAttribute( "key" );
+ final Properties attributes =
+ buildAttributes( config.getChild( "attributes" ) );
+ return new StageDescriptor( key, attributes );
+ }
}
-
/**
* A utility method to build a [EMAIL PROTECTED] ReferenceDescriptor}
* object from specified configuration data.
@@ -250,7 +263,7 @@
{
return createReference( type );
}
- final String versionString = service.getAttribute( "version", "1.0" );
+ final String versionString = service.getAttribute( "version", "" );
final Version version = buildVersion( versionString );
return new ReferenceDescriptor( type, version );
}
@@ -494,11 +507,24 @@
protected ExtensionDescriptor buildExtension( Configuration config )
throws ConfigurationException
{
- ReferenceDescriptor reference =
- buildReferenceDescriptor( config );
- final Properties attributes =
- buildAttributes( config.getChild( "attributes" ) );
- return new ExtensionDescriptor( reference, attributes );
+ if( config.getAttribute( "type", null ) != null )
+ {
+ //
+ // legacy case
+ //
+
+ String urn = config.getAttribute( "type" );
+ final Properties attributes =
+ buildAttributes( config.getChild( "attributes" ) );
+ return new ExtensionDescriptor( urn, attributes );
+ }
+ else
+ {
+ String urn = config.getAttribute( "urn" );
+ final Properties attributes =
+ buildAttributes( config.getChild( "attributes" ) );
+ return new ExtensionDescriptor( urn, attributes );
+ }
}
/**
1.3 +1 -50
avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/verifier/TypeVerifier.java
Index: TypeVerifier.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/verifier/TypeVerifier.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TypeVerifier.java 14 Jul 2003 22:55:21 -0000 1.2
+++ TypeVerifier.java 18 Jul 2003 08:26:31 -0000 1.3
@@ -111,31 +111,10 @@
* @param name the name of component
* @param implementation the implementation class of component
* @param services the classes representing services
- * @param phases the classes representing stage depedencies
* @throws VerifyException if error thrown on failure and
* component fails check
*/
public void verifyType( final String name,
- final Class implementation,
- final Class[] services,
- final Class[] phases )
- throws VerifyException
- {
- verifyComponent( name, implementation, services );
- verifyImplementsPhases( name, implementation, phases );
- }
-
- /**
- * Verify that the supplied implementation class
- * and service classes are valid for a component.
- *
- * @param name the name of component
- * @param implementation the implementation class of component
- * @param services the classes representing services
- * @throws VerifyException if error thrown on failure and
- * component fails check
- */
- public void verifyComponent( final String name,
final Class implementation,
final Class[] services )
throws VerifyException
@@ -146,34 +125,6 @@
verifyImplementsServices( name, implementation, services );
}
- /**
- * Verify that the supplied implementation implements the specified
- * phase interfaces.
- *
- * @param name the name of component
- * @param implementation the class representing the component
- * @param phases the phase interfaces that the implementation must provide
- * @throws VerifyException if error thrown on failure and
- * component fails check
- */
- public void verifyImplementsPhases( final String name,
- final Class implementation,
- final Class[] phases )
- throws VerifyException
- {
- for( int i = 0; i < phases.length; i++ )
- {
- if( !phases[ i ].isAssignableFrom( implementation ) )
- {
- final String message =
- REZ.getString( "verifier.noimpl-phase.error",
- name,
- implementation.getName(),
- phases[ i ].getName() );
- throw new VerifyException( message );
- }
- }
- }
/**
* Verify that the supplied implementation implements the specified
1.9 +5 -9
avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/writer/XMLTypeWriter.java
Index: XMLTypeWriter.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/impl/src/java/org/apache/avalon/meta/info/writer/XMLTypeWriter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XMLTypeWriter.java 15 Jul 2003 21:26:35 -0000 1.8
+++ XMLTypeWriter.java 18 Jul 2003 08:26:31 -0000 1.9
@@ -456,10 +456,8 @@
{
final StageDescriptor stage = stages[ i ];
writer.write( "\n <stage " );
- writer.write( "type=\"" );
- writer.write( stage.getReference().getClassname() );
- writer.write( "\" version=\"" );
- writer.write( stage.getReference().getVersion().toString() );
+ writer.write( "urn=\"" );
+ writer.write( stage.getKey() );
final int count = stage.getAttributeNames().length;
if( 0 == count )
@@ -498,10 +496,8 @@
final ExtensionDescriptor extension = extensions[ i ];
writer.write( "\n <extension " );
- writer.write( "type=\"" );
- writer.write( extension.getReference().getClassname() );
- writer.write( "\" version=\"" );
- writer.write( extension.getReference().getVersion().toString() );
+ writer.write( "key=\"" );
+ writer.write( extension.getKey() );
final int count = extension.getAttributeNames().length;
if( 0 == count )
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]