mcconnell 2002/11/18 02:41:34
Modified: meta/src/java/org/apache/excalibur/meta/info Type.java
meta/src/java/org/apache/excalibur/meta/model Profile.java
meta/src/java/org/apache/excalibur/meta/model/builder
ProfileBuilder.java XMLProfileCreator.java
Added: meta/src/java/org/apache/excalibur/meta/model Mode.java
Log:
Updates to the model sub-package to extract state information that can
be seperated out into the Appliance abstraction.
Revision Changes Path
1.10 +2 -2
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/Type.java
Index: Type.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/Type.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Type.java 23 Oct 2002 16:34:46 -0000 1.9
+++ Type.java 18 Nov 2002 10:41:33 -0000 1.10
@@ -344,7 +344,7 @@
}
/**
- * Return the stages supported by this extension.
+ * Return the stages extension handling provided by this extension.
*
* @return an array of extension descriptors.
*/
1.2 +18 -108
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/Profile.java
Index: Profile.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/Profile.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Profile.java 11 Nov 2002 10:24:00 -0000 1.1
+++ Profile.java 18 Nov 2002 10:41:34 -0000 1.2
@@ -145,21 +145,6 @@
{
/**
- * Constant indicating that the profile was implicitly created.
- */
- public static final int IMPLICIT = 0;
-
- /**
- * Constant indicating that the profile was created based on a profile packaged
with the type.
- */
- public static final int PACKAGED = 1;
-
- /**
- * Constant indicating that the profile was explicitly declared under an
assembly directive.
- */
- public static final int EXPLICIT = 2;
-
- /**
* The name of the component profile. This is an
* abstract name used during assembly.
*/
@@ -198,22 +183,10 @@
/**
* The creation mode.
*/
- private final int m_mode;
-
- /**
- * The enabled status of the profile. Normally a profile is enabled however, a
- * failure to assemble will result in the disabling of the profile.
- */
- private boolean m_enabled = true;
+ private final Mode m_mode;
/**
- * The activation policy - TRUE if activation on startup, FALSE to activate on
request.
- */
- private final boolean m_activation;
-
- /**
- * Create an Profile instance, enabled, lazy activation and explicit
- * status.
+ * Create an explicit Profile instance.
*
* @param name the abstract name of the profile
* @param type the type of component that this profile qualifies
@@ -223,7 +196,7 @@
final Type type,
final LoggingDirective categories )
{
- this( name, null, null, null, categories, type, true, false, EXPLICIT );
+ this( name, null, null, null, categories, type, Mode.EXPLICIT );
}
/**
@@ -234,8 +207,6 @@
* @param context the context instance to use during type instantiation
* @param categories the logging categories descriptor
* @param type the type of component that this profile qualifies
- * @param enabled the enabled state of the component profile
- * @param activation TRUE if activation on startup, FALSE to activate on request
* @param mode the creation mode (either IMPLICIT, PACKAGED, or EXPLICIT)
*/
public Profile( final String name,
@@ -243,15 +214,13 @@
final ContextDirective context,
final LoggingDirective categories,
final Type type,
- final boolean enabled,
- final boolean activation,
- final int mode )
+ final Mode mode )
{
- this( name, null, configuration, context, categories, type, enabled,
activation, mode );
+ this( name, null, configuration, context, categories, type, mode );
}
/**
- * Create a Profile instance without parameters.
+ * Create an explicit Profile instance without parameters.
*
* @param name the abstract name of profile
* @param activation the profile activation policy
@@ -266,9 +235,8 @@
template.getContext(),
template.getCategories(),
template.getType(),
- template.isEnabled(),
- activation,
- EXPLICIT );
+ Mode.EXPLICIT
+ );
}
/**
@@ -280,8 +248,6 @@
* @param context the context instance to use during type instantiation
* @param categories the logging categories descriptor
* @param type the type of component that this profile qualifies
- * @param enabled the enabled state of the component profile
- * @param activation TRUE if activation on startup, FALSE to activate on request
* @param mode the creation mode (either IMPLICIT, PACKAGED, or EXPLICIT)
*/
public Profile( final String name,
@@ -290,9 +256,7 @@
final ContextDirective context,
final LoggingDirective categories,
final Type type,
- final boolean enabled,
- final boolean activation,
- final int mode )
+ final Mode mode )
{
if( null == type )
{
@@ -305,7 +269,7 @@
}
else
{
- if( mode != EXPLICIT )
+ if( !mode.equals( Mode.EXPLICIT ) )
{
m_name = name + "-" + System.identityHashCode( this );
}
@@ -320,38 +284,20 @@
throw new NullPointerException( "categories" );
}
+ if( null == mode )
+ {
+ throw new NullPointerException( "mode" );
+ }
+
m_parameters = parameters;
m_configuration = configuration;
m_categories = categories;
m_type = type;
m_context = context;
- m_enabled = enabled;
- m_activation = activation;
m_mode = mode;
}
/**
- * Test is this profile is enabled. A profile is enabled unless explicitly
disabled by an
- * assembly directive, or implicity disabled as a result of an assembly failure.
- *
- * @return TRUE if the profile is enabled.
- * @see #setEnabled( boolean )
- */
- public boolean isEnabled()
- {
- return m_enabled;
- }
-
- /**
- * Set the enabled status of the profile to the supplied value.
- * @param value the enabled status - TRUE or FALSE
- */
- public void setEnabled( boolean value )
- {
- m_enabled = value;
- }
-
- /**
* Return the name of component metadata instance.
*
* @return the name of the component.
@@ -490,24 +436,12 @@
* Returns the creation mode for this profile.
* @return a value of EXPLICIT, PACKAGED or IMPLICIT
*/
- public int getMode()
+ public Mode getMode()
{
return m_mode;
}
/**
- * Return the activation policy for the component. If TRUE, activation
- * will occur at startup. If false, activation will be deferred to
- * the first lookup invocation if any (i.e. lazy activation).
- *
- * @return the activation policy
- */
- public boolean getActivationPolicy()
- {
- return m_activation;
- }
-
- /**
* Returns a string representation of the profile.
* @return a string representation
*/
@@ -515,7 +449,7 @@
{
return "Profile name: " + getName()
+ ", type: " + getType().getInfo().getName()
- + ", mode: " + modeToString( getMode() );
+ + ", mode: " + getMode();
}
/**
@@ -544,28 +478,4 @@
return buffer.toString();
}
- /**
- * Returns a string representation of a mode value.
- * @param mode the mode value
- * @return the string representation
- */
- public static String modeToString( int mode )
- {
- if( mode == IMPLICIT )
- {
- return "IMPLICIT";
- }
- else if( mode == PACKAGED )
- {
- return "PACKAGED";
- }
- else if( mode == EXPLICIT )
- {
- return "EXPLICIT";
- }
- else
- {
- return "?";
- }
- }
}
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/Mode.java
Index: Mode.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.excalibur.meta.model;
/**
* The <code>Mode</code> class declares the EXPLICIT, PACKAGED or IMPLICIT mode of
creation of a profile.
*
* @see Profile
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/18 10:41:34 $
*/
public class Mode
{
/**
* Constant indicating that the profile was implicitly created.
*/
public static final int IMPLICIT_VALUE = 0;
/**
* Constant indicating that the profile was created based on a profile packaged
with the type.
*/
public static final int PACKAGED_VALUE = 1;
/**
* Constant indicating that the profile was explicitly declared under an
assembly directive.
*/
public static final int EXPLICIT_VALUE = 2;
/**
* Constant indicating that the profile was implicitly created.
*/
public static final Mode IMPLICIT = new Mode( IMPLICIT_VALUE );
/**
* Constant indicating that the profile was created based on a profile packaged
with the type.
*/
public static final Mode PACKAGED = new Mode( PACKAGED_VALUE );
/**
* Constant indicating that the profile was explicitly declared under an
assembly directive.
*/
public static final Mode EXPLICIT = new Mode( EXPLICIT_VALUE );
/**
* Returns a string representation of a mode value.
* @param mode the mode value
* @return the string representation
*/
public static String modeToString( int mode )
{
if( mode == IMPLICIT_VALUE )
{
return "IMPLICIT";
}
else if( mode == PACKAGED_VALUE )
{
return "PACKAGED";
}
else if( mode == EXPLICIT_VALUE )
{
return "EXPLICIT";
}
else
{
return "?";
}
}
/**
* The creation mode.
*/
private final int m_mode;
/**
* Creation of a new mode value.
* @param the int value of the mode.
*/
public Mode( int mode )
{
m_mode = mode;
}
/**
* The supplied argument.
*/
public int getValue()
{
return m_mode;
}
/**
* Return a string representatio of the mode.
* @return String the string value
*/
public String toString()
{
return modeToString( getValue() );
}
/**
* Compare a supplied object for equality.
* @param object the other object
* @return TRUE if the supplied mode is equivalent to this mode.
*/
public boolean equals( Object object )
{
if( object instanceof Mode )
{
return ((Mode)object).getValue() == getValue();
}
return false;
}
}
1.2 +41 -9
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/ProfileBuilder.java
Index: ProfileBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/ProfileBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProfileBuilder.java 11 Nov 2002 10:38:24 -0000 1.1
+++ ProfileBuilder.java 18 Nov 2002 10:41:34 -0000 1.2
@@ -56,9 +56,11 @@
package org.apache.excalibur.meta.model.builder;
import java.io.InputStream;
+import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.excalibur.meta.model.Profile;
+import org.apache.excalibur.meta.model.ModelRuntimeException;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.info.builder.TypeBuilder;
@@ -72,12 +74,27 @@
public final class ProfileBuilder
{
private static final Resources REZ =
- ResourceManager.getPackageResources( TypeBuilder.class );
+ ResourceManager.getPackageResources( ProfileBuilder.class );
- private final ProfileCreator m_xmlProfileCreator = createXMLProfileCreator();
+ private ProfileCreator m_xmlProfileCreator;
+
+ public ProfileBuilder()
+ {
+ this( Profile.class );
+ }
+
+ /**
+ * Creation of a profile builder that uses the supplied base class for
+ * new profile creation.
+ * @param base the profile base class
+ */
+ public ProfileBuilder( Class base )
+ {
+ m_xmlProfileCreator = createXMLProfileCreator( base );
+ }
/**
- * Build Profile from the XML descriptor format.
+ * Build the set of packaged profiles for a type.
*
* @param loader the ClassLoader to load info from
* @param type the Type on which the profile is based
@@ -94,7 +111,20 @@
final ProfileCreator creator = getXMLProfileCreator( xprofile );
return creator.createPackagedProfiles( loader, type, inputStream );
+ }
+ /**
+ * Build a profile using a supplied type and configuration.
+ *
+ * @param loader the ClassLoader to load info from
+ * @param type the Type on which the profile is based
+ * @return the created Profile
+ * @throws Exception if an error occurs
+ */
+ public Profile build( Type type, Configuration config )
+ throws Exception
+ {
+ return m_xmlProfileCreator.createProfile( type, config );
}
/**
@@ -124,17 +154,19 @@
*
* @return the XML {@link ProfileCreator}
*/
- private static ProfileCreator createXMLProfileCreator()
+ private static ProfileCreator createXMLProfileCreator( Class base )
{
ProfileCreator xmlProfileCreator = null;
try
{
- xmlProfileCreator = new XMLProfileCreator();
+ xmlProfileCreator = new XMLProfileCreator( base );
}
- catch( final Exception e )
+ catch( final Throwable e )
{
- //Ignore it if ClassNot found due to no
- //XML Classes on classpath
+ final String error =
+ "Unexpected error while attempting to create the XML Profile
Creator."
+ + " Base: " + base.getName();
+ throw new ModelRuntimeException( error, e );
}
return xmlProfileCreator;
}
1.2 +83 -47
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/XMLProfileCreator.java
Index: XMLProfileCreator.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/XMLProfileCreator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLProfileCreator.java 11 Nov 2002 10:38:24 -0000 1.1
+++ XMLProfileCreator.java 18 Nov 2002 10:41:34 -0000 1.2
@@ -58,12 +58,16 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Vector;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Array;
+
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.excalibur.meta.model.ModelRuntimeException;
import org.apache.excalibur.meta.model.LoggingDirective;
import org.apache.excalibur.meta.model.Category;
import org.apache.excalibur.meta.model.ContextDirective;
@@ -71,6 +75,7 @@
import org.apache.excalibur.meta.model.Import;
import org.apache.excalibur.meta.model.Parameter;
import org.apache.excalibur.meta.model.Profile;
+import org.apache.excalibur.meta.model.Mode;
import org.apache.excalibur.meta.ConfigurationBuilder;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.info.builder.XMLTypeCreator;
@@ -90,6 +95,48 @@
private static final Resources REZ =
ResourceManager.getPackageResources( XMLTypeCreator.class );
+ /**
+ * The profile base class.
+ */
+ private Class m_clazz;
+
+ /**
+ * The profile base class constructor.
+ */
+ private Constructor m_base;
+
+ public XMLProfileCreator() throws Exception
+ {
+ this( Profile.class );
+ }
+
+ /**
+ * Creation of a profile builder that uses the supplied base class for
+ * new profile creation.
+ * @param base the profile base class
+ */
+ public XMLProfileCreator( Class base ) throws Exception
+ {
+ m_clazz = base;
+ m_base = base.getConstructor(
+ new Class[]
+ {
+ String.class,
+ Parameters.class,
+ Configuration.class,
+ ContextDirective.class,
+ LoggingDirective.class,
+ Type.class,
+ Mode.class
+ }
+ );
+ }
+
+ protected Constructor getConstructor()
+ {
+ return m_base;
+ }
+
/**
* Create an array of packaged {@link Profile} objects for specified
* type, loaded from specified {@link InputStream}. If the
@@ -129,7 +176,7 @@
public Profile createProfile( Type type, Configuration config )
throws Exception
{
- return buildProfile( type, config, Profile.EXPLICIT );
+ return buildProfile( type, config, Mode.EXPLICIT );
}
/**
@@ -156,13 +203,14 @@
for( int i = 0; i < profiles.length; i++ )
{
vector.add( buildProfile(
- type, profiles[ i ], Profile.PACKAGED ) );
+ type, profiles[ i ], Mode.PACKAGED ) );
}
- return (Profile[])vector.toArray( new Profile[ 0 ] );
+
+ return (Profile[])vector.toArray( (Object[]) Array.newInstance( m_clazz, 0
) );
}
private Profile buildProfile(
- Type type, Configuration profile, int mode )
+ Type type, Configuration profile, Mode mode )
throws Exception
{
@@ -180,10 +228,6 @@
// build the profile directives
//
- final boolean enabled =
- profile.getAttributeAsBoolean( "enabled", true );
- final boolean activation =
- getActivationMode( profile );
final Parameters params =
Parameters.fromConfiguration( profile.getChild( "parameters" ) );
final ContextDirective context =
@@ -195,36 +239,45 @@
// create the profile instance
//
- return new Profile(
- name, params, config, context, categories, type, enabled,
- activation, mode );
+ try
+ {
+ return (Profile) getConstructor().newInstance(
+ new Object[]{
+ name, params, config, context, categories, type, mode } );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to build profile using class: " +
m_base;
+ throw new ModelRuntimeException( error, e );
+ }
}
- /**
- * Utility method to get the activation mode for the profile.
- * If the activation attribute value is equal to "startup"
- * TRUE is returned. If the value if "lazy", FALSE is returned.
- * Otherwise the value will be resolved as a boolean.
- *
- * @param config the profile configuration
- * @return boolean TRUE if activation on startup
- */
- public boolean getActivationMode( Configuration config )
+ private Profile createImplicitProfile( Type type ) throws Exception
{
- String value =
- config.getAttribute( "activation", "lazy" );
- if( value.equalsIgnoreCase( "startup" ) )
+ ContextDirective context =
+ new ContextDirective(
+ ContextDirective.DEFAULT_CONTEXT_CLASS,
+ new Import[ 0 ], new Entry[ 0 ] );
+ final Configuration defaults =
+ new DefaultConfiguration( "default", null );
+ final LoggingDirective categories =
+ createDefaultLoggingDirective( type );
+
+ try
{
- return true;
+ return (Profile) getConstructor().newInstance(
+ new Object[]{ null, null, defaults, context, categories, type,
Mode.IMPLICIT } );
}
- if( value.equalsIgnoreCase( "lazy" ) )
+ catch( Throwable e )
{
- return false;
+ final String error =
+ "Unexpected error while attempting to build implicit profile using
class: " + m_base;
+ throw new ModelRuntimeException( error, e );
}
- return config.getAttributeAsBoolean(
- "activation", false );
}
+
/**
* Utility method to create a new context directive.
*
@@ -420,23 +473,6 @@
final String priority = config.getAttribute( "priority", null );
final String target = config.getAttribute( "target", null );
return new Category( name, priority, target );
- }
-
- private Profile createImplicitProfile( Type type ) throws Exception
- {
- ContextDirective context =
- new ContextDirective(
- ContextDirective.DEFAULT_CONTEXT_CLASS,
- new Import[ 0 ], new Entry[ 0 ] );
- final Configuration defaults =
- new DefaultConfiguration( "default", null );
- final LoggingDirective categories =
- createDefaultLoggingDirective( type );
-
- return new Profile(
- null, null, defaults, context, categories, type, true, false,
- Profile.IMPLICIT
- );
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>