mcconnell 2002/12/19 02:52:47 Modified: meta/src/java/org/apache/avalon/meta/info ContextDescriptor.java ExtensionDescriptor.java ReferenceDescriptor.java Service.java Type.java meta/src/java/org/apache/avalon/meta/info/builder XMLServiceCreator.java XMLTypeCreator.java meta/src/java/org/apache/avalon/meta/model/verifier ProfileVerifier.java Log: Enhancement to ContextDirective and Service. ContextDirective updated to support reference to a service defintion of the context interface together with utilities to merge component supplied context entries with service supplied context entries. Revision Changes Path 1.3 +55 -17 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ContextDescriptor.java 17 Dec 2002 09:56:20 -0000 1.2 +++ ContextDescriptor.java 19 Dec 2002 10:52:47 -0000 1.3 @@ -51,6 +51,8 @@ package org.apache.avalon.meta.info; import java.util.Properties; +import java.util.Arrays; +import java.util.List; /** * A descriptor describing the Context that the Component @@ -71,18 +73,18 @@ */ public class ContextDescriptor extends Descriptor { - private final ReferenceDescriptor m_type; + private final ReferenceDescriptor m_reference; private final EntryDescriptor[] m_entries; /** * Create a descriptor without attributes. - * @param type the classname of the context class + * @param reference the classname of the context class * @param entries the set of entries required within the context */ - public ContextDescriptor( final ReferenceDescriptor type, + public ContextDescriptor( final ReferenceDescriptor reference, final EntryDescriptor[] entries ) { - this( type, entries, null ); + this( reference, entries, null ); } /** @@ -93,35 +95,34 @@ * @exception NullPointerException if type or entries argument is null * @exception IllegalArgumentException if the classname format is invalid */ - public ContextDescriptor( final ReferenceDescriptor type, + public ContextDescriptor( final ReferenceDescriptor reference, final EntryDescriptor[] entries, final Properties attributes ) throws NullPointerException, IllegalArgumentException { super( attributes ); - if( null == type ) - { - throw new NullPointerException( "type" ); - } - if( null == entries ) { throw new NullPointerException( "entries" ); } + if( null == reference ) + { + throw new NullPointerException( "reference" ); + } - m_type = type; + m_reference = reference; m_entries = entries; } /** - * Return the type of Context class. + * Return the reference decription for the context. * - * @return the type of Context class. + * @return the referencee descriptor. */ - public ReferenceDescriptor getType() + public ReferenceDescriptor getReference() { - return m_type; + return m_reference; } /** @@ -129,7 +130,7 @@ * * @return the entries contained in the context. */ - public EntryDescriptor[] getEntrys() + public EntryDescriptor[] getEntries() { return m_entries; } @@ -150,5 +151,42 @@ } } return null; + } + + /** + * Returns a set of entry descriptors resulting from a merge of the descriptors + * container in this descriptor with the supplied descriptors. + * + * @param entries the entries to merge + * @return the mergerged set of entries + * @exception Exception of a entry conflict occurs + */ + public EntryDescriptor[] merge( EntryDescriptor[] entries ) + throws IllegalArgumentException + { + for( int i=0; i<entries.length; i++ ) + { + EntryDescriptor entry = entries[i]; + final String key = entry.getKey(); + EntryDescriptor local = getEntry( entry.getKey() ); + if( local != null ) + { + if( !entry.getType().equals( local.getType() ) ) + { + final String error = + "Conflicting entry type for key: " + key; + throw new IllegalArgumentException( error ); + } + } + } + + return join( entries, getEntries() ); + } + + private EntryDescriptor[] join( EntryDescriptor[] primary, EntryDescriptor[] secondary ) + { + List list = Arrays.asList( primary ); + list.addAll( Arrays.asList( secondary ) ); + return (EntryDescriptor[]) list.toArray( new EntryDescriptor[0] ); } } 1.3 +3 -3 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ExtensionDescriptor.java 17 Dec 2002 09:56:20 -0000 1.2 +++ ExtensionDescriptor.java 19 Dec 2002 10:52:47 -0000 1.3 @@ -71,7 +71,7 @@ private final ContextDescriptor m_context; /** - * Constructor an extension descriptor without attributes. + * Creation of an extension descriptor without attributes. * @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 @@ -84,7 +84,7 @@ } /** - * Constructor a phase descriptor with attributes. + * Creation of a phase descriptor with attributes. * @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 1.2 +32 -5 avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/ReferenceDescriptor.java Index: ReferenceDescriptor.java =================================================================== RCS file: /home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/ReferenceDescriptor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ReferenceDescriptor.java 24 Nov 2002 12:58:26 -0000 1.1 +++ ReferenceDescriptor.java 19 Dec 2002 10:52:47 -0000 1.2 @@ -140,19 +140,18 @@ */ public boolean matches( final ReferenceDescriptor other ) { - return - other.getClassname().equals( getClassname() ) + return other.getClassname().equals( getClassname() ) && other.getVersion().complies( getVersion() ); } /** - * Convert to a string of format name/version + * Convert to a string of format name:version * * @return string describing service */ public String toString() { - return getClassname() + "/" + getVersion(); + return getClassname() + ":" + getVersion(); } /** @@ -189,4 +188,32 @@ return match; } + + /** + * Creation of a new reference descriptor form a supplied string. + * The implementation looks for the classname/version delimiter + * of ":". If no version information is found, the default 1.0.0 + * version is assigned. + * + * @param path the structured path in for form <classname>:<version> + * @return the new reference descriptor + */ + public static ReferenceDescriptor newInstance( String path ) + { + final String type; + final Version version; + int index = path.indexOf(":"); + if( index > -1 ) + { + type = path.substring( 0, index ); + version = Version.getVersion( path.substring( index + 1 ) ); + } + else + { + type = path; + version = Version.getVersion( "1.0.0" ); + } + return new ReferenceDescriptor( type, version ); + } + } 1.3 +68 -31 avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Service.java Index: Service.java =================================================================== RCS file: /home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Service.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Service.java 15 Dec 2002 17:48:03 -0000 1.2 +++ Service.java 19 Dec 2002 10:52:47 -0000 1.3 @@ -73,61 +73,85 @@ //========================================================================= /** - * The service classname key. + * The service reference. */ - private final String m_classname; + private final ReferenceDescriptor m_reference; /** - * The service version. + * The optional context entry criteria. */ - private final Version m_version; + private final EntryDescriptor[] m_entries; //========================================================================= // constructor //========================================================================= /** - * Creation of a new Service instance. + * Creation of a new Service instance using a classname and + * supplied properties argument. + * + * @param reference the versioned classname + */ + public Service( final ReferenceDescriptor reference ) + { + this( reference, null, null ); + } + + /** + * Creation of a new Service instance using a classname and + * supplied properties argument. * - * @param classname the classname of the service + * @param reference the versioned classname + * @param attributes the set of attributes to assign to the descriptor */ - public Service( final String classname ) + public Service( + final ReferenceDescriptor reference, + final EntryDescriptor[] entries ) { - this( classname, null ); + this( reference, entries, null ); } /** * Creation of a new Service instance using a classname and * supplied properties argument. * - * @param classname the classname of the service - * @param version the service version + * @param reference the versioned classname + * @param attributes the set of attributes to assign to the descriptor */ - public Service( final String classname, final Version version ) + public Service( + final ReferenceDescriptor reference, + final Properties attributes ) { - this( classname, version, null ); + this( reference, null, attributes ); } /** * Creation of a new Service instance using a classname and * supplied properties argument. * - * @param classname the classname of the service - * @param version the service version + * @param reference the versioned classname + * @param entries the set of optional context entries * @param attributes the set of attributes to assign to the descriptor */ public Service( - final String classname, - final Version version, + final ReferenceDescriptor reference, + final EntryDescriptor[] entries, final Properties attributes ) { super( attributes ); - if( classname == null ) + if( reference == null ) + { + throw new NullPointerException( "reference" ); + } + m_reference = reference; + if( entries == null ) + { + m_entries = new EntryDescriptor[0]; + } + else { - throw new NullPointerException( "classname" ); + m_entries = entries; } - m_version = version; - m_classname = classname; } //========================================================================= @@ -140,7 +164,7 @@ */ public String getClassname() { - return m_classname; + return m_reference.getClassname(); } /** @@ -149,11 +173,26 @@ */ public Version getVersion() { - if( m_version == null ) - { - return DEFAULT_VERSION; - } - return m_version; + return m_reference.getVersion(); + } + + /** + * Return the service reference. + * @return the reference + */ + public ReferenceDescriptor getReference() + { + return m_reference; + } + + /** + * Return the entries declared by the service. + * + * @return the entry descriptors + */ + public EntryDescriptor[] getEntries() + { + return m_entries; } /** @@ -165,9 +204,7 @@ */ public boolean matches( final ReferenceDescriptor reference ) { - return - reference.getClassname().equals( getClassname() ) - && reference.getVersion().complies( getVersion() ); + return reference.equals( getReference() ); } /** @@ -209,7 +246,7 @@ */ public String toString() { - return getClassname() + ":" + getVersion(); + return getReference().toString(); } } 1.6 +1 -12 avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Type.java Index: Type.java =================================================================== RCS file: /home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Type.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Type.java 11 Dec 2002 05:16:38 -0000 1.5 +++ Type.java 19 Dec 2002 10:52:47 -0000 1.6 @@ -334,17 +334,6 @@ } /** - * Return the lifecycle stages extensions required by this extension. - * - * @return an array of stage descriptors. - * @deprecated use getStages() - */ - public StageDescriptor[] getPhases() - { - return m_stages; - } - - /** * Return the lifecycle stages extensions required by this component type. * * @return an array of stage descriptors. 1.2 +48 -2 avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/XMLServiceCreator.java Index: XMLServiceCreator.java =================================================================== RCS file: /home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/XMLServiceCreator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XMLServiceCreator.java 24 Nov 2002 12:58:27 -0000 1.1 +++ XMLServiceCreator.java 19 Dec 2002 10:52:47 -0000 1.2 @@ -52,6 +52,7 @@ import java.io.InputStream; import java.util.Properties; +import java.util.ArrayList; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.framework.Version; @@ -59,6 +60,8 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.meta.ConfigurationBuilder; import org.apache.avalon.meta.info.Service; +import org.apache.avalon.meta.info.EntryDescriptor; +import org.apache.avalon.meta.info.ReferenceDescriptor; import org.xml.sax.InputSource; /** @@ -119,10 +122,12 @@ final Properties attributes = buildAttributes( info.getChild( "attributes" ) ); + final EntryDescriptor[] entries = + buildEntries( info.getChild( "entries" ).getChildren("entry") ); final String versionString = info.getChild( "version" ).getValue( "1.0" ); final Version version = buildVersion( versionString ); - return new Service( classname, version, attributes ); + return new Service( new ReferenceDescriptor( classname, version ), entries, attributes ); } /** @@ -150,6 +155,47 @@ } return attributes; } + + /** + * A utility method to build an array of [EMAIL PROTECTED] EntryDescriptor} + * objects from specified configuration. + * + * @param entrySet the set of entrys to build + * @return the created [EMAIL PROTECTED] EntryDescriptor}s + * @throws ConfigurationException if an error occurs + */ + protected EntryDescriptor[] buildEntries( 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 [EMAIL PROTECTED] EntryDescriptor} from configuration. + * + * @param config the configuration + * @return the created [EMAIL PROTECTED] EntryDescriptor} + * @throws ConfigurationException if an error occurs + */ + protected EntryDescriptor buildEntry( final Configuration config ) + throws ConfigurationException + { + final String key = config.getAttribute( "key" ); + final String type = config.getAttribute( "type", "java.lang.String" ); + final boolean optional = + config.getAttributeAsBoolean( "optional", false ); + + return new EntryDescriptor( key, type, optional ); + } + /** * A utility method to parse a Version object from specified string. 1.4 +6 -45 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XMLTypeCreator.java 17 Dec 2002 09:56:20 -0000 1.3 +++ XMLTypeCreator.java 19 Dec 2002 10:52:47 -0000 1.4 @@ -360,56 +360,17 @@ throws ConfigurationException { final EntryDescriptor[] entrys = - buildEntries( context.getChildren( "entry" ) ); + buildEntries( context.getChildren( "entry" ) ); final Properties attributes = - buildAttributes( context.getChild( "attributes" ) ); + buildAttributes( context.getChild( "attributes" ) ); - final ReferenceDescriptor type = + ReferenceDescriptor reference = createReference( context.getAttribute( "type", Context.class.getName() ) ); - return new ContextDescriptor( type, entrys, attributes ); + return new ContextDescriptor( reference, entrys, attributes ); } - /** - * A utility method to build an array of [EMAIL PROTECTED] EntryDescriptor} - * objects from specified configuration. - * - * @param entrySet the set of entrys to build - * @return the created [EMAIL PROTECTED] EntryDescriptor}s - * @throws ConfigurationException if an error occurs - */ - protected EntryDescriptor[] buildEntries( 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 [EMAIL PROTECTED] EntryDescriptor} from configuration. - * - * @param config the configuration - * @return the created [EMAIL PROTECTED] EntryDescriptor} - * @throws ConfigurationException if an error occurs - */ - protected EntryDescriptor buildEntry( final Configuration config ) - throws ConfigurationException - { - final String key = config.getAttribute( "key" ); - final String type = config.getAttribute( "type", "java.lang.String" ); - final boolean optional = - config.getAttributeAsBoolean( "optional", false ); - - return new EntryDescriptor( key, type, optional ); - } /** * A utility method to build an array of [EMAIL PROTECTED] ServiceDescriptor} @@ -537,7 +498,7 @@ else { type = path; - version = buildVersion( "1.0" ); + version = buildVersion( "1.0.0" ); } return new ReferenceDescriptor( type, version ); } 1.3 +2 -2 avalon-sandbox/meta/src/java/org/apache/avalon/meta/model/verifier/ProfileVerifier.java Index: ProfileVerifier.java =================================================================== RCS file: /home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/model/verifier/ProfileVerifier.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ProfileVerifier.java 7 Dec 2002 09:48:58 -0000 1.2 +++ ProfileVerifier.java 19 Dec 2002 10:52:47 -0000 1.3 @@ -180,7 +180,7 @@ final Type info = profile.getType(); final ContextDescriptor context = info.getContext(); - final int count = context.getEntrys().length; + final int count = context.getEntries().length; if( !Contextualizable.class.isAssignableFrom( clazz ) ) {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>