svn commit: rev 22435 - avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder

[email protected]
Newsgroups gmane.comp.jakarta.avalon.cvs
Message-ID <[email protected]>
Author: mcconnell
Date: Thu Jul  1 11:39:13 2004
New Revision: 22435

Modified:
   avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLComponentProfileCreator.java
Log:
Enhancements to support simplification of the context entry directive model and better support for automated directive geneneration.

Modified: avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLComponentProfileCreator.java
==============================================================================
--- avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLComponentProfileCreator.java	(original)
+++ avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLComponentProfileCreator.java	Thu Jul  1 11:39:13 2004
@@ -269,52 +269,86 @@
         ArrayList list = new ArrayList();
         for( int i = 0; i < configs.length; i++ )
         {
-            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 );
-            }
-
-            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 );
-                    ConstructorDirective constructor = 
-                      new ConstructorDirective( key, classname, params );
-                    list.add( constructor );
-                }
-                else
-                {
-                    ConstructorDirective constructor = 
-                      new ConstructorDirective( 
-                        key, classname, (String) child.getValue( null ) );
-                    list.add( constructor );
-                }
-            }
-            else
-            {
-                final String error = 
-                  "Entry child unrecognized: " + name;
-                throw new ConfigurationException( error );
-            }
+            Configuration conf = configs[ i ];
+            EntryDirective entry = getEntry( conf );
+            list.add( entry );
         }
         return (EntryDirective[])list.toArray( new EntryDirective[ 0 ] );
-    }
+    }
+
+    /**
+     * Utility method to create a single entry directive.
+     *
+     * @param config the entry directive configuration
+     * @return the entry directive
+     * @throws ConfigurationException if an error occurs
+     */
+    protected EntryDirective getEntry( Configuration conf )
+        throws ConfigurationException
+    {
+        final String key = conf.getAttribute( "key" );
+        final String classname = conf.getAttribute( "class", "java.lang.String" );
+        if( ( null != classname ) || ( null != conf.getValue( null ) ) )
+        {
+            String value = conf.getValue( null );
+            if( null != value )
+            {
+                return new ConstructorDirective( 
+                  key, classname, value );
+            } 
+            else
+            {
+                Configuration[] configs = conf.getChildren( "param" );
+                Parameter[] params = getParameters( configs );
+                return new ConstructorDirective( key, classname, params );
+            }
+        }
+        else
+        {
+            //
+            // its using the legacy constructor and import approach
+            //
+
+            final Configuration[] children = conf.getChildren();
+            if( children.length != 1 )
+            {
+                final String error = 
+                  "Entry '" + key + "' does not contain one child element.";
+                throw new ConfigurationException( error );
+            }
+
+            Configuration child = children[0];
+            final String name = child.getName();
+            if( name.equals( "import" ) )
+            {
+                final String importKey = child.getAttribute( "key" );
+                return new ImportDirective( key, importKey );
+            }
+            else if( name.equals( "constructor" ) )
+            {
+                final String classname2 = 
+                  child.getAttribute( "class", "java.lang.String" );
+                Configuration[] paramsConf = child.getChildren( "param" );
+                if( paramsConf.length > 0 )
+                {
+                    Parameter[] params = getParameters( paramsConf );
+                    return new ConstructorDirective( key, classname2, params );
+                }
+                else
+                {
+                    return new ConstructorDirective( 
+                      key, classname2, (String) child.getValue( null ) );
+                }
+            }
+            else
+            {
+                final String error = 
+                  "Entry child unrecognized: " + name;
+                throw new ConfigurationException( error );
+            }
+        }
+    }
+
 
     /**
      * Utility method to create a set of parameter directive.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.