mcconnell 2003/07/10 12:42:07
Modified: merlin/meta/src/java/org/apache/avalon/meta/data/builder
XMLDeploymentProfileCreator.java
merlin/meta/src/java/org/apache/avalon/meta/data/writer
XMLDeploymentProfileWriter.java
merlin/meta/src/test block.xml
Log:
Updated Entry to be an abstract base class with Constructor and Import as concrete
classes.
Revision Changes Path
1.4 +43 -56
avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/XMLDeploymentProfileCreator.java
Index: XMLDeploymentProfileCreator.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/XMLDeploymentProfileCreator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLDeploymentProfileCreator.java 9 Jul 2003 11:39:28 -0000 1.3
+++ XMLDeploymentProfileCreator.java 10 Jul 2003 19:42:07 -0000 1.4
@@ -190,29 +190,6 @@
}
/**
- * Utility method to create a new import directive.
- *
- * @param config the import directive configuration
- * @return the import directive
- * @throws ConfigurationException if an error occurs
- */
- protected ImportDirective getImportDirective( Configuration config )
- throws ConfigurationException
- {
- if( config.getAttribute( "name", null ) != null )
- {
- final String error =
- "The 'import' tag format has changed."
- + " Please check Merlin Home for details "
- + "http://avalon.apache.org/sandbox/merlin/resources";
- throw new ConfigurationException( error );
- }
-
- final String key = config.getAttribute( "key" );
- return new ImportDirective( key );
- }
-
- /**
* Utility method to create a set of entry directives.
*
* @param configs the entry directive configurations
@@ -225,40 +202,50 @@
ArrayList list = new ArrayList();
for( int i = 0; i < configs.length; i++ )
{
- EntryDirective entry = getEntryDirective( configs[ i ] );
- list.add( entry );
- }
- return (EntryDirective[])list.toArray( new EntryDirective[ 0 ] );
- }
+ Configuration conf = configs[ i ];
+ final String key = conf.getAttribute( "key" );
+ final Configuration[] children = conf.getChildren();
+ if( children.length != 1 )
+ {
+ final String error =
+ "Entry '" + key + "' does not contain one child element.";
+ throw new ConfigurationException( error );
+ }
- /**
- * Utility method to create a new entry directive.
- *
- * @param config the entry directive configuration
- * @return the entry directive
- * @throws ConfigurationException if an error occurs
- */
- protected EntryDirective getEntryDirective( Configuration config )
- throws ConfigurationException
- {
- String key = config.getAttribute( "key" );
- if( config.getChild( "import", false ) != null )
- {
- ImportDirective imp = getImportDirective( config.getChild( "import" ) );
- return new EntryDirective( key, imp );
- }
- else if( config.getChild( "param", false ) != null )
- {
- Parameter param = getParameter( config.getChild( "param" ) );
- return new EntryDirective( key, param );
- }
- else
- {
- final String error =
- "Entry directive format has changed."
- + " New structure requires a single embedded 'import' or a 'param'
element.";
- throw new ConfigurationException( error );
+ Configuration child = children[0];
+ final String name = child.getName();
+ if( name.equals( "import" ) )
+ {
+ final String importKey = child.getAttribute( "key" );
+ list.add( new ImportDirective( key, importKey ) );
+ }
+ else if( name.equals( "constructor" ) )
+ {
+ final String classname =
+ child.getAttribute( "class", "java.lang.String" );
+ Configuration[] paramsConf = child.getChildren( "param" );
+ if( paramsConf.length > 0 )
+ {
+ Parameter[] params = getParameters( paramsConf );
+ list.add(
+ new ConstructorDirective(
+ key, classname, params ) );
+ }
+ else
+ {
+ list.add(
+ new ConstructorDirective(
+ key, classname, child.getValue() ) );
+ }
+ }
+ else
+ {
+ final String error =
+ "Entry child unrecognized: " + name;
+ throw new ConfigurationException( error );
+ }
}
+ return (EntryDirective[])list.toArray( new EntryDirective[ 0 ] );
}
/**
1.4 +24 -6
avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/writer/XMLDeploymentProfileWriter.java
Index: XMLDeploymentProfileWriter.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/writer/XMLDeploymentProfileWriter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLDeploymentProfileWriter.java 9 Jul 2003 11:39:28 -0000 1.3
+++ XMLDeploymentProfileWriter.java 10 Jul 2003 19:42:07 -0000 1.4
@@ -65,6 +65,7 @@
import org.apache.avalon.meta.data.CategoryDirective;
import org.apache.avalon.meta.data.ImportDirective;
import org.apache.avalon.meta.data.EntryDirective;
+import org.apache.avalon.meta.data.ConstructorDirective;
import org.apache.avalon.meta.data.Parameter;
import org.apache.excalibur.configuration.ConfigurationUtil;
@@ -238,7 +239,7 @@
writer.write( " class=\"" + context.getClassname() + "\"");
}
- EntryDirective[] entries = context.getEntries();
+ EntryDirective[] entries = context.getEntryDirectives();
if( entries.length == 0 )
{
@@ -278,16 +279,33 @@
final String padding = pad + INDENT;
writer.write( "\n" + pad + "<entry" );
writer.write( " key=\"" + entry.getKey() + "\">" );
- if( entry.getMode() == EntryDirective.IMPORT )
+ if( entry instanceof ImportDirective )
{
- ImportDirective imp = entry.getImportDirective();
+ ImportDirective imp = (ImportDirective) entry;
writer.write( "\n" + padding + "<import" );
writer.write( " key=\"" + imp.getKey() + "\"" );
writer.write( "/>" );
}
- else if( entry.getMode() == EntryDirective.PARAM )
+ else if( entry instanceof ConstructorDirective )
{
- writeParam( writer, entry.getParameter(), padding );
+ final String fill = padding + INDENT;
+ ConstructorDirective cd = (ConstructorDirective) entry;
+ writer.write( "\n" + padding + "<constructor" );
+ if( !cd.getClassname().equals( "java.lang.String" ) )
+ {
+ writer.write( " class=\"" + cd.getClassname() + "\"" );
+ }
+ writer.write( ">" );
+ if( cd.getParameters().length > 0 )
+ {
+ writeParams( writer, cd.getParameters(), fill );
+ writer.write( "\n" + padding + "</constructor>" );
+ }
+ else
+ {
+ writer.write( cd.getArgument() );
+ writer.write( "</constructor>" );
+ }
}
writer.write( "\n" + pad + "</entry>" );
}
1.4 +3 -3 avalon-sandbox/merlin/meta/src/test/block.xml
Index: block.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/test/block.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- block.xml 9 Jul 2003 11:39:28 -0000 1.3
+++ block.xml 10 Jul 2003 19:42:07 -0000 1.4
@@ -39,13 +39,13 @@
</categories>
<context class="MyContextImpl">
<entry key="abc">
- <param class="java.io.File">here/there.xml</param>
+ <constructor class="java.io.File">here/there.xml</constructor>
</entry>
<entry key="batman">
- <param class="MyEntryClass">
+ <constructor class="MyEntryClass">
<param>abc</param>
<param>def</param>
- </param>
+ </constructor>
</entry>
<entry key="green-lantern">
<import key="urn:avalon:classloader"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]