mcconnell 2002/07/18 09:57:00 Modified: assembly build.xml assembly/demo/src/java/org/apache/excalibur/playground BasicComponent.java BasicComponent.xinfo BasicComponent.xprofile assembly/src/etc kernel.xml assembly/src/java/org/apache/excalibur/merlin/container ResourceProvider.java assembly/src/java/org/apache/excalibur/merlin/model Profile.java assembly/src/java/org/apache/excalibur/merlin/model/builder XMLProfileCreator.java assembly/src/java/org/apache/excalibur/meta/info/builder XMLTypeCreator.java Added: assembly/src/java/org/apache/excalibur/merlin/model ContextDirective.java Entry.java ModelException.java ModelRuntimeException.java Parameter.java Log: addition of context management framework Revision Changes Path 1.27 +15 -10 jakarta-avalon-excalibur/assembly/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/build.xml,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- build.xml 17 Jul 2002 15:47:23 -0000 1.26 +++ build.xml 18 Jul 2002 16:57:00 -0000 1.27 @@ -20,10 +20,11 @@ General Targets: ---------------- - all - clean, build and dist + all - clean, build, dist and docs (everything) build - compilation and jar creation deploy - places internal and external jars into an extensions directory javadoc - javadoc API generation + docs - projects documentation clean - destroy the build, dist and extensions directory help - this message @@ -69,7 +70,11 @@ <target name="dist" depends="build"/> <target name="meta" depends="meta.javadoc"/> <target name="merlin" depends="merlin.javadoc"/> - <target name="all" depends="clean,meta,merlin,deploy"/> + <target name="all" depends="clean,deploy,docs"/> + + <target name="docs" depends="meta,merlin"> + <ant antfile="docs.xml"/> + </target> <target name="clean"> <delete dir="${build}"/> @@ -202,9 +207,9 @@ <target name="javadoc" depends="meta.javadoc,merlin.javadoc" /> <target name="merlin.javadoc" depends="build" > - <echo message="path: ${javadoc.root.path}/${ant.project.name}"/> - <mkdir dir="${javadoc.root.path}/${ant.project.name}" /> - <javadoc destdir="${javadoc.root.path}/${ant.project.name}" + <echo message="path: ${docs.dir}/api/${ant.project.name}"/> + <mkdir dir="${docs.dir}/api/${ant.project.name}" /> + <javadoc destdir="${docs.dir}/api/${ant.project.name}" doctitle="<h1>${project.title}</h1>" noindex="false" author="false" use="true" @@ -223,7 +228,7 @@ <link href="${avalon.href}" /> <link href="${meta.href}" /> </javadoc> - <copy todir="${javadoc.root.path}/${ant.project.name}"> + <copy todir="${docs.dir}/api/${ant.project.name}"> <fileset dir="${src.dir}/etc"> <include name="*.gif"/> <include name="*.xml"/> @@ -232,9 +237,9 @@ </target> <target name="meta.javadoc" depends="meta.build" > - <echo message="path: ${javadoc.root.path}/meta"/> - <mkdir dir="${javadoc.root.path}/meta" /> - <javadoc destdir="${javadoc.root.path}/meta" + <echo message="path: ${docs.dir}/api/meta"/> + <mkdir dir="${docs.dir}/api/meta" /> + <javadoc destdir="${docs.dir}/api/meta" doctitle="<h1>Avalon Component Meta Model</h1>" noindex="false" author="false" use="true" @@ -251,7 +256,7 @@ <link href="${jdk.href}" /> <link href="${avalon.href}" /> </javadoc> - <copy todir="${javadoc.root.path}/meta" file="${src.dir}/etc/meta.gif"/> + <copy todir="${docs.dir}/api/meta" file="${src.dir}/etc/meta.gif"/> </target> <target name="deploy" depends="build"> 1.4 +38 -3 jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.java Index: BasicComponent.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BasicComponent.java 4 Jul 2002 09:01:32 -0000 1.3 +++ BasicComponent.java 18 Jul 2002 16:57:00 -0000 1.4 @@ -3,6 +3,11 @@ package org.apache.excalibur.playground; import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.context.Contextualizable; +import org.apache.avalon.framework.context.ContextException; +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.activity.Startable; /** * This is a minimal demonstration component that implements the @@ -10,17 +15,47 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a> */ -public class BasicComponent extends AbstractLogEnabled -implements BasicService +public class BasicComponent extends AbstractLogEnabled +implements Contextualizable, Initializable, Startable, BasicService { + private String m_location; + + public void contextualize( Context context ) + { + getLogger().info( "contextualization: " + context.getClass().getName() ); + try + { + m_location = (String) context.get("location"); + } + catch( Throwable e ) + { + getLogger().error("contextualization failure", e ); + } + } + + public void initialize() + { + getLogger().info("initialize"); + } + + public void start() + { + doPrimeObjective(); + } + + public void stop() + { + getLogger().info("stopping"); + } + //======================================================================= // BasicService //======================================================================= public void doPrimeObjective() { - getLogger().info("hello from BasicComponent"); + getLogger().info("hello from '" + m_location + "'."); } } 1.5 +4 -2 jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.xinfo Index: BasicComponent.xinfo =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.xinfo,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- BasicComponent.xinfo 7 Jul 2002 23:06:39 -0000 1.4 +++ BasicComponent.xinfo 18 Jul 2002 16:57:00 -0000 1.5 @@ -6,12 +6,14 @@ <component-info> <component> - <!-- the component name --> <name>basic-component</name> </component> + <context> + <entry key="location"/> + </context> + <services> - <!-- services that this component provides --> <service> <service-ref type="org.apache.excalibur.playground.BasicService"/> </service> 1.2 +14 -1 jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.xprofile Index: BasicComponent.xprofile =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/BasicComponent.xprofile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BasicComponent.xprofile 7 Jul 2002 04:43:35 -0000 1.1 +++ BasicComponent.xprofile 18 Jul 2002 16:57:00 -0000 1.2 @@ -1,6 +1,19 @@ <?xml version="1.0"?> <profiles> - <component/> + + <!-- + A packaged profile is equivalent to a compoent declaration inside a container, + except that it is provided by a component type. A PACKAGED profiles take priority + over an IMPLICIT profile. An EXPLICIT profile declared inside a container defintion + will take priority over PACKAGED profiles. + --> + + <component name="basic"> + <context class="org.apache.excalibur.playground.BasicContext"> + <entry key="location">Paris</entry> + </context> + </component> + </profiles> 1.13 +28 -11 jakarta-avalon-excalibur/assembly/src/etc/kernel.xml Index: kernel.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/etc/kernel.xml,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- kernel.xml 18 Jul 2002 03:40:11 -0000 1.12 +++ kernel.xml 18 Jul 2002 16:57:00 -0000 1.13 @@ -90,7 +90,7 @@ --> <context> - <entry name="location" value="Paris"/> + <entry key="location" value="Paris"/> </context> <!-- @@ -142,16 +142,33 @@ --> <!-- - <component name="test" class="org.apache.avalon.merlin.DefaultContainer"> - <configuration> - <container> - <classpath> - <fileset dir="dist"> - <include name="demo.jar"/> - </fileset> - </classpath> - </container> - </configuration> + <component name="test" class="org.apache.avalon.merlin.kernel.DefaultKernel"> + + <context> + + <import as="classloader"> + <classpath> + <fileset dir="dist"> + <include name="demo.jar"/> + </fileset> + </classpath> + </import> + + <import key="logging" as="logging"/> + + <import as="descriptor"> + <kernel name="embedded"> + <container name="root-embedded"> + <classpath> + <fileset dir="dist"> + <include name="demo.jar"/> + </fileset> + </classpath> + </container> + </kernel> + </import> + </context> + </component> --> 1.5 +2 -2 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/ResourceProvider.java Index: ResourceProvider.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/container/ResourceProvider.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ResourceProvider.java 18 Jul 2002 03:40:11 -0000 1.4 +++ ResourceProvider.java 18 Jul 2002 16:57:00 -0000 1.5 @@ -199,7 +199,7 @@ public Context createContext( Profile profile ) throws Exception { - return profile.getContext(); + return profile.getContext().getContext( m_classloader, null ); } /** 1.7 +6 -7 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Profile.java Index: Profile.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Profile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Profile.java 18 Jul 2002 03:40:11 -0000 1.6 +++ Profile.java 18 Jul 2002 16:57:00 -0000 1.7 @@ -131,7 +131,7 @@ /** * The configuration for component (if any). */ - private final Context m_context; + private final ContextDirective m_context; /** * The logging descriptor. @@ -163,7 +163,7 @@ public Profile( final String name, final Parameters parameters, final Configuration configuration, - final Context context, + final ContextDirective context, final CategoryDescriptor loggers, final Type type, final boolean enabled, @@ -244,12 +244,11 @@ } /** - * Return the Context for profile. This operation may be changed to a - * ContextDirective in the near future. + * Return the context directive for the profile. * - * @return the Context for component. + * @return the ContextDirective for the profile. */ - public Context getContext() + public ContextDirective getContext() { return m_context; } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ContextDirective.java Index: ContextDirective.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.model; import java.util.Map; import java.util.Hashtable; import java.lang.reflect.Constructor; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.DefaultContext; import org.apache.avalon.framework.context.ContextException; /** * A context descriptor declares the context creation criteria for * the context instance and context entries. * * <p><b>XML</b></p> * <p>A context directive may contain multiple import statements. Each import * statement corresponds to a request for a context value from the container.</p> * <pre> * <context class="<font color="darkred">MyContextCLass</font>"> * <import key="<font color="darkred">avalon.work</font>" as="base"/> * <entry key="<font color="darkred">location</font>" value="Paris"/> * <font color="gray"></context></font> * </pre> * * @see Entry * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a> * @version $Revision: 1.1 $ $Date: 2002/07/18 16:57:00 $ */ public class ContextDirective { public static final String DEFAULT_CONTEXT_CLASS = "org.apache.avalon.framework.context.DefaultContext"; /** * The set of entry directives. */ private final Entry[] m_entries; /** * The set of entry directives. */ private final String m_classname; /** * Cached reference to created context value. */ private Context m_context; /** * Creation of a new context directive. * @param location the filename of the logging destination */ public ContextDirective( final Entry[] entries ) { this( DEFAULT_CONTEXT_CLASS, entries ); } /** * Creation of a new file target. * @param classname the context implementation class * @param parameters the context implementation constructor arguments * @param entries the context entry descriptors */ public ContextDirective( final String classname, final Entry[] entries ) { m_classname = classname; m_entries = entries; } /** * Return the classname of the context implementation to use. * @return the classname */ public String getClassname() { return m_classname; } /** * Return the set of entry directives. * @return the entries */ public Entry[] getEntries() { return m_entries; } /** * Returns the context object based on the context directives. * @param parent a possibly null parent context * @return the context object */ public Context getContext( ClassLoader loader, Context parent ) throws ModelException { if( m_context != null ) return m_context; final String classname = getClassname(); Class clazz; try { clazz = loader.loadClass( classname ); } catch( ClassNotFoundException cnfe ) { throw new ModelException( "Could not find context class " + classname, cnfe ); } Map map = new Hashtable(); try { Constructor constructor = clazz.getConstructor( new Class[]{Map.class, Context.class} ); m_context = (Context)constructor.newInstance( new Object[]{map, parent} ); } catch( Throwable e ) { throw new ModelException( "Unexpected exception while creating context form " + classname, e ); } Entry[] entries = getEntries(); for( int i=0; i<entries.length; i++ ) { Entry entry = entries[i]; final String key = entry.getKey(); try { final Object value = entry.getValue( loader ); map.put( key, value ); } catch( Throwable e ) { final String error = "Unable to create the context entry for the key: " + key; throw new ModelException( error, e ); } } if( m_context instanceof DefaultContext ) { ((DefaultContext)m_context).makeReadOnly(); } return m_context; } } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Entry.java Index: Entry.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.model; /** * A entry descriptor declares the context entry creation criteria for * a single context entry instance. * * <p><b>XML</b></p> * <p>A entry may container either (a) body content, or (b) a set of constructor * parameters to be applied as arguments to a constructor of the supplied classname.</p> * <pre> * <entry key="<font color="darkred">location</font>"><font color="darkred">Paris</font></entry>; * <entry key="<font color="darkred">home</font>" class="<font color="darkred">java.io.File</font>"><font color="darkred">../home</font></entry>; * <entry key="<font color="darkred">special</font>" class="<font color="darkred">MyObjectCLass</font>"> * <parameter"><font color="darkred">Paris</font></parameter> * <parameter class="<font color="darkred">java.io.File</font>"><font color="darkred">../home</font></parameter>; * </entry> * </pre> * * @see Parameter * @see ContextDirective * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a> * @version $Revision: 1.1 $ $Date: 2002/07/18 16:57:00 $ */ public class Entry extends Parameter { /** * The entry key. */ private final String m_key; /** * Creation of a new entry directive. * @param key the entry key * @param classname the classname of the entry implementation * @param parameters implementation class constructor parameter directives */ public Entry( final String key, final String classname, final String value ) { super( classname, value ); if( null == key ) throw new NullPointerException("key"); m_key = key; } /** * Creation of a new entry directive. * @param key the entry key * @param classname the classname of the entry implementation * @param parameters implementation class constructor parameter directives */ public Entry( final String key, final String classname, final Parameter[] parameters ) { super( classname, parameters ); if( null == key ) throw new NullPointerException("key"); m_key = key; } /** * Return the context key. * @return the key */ public String getKey() { return m_key; } } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ModelException.java Index: ModelException.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.model; import org.apache.avalon.framework.CascadingException; /** * Exception to indicate that there was a model related error. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a> * @version $Revision: 1.1 $ $Date: 2002/07/18 16:57:00 $ */ public final class ModelException extends CascadingException { /** * Construct a new <code>ModelException</code> instance. * * @param message The detail message for this exception. */ public ModelException( final String message ) { this( message, null ); } /** * Construct a new <code>ModelException</code> instance. * * @param message The detail message for this exception. * @param throwable the root cause of the exception */ public ModelException( final String message, final Throwable throwable ) { super( message, throwable ); } } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/ModelRuntimeException.java Index: ModelRuntimeException.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.model; import org.apache.avalon.framework.CascadingRuntimeException; /** * Exception to indicate that there was a model related runtime error. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a> * @version $Revision: 1.1 $ $Date: 2002/07/18 16:57:00 $ */ public final class ModelRuntimeException extends CascadingRuntimeException { /** * Construct a new <code>ModelRuntimeException</code> instance. * * @param message The detail message for this exception. */ public ModelRuntimeException( final String message ) { this( message, null ); } /** * Construct a new <code>ModelRuntimeException</code> instance. * * @param message The detail message for this exception. * @param throwable the root cause of the exception */ public ModelRuntimeException( final String message, final Throwable throwable ) { super( message, throwable ); } } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/Parameter.java Index: Parameter.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.model; import java.lang.reflect.Constructor; /** * A <code>Parameter</code> represents a single constructor typed argument value. A parameter * container a classname (default value of <code>java.lang.String</code>) and possible sub-parameters. * A parameter's value is established by creating a new instance using the parameter's classname, * together with the values directived from the sub-sidiary parameters as constructor arguments. * * <p><b>XML</b></p> * <p>A parameter is a nested structure containing a string value or contructor parameter arguments.</p> * <pre> * <font color="gray"><-- Simple parameter declaration --></font> * * <parameter><font color="darkred">London</font>"/parameter> * * <font color="gray"><-- Typed parameter declaration --></font> * * <parameter class="<font color="darkred">java.io.File</font>"><font color="darkred">./home</font></parameter> * * <font color="gray"><-- Multi-argument constructor parameter declaration --></font> * * <parameter class="<font color="darkred">MyClass</font>"> * <parameter class="<font color="darkred">java.io.File</font>"><font color="darkred">./home</font></parameter> * <parameter><font color="darkred">London</font>"/> * </parameter> * </pre> * * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a> * @version $Revision: 1.1 $ $Date: 2002/07/18 16:57:00 $ */ public class Parameter { // <parameter>Paris</parameter> // <parameter class="java.io.File"> // <parameter>./home</parameter> // </parameter> /** * The classname to use as the parameter implementation class (defaults to java.lang.String) */ private final String m_classname; /** * The derived value. */ private Object m_value; /** * The sub-parameters from which the value for this parameter may be derived. */ private final Parameter[] m_parameters; /** * Creation of a new parameter using the default <code>java.lang.String</code> * type and a supplied value. * * @param value the string value */ public Parameter( final String value ) { m_parameters = new Parameter[0]; m_classname = "java.lang.String"; m_value = value; } /** * Creation of a new entry directive using a supplied classname and value. * @param classname the classname of the parameter * @param value the parameter constructor value */ public Parameter( final String classname, final String value ) { if( null == classname ) throw new NullPointerException("classname"); if( null == value ) throw new NullPointerException("value"); m_parameters = new Parameter[]{ new Parameter( value ) }; m_classname = classname; } /** * Creation of a new entry directive. * @param key the entry key * @param classname the classname of the entry implementation * @param parameters implementation class constructor parameter directives */ public Parameter( final String classname, final Parameter[] parameters ) { if( null == classname ) throw new NullPointerException("classname"); m_classname = classname; m_parameters = parameters; } /** * Return the classname of the parameter implementation to use. * @return the classname */ public String getClassname() { return m_classname; } /** * Return the classname of the parameter implementation to use. * @return the classname */ Class getParameterClass( ClassLoader loader ) throws ModelException { final String classname = getClassname(); try { return loader.loadClass( classname ); } catch( final ClassNotFoundException e ) { if( classname.equals( "int" ) ) { return int.class; } else if( classname.equals( "short" ) ) { return short.class; } else if( classname.equals( "long" ) ) { return long.class; } else if( classname.equals( "byte" ) ) { return byte.class; } else if( classname.equals( "double" ) ) { return double.class; } else if( classname.equals( "byte" ) ) { return byte.class; } else if( classname.equals( "float" ) ) { return float.class; } else if( classname.equals( "char" ) ) { return char.class; } else if( classname.equals( "char" ) ) { return char.class; } else if( classname.equals( "boolean" ) ) { return boolean.class; } else { throw new ModelRuntimeException( "Could not locate the parameter implemetation for class: '" + m_classname + "'.", e ); } } } /** * Return the derived parameter value. * @return the value */ public Object getValue( ClassLoader loader ) throws ModelException { if( m_value != null ) return m_value; if( m_parameters.length == 0 ) { try { m_value = getParameterClass( loader ).newInstance(); return m_value; } catch( InstantiationException e ) { final String error = "Unable to instantiate instance of class: " + m_classname; throw new ModelException( error, e ); } catch( IllegalAccessException e ) { final String error = "Cannot access null constructor for the class: '" + m_classname + "'."; throw new ModelException( error, e ); } } else { Class[] params = new Class[ m_parameters.length ]; for( int i=0; i<m_parameters.length; i++ ) { try { params[i] = m_parameters[i].getParameterClass( loader ); } catch( Throwable e ) { final String error = "Unable to resolve sub-parameter class: " + m_parameters[i].getClassname() + " inside the parameter " + m_classname; throw new ModelException( error, e ); } } Object[] values = new Object[ m_parameters.length ]; for( int i=0; i<m_parameters.length; i++ ) { try { values[i] = m_parameters[i].getValue( loader ); } catch( Throwable e ) { final String error = "Unable to instantiate sub-parameter for value: " + m_parameters[i].getClassname() + " inside the parameter " + m_classname; throw new ModelException( error, e ); } } Constructor constructor; try { constructor = getParameterClass( loader ).getConstructor( params ); } catch( NoSuchMethodException e ) { final String error = "Supplied parameters in " + m_classname + " do not match an available constructor."; throw new ModelException( error, e ); } try { m_value = constructor.newInstance( values ); return m_value; } catch( InstantiationException e ) { final String error = "Unable to instantiate an instance of a multi-parameter constructor for class: '" + m_classname + "'."; throw new ModelException( error, e ); } catch( IllegalAccessException e ) { final String error = "Cannot access multi-parameter constructor for the class: '" + m_classname + "'."; throw new ModelException( error, e ); } catch( Throwable e ) { final String error = "Unexpected error while attmpting to instantiate a multi-parameter constructor " + "for the class: '" + m_classname + "'."; throw new ModelException( error, e ); } } } } 1.5 +71 -9 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLProfileCreator.java Index: XMLProfileCreator.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLProfileCreator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XMLProfileCreator.java 13 Jul 2002 21:28:18 -0000 1.4 +++ XMLProfileCreator.java 18 Jul 2002 16:57:00 -0000 1.5 @@ -24,6 +24,9 @@ import org.apache.excalibur.meta.ConfigurationBuilder; import org.apache.excalibur.merlin.model.Profile; import org.apache.excalibur.merlin.model.CategoryDescriptor; +import org.apache.excalibur.merlin.model.ContextDirective; +import org.apache.excalibur.merlin.model.Entry; +import org.apache.excalibur.merlin.model.Parameter; import org.apache.excalibur.configuration.ContextFactory; import org.xml.sax.InputSource; @@ -80,9 +83,10 @@ CategoryDescriptor loggers = new CategoryDescriptor( type.getInfo().getName(), null, null ); + ContextDirective context = new ContextDirective( new Entry[0] ); return new Profile[]{ - new Profile( null, null, null, null, loggers, type, true, Profile.IMPLICIT ) }; + new Profile( null, null, null, context, loggers, type, true, Profile.IMPLICIT ) }; } for( int i=0; i<profiles.length; i++ ) { @@ -99,20 +103,78 @@ private Profile buildProfile( Type type, Configuration profile, int mode ) throws Exception { - String name = null; - if( mode == Profile.EXPLICIT ) - { - name = profile.getAttribute("name"); - } + final String name = profile.getAttribute("name"); boolean enabled = profile.getAttributeAsBoolean( "enabled", true ); Parameters params = Parameters.fromConfiguration( profile.getChild("parameters") ); Configuration config = profile.getChild("configuration"); Configuration loggersConfig = profile.getChild("loggers"); CategoryDescriptor loggers = createCategoryDescriptor( loggersConfig, name ); - Context context = ContextFactory.createContextFromConfiguration( - null, profile.getChild("context") ); + ContextDirective context = createContextDirective( profile.getChild("context") ); return new Profile( name, params, config, context, loggers, type, enabled, mode ); } + + public ContextDirective createContextDirective( Configuration config ) throws ConfigurationException + { + String classname = config.getAttribute( "class", ContextDirective.DEFAULT_CONTEXT_CLASS ); + Entry[] entries = createEntries( config.getChildren("entry") ); + return new ContextDirective( classname, entries ); + } + + public Entry[] createEntries( Configuration[] configs ) throws ConfigurationException + { + ArrayList list = new ArrayList(); + for( int i=0; i<configs.length; i++ ) + { + Entry entry = createEntry( configs[i] ); + list.add( entry ); + } + return (Entry[]) list.toArray( new Entry[0] ); + } + + public Entry createEntry( Configuration config ) throws ConfigurationException + { + String key = config.getAttribute( "key" ); + String classname = config.getAttribute( "classname", "java.lang.String" ); + String value = config.getValue( null ); + if( value != null ) + { + return new Entry( key, classname, value ); + } + else + { + Configuration[] params = config.getChildren("parameter"); + Parameter[] parameters = createParameters( params ); + return new Entry( key, classname, parameters ); + } + } + + public Parameter[] createParameters( Configuration[] configs ) throws ConfigurationException + { + ArrayList list = new ArrayList(); + for( int i=0; i<configs.length; i++ ) + { + Parameter parameter = createParameter( configs[i] ); + list.add( parameter ); + } + return (Parameter[]) list.toArray( new Parameter[0] ); + } + + public Parameter createParameter( Configuration config ) throws ConfigurationException + { + String classname = config.getAttribute( "classname", "java.lang.String" ); + String value = config.getValue( null ); + if( value != null ) + { + return new Parameter( classname, value ); + } + else + { + Configuration[] params = config.getChildren("parameter"); + Parameter[] parameters = createParameters( params ); + return new Parameter( classname, parameters ); + } + } + public CategoryDescriptor createCategoryDescriptor( Configuration config, String fallback ) throws ConfigurationException 1.3 +4 -4 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLTypeCreator.java Index: XMLTypeCreator.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLTypeCreator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XMLTypeCreator.java 12 Jul 2002 17:11:04 -0000 1.2 +++ XMLTypeCreator.java 18 Jul 2002 16:57:00 -0000 1.3 @@ -252,7 +252,7 @@ throws ConfigurationException { final EntryDescriptor[] entrys = - buildEntrys( context.getChildren( "entry" ) ); + buildEntries( context.getChildren( "entry" ) ); final Properties attributes = buildAttributes( context.getChild( "attributes" ) ); @@ -272,7 +272,7 @@ * @return the created {@link EntryDescriptor}s * @throws ConfigurationException if an error occurs */ - private EntryDescriptor[] buildEntrys( final Configuration[] entrySet ) + private EntryDescriptor[] buildEntries( final Configuration[] entrySet ) throws ConfigurationException { final ArrayList entrys = new ArrayList(); @@ -297,7 +297,7 @@ throws ConfigurationException { final String key = config.getAttribute( "key" ); - final String type = config.getAttribute( "type" ); + final String type = config.getAttribute( "type", "java.lang.String" ); final boolean optional = config.getAttributeAsBoolean( "optional", false );
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>