Author: niclas
Date: Sat Jul 31 10:20:26 2004
New Revision: 31046
Modified:
avalon/trunk/runtime/meta/api/src/java/org/apache/avalon/meta/info/Type.java
avalon/trunk/runtime/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java
avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/TypeBuilder.java
avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
avalon/trunk/runtime/meta/spi/src/java/org/apache/avalon/meta/info/builder/TypeFactory.java
Log:
Added Parameters override support in Meta.
Modified: avalon/trunk/runtime/meta/api/src/java/org/apache/avalon/meta/info/Type.java
==============================================================================
--- avalon/trunk/runtime/meta/api/src/java/org/apache/avalon/meta/info/Type.java (original)
+++ avalon/trunk/runtime/meta/api/src/java/org/apache/avalon/meta/info/Type.java Sat Jul 31 10:20:26 2004
@@ -20,6 +20,7 @@
import java.io.Serializable;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.parameters.Parameters;
/**
* This class contains the meta information about a particular
@@ -52,6 +53,7 @@
private final CategoryDescriptor[] m_loggers;
private final StageDescriptor[] m_stages;
private final ExtensionDescriptor[] m_extensions;
+ private final Parameters m_parameters;
/**
* Creation of a new Type instance using a supplied component descriptor,
@@ -156,6 +158,47 @@
final Configuration defaults )
throws NullPointerException
{
+ this(
+ descriptor, security, loggers, context, services, dependencies,
+ stages, extensions, defaults, null );
+ }
+
+ /**
+ * Creation of a new Type instance using a supplied component descriptor,
+ * logging, cotext, services, depedencies, stages and extension descriptors.
+ * @param descriptor a component descriptor that contains information about
+ * the component type
+ * @param security a component security descriptor
+ * @param loggers a set of logger descriptors the declare the logging channels
+ * required by the type
+ * @param context a component context descriptor that declares the context type
+ * and context entry key and value classnames
+ * @param services a set of service descriprors that detail the service that
+ * this component type is capable of supplying
+ * @param dependencies a set of depedency descriprors that detail the service
+ * that this component type is depedent on
+ * @param stages a set of stage descriprors that detail the extensiuon stage
+ * interfaces that this component requires a handler for
+ * @param extensions a set of lifecycle extension capabilities that this
+ * componet can provide to its container during the process of stage
+ * suppier resolution
+ * @param defaults the static configuration defaults
+ * @param params static parameter defaults
+ * @exception NullPointerException if the descriptor, loggers, context, services,
+ * dependencies, stages, or extensions argument is null
+ */
+ public Type( final InfoDescriptor descriptor,
+ final SecurityDescriptor security,
+ final CategoryDescriptor[] loggers,
+ final ContextDescriptor context,
+ final ServiceDescriptor[] services,
+ final DependencyDescriptor[] dependencies,
+ final StageDescriptor[] stages,
+ final ExtensionDescriptor[] extensions,
+ final Configuration defaults,
+ final Parameters params )
+ throws NullPointerException
+ {
if ( null == descriptor )
{
throw new NullPointerException( "descriptor" );
@@ -198,6 +241,7 @@
m_stages = stages;
m_extensions = extensions;
m_configuration = defaults;
+ m_parameters = params;
}
/**
@@ -348,6 +392,17 @@
}
/**
+ * Returns the default parameters supplied with the type.
+ *
+ * @return the default parameters or null if no packaged defaults
+ */
+ public Parameters getParameters()
+ {
+ return m_parameters;
+ }
+
+
+ /**
* Return the lifecycle stages extensions required by this component type.
*
* @return an array of stage descriptors.
@@ -414,6 +469,9 @@
*/
public boolean equals(Object other)
{
+ if( null == other )
+ return false;
+
if( ! (other instanceof Type ) )
return false;
@@ -425,9 +483,28 @@
if( ! m_security.equals( t.m_security ) )
return false;
- if( ! m_configuration.equals( t.m_configuration ) )
+ if( null == m_configuration )
+ {
+ if( ! ( null == t.m_configuration ) )
+ return false;
+ }
+ else
+ {
+ if( ! m_configuration.equals( t.m_configuration ) )
return false;
-
+ }
+
+ if( null == m_parameters )
+ {
+ if( ! ( null == t.m_parameters ) )
+ return false;
+ }
+ else
+ {
+ if( ! m_parameters.equals( t.m_parameters ) )
+ return false;
+ }
+
if( ! m_context.equals( t.m_context ) )
return false;
@@ -471,11 +548,19 @@
hash >>>= 13;
hash ^= m_context.hashCode();
hash >>>= 13;
+
if( m_configuration != null )
{
- hash ^= m_context.hashCode();
+ hash ^= m_configuration.hashCode();
hash >>>= 13;
}
+
+ if( m_parameters != null )
+ {
+ hash ^= m_parameters.hashCode();
+ hash >>>= 13;
+ }
+
hash >>>= 13;
for( int i=0; i<m_services.length; i++ )
{
Modified: avalon/trunk/runtime/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java
==============================================================================
--- avalon/trunk/runtime/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java (original)
+++ avalon/trunk/runtime/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java Sat Jul 31 10:20:26 2004
@@ -21,6 +21,7 @@
import org.apache.avalon.meta.info.*;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.parameters.Parameters;
import java.util.Properties;
import java.io.*;
@@ -42,6 +43,7 @@
private StageDescriptor[] m_stages;
private ExtensionDescriptor[] m_extensions;
private Configuration m_defaults;
+ private Parameters m_parameters;
private ReferenceDescriptor m_reference;
private String m_key;
@@ -74,6 +76,7 @@
new ExtensionDescriptor( m_key )
};
m_defaults = new DefaultConfiguration("default");
+ m_parameters = Parameters.EMPTY_PARAMETERS;
}
private void checkType(Type type)
@@ -82,6 +85,7 @@
checkArray(m_loggers, type.getCategories());
assertEquals( m_security, type.getSecurity() );
assertEquals( m_defaults, type.getConfiguration() );
+ assertEquals( m_parameters , type.getParameters() );
assertEquals( m_context, type.getContext());
checkArray(m_dependencies, type.getDependencies());
assertEquals(m_dependencies[0], type.getDependency(m_dependencies[0].getKey()));
@@ -110,7 +114,7 @@
Type type =
new Type(
m_descriptor, m_security, m_loggers, m_context, m_services, m_dependencies,
- m_stages, m_extensions, m_defaults);
+ m_stages, m_extensions, m_defaults, m_parameters );
checkType(type);
}
@@ -119,7 +123,7 @@
Type type =
new Type(
m_descriptor, m_security, m_loggers, m_context, m_services, m_dependencies,
- m_stages, m_extensions, m_defaults );
+ m_stages, m_extensions, m_defaults, m_parameters );
checkType( type );
@@ -142,6 +146,6 @@
private static InfoDescriptor createSimpleInfo( String classname )
{
- return new InfoDescriptor( null, classname, null, null, null, null, null);
+ return new InfoDescriptor( null, classname, null, null, null, null, null );
}
}
Modified: avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/TypeBuilder.java
==============================================================================
--- avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/TypeBuilder.java (original)
+++ avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/TypeBuilder.java Sat Jul 31 10:20:26 2004
@@ -18,10 +18,14 @@
package org.apache.avalon.meta.info.builder;
import java.io.InputStream;
+import java.io.IOException;
+import java.util.Properties;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.meta.ConfigurationBuilder;
import org.apache.avalon.meta.info.Type;
@@ -177,11 +181,38 @@
defaults = new DefaultConfiguration( "configuration", (String) null );
}
+ final String xparams =
+ classname.replace( '.', '/' ) + ".xparams";
+ final InputStream paramsStream =
+ classLoader.getResourceAsStream( xparams );
+
+ Parameters params;
+ if( paramsStream != null )
+ {
+ try
+ {
+ Properties properties = new Properties();
+ properties.load( paramsStream );
+ params = Parameters.fromProperties( properties );
+ }
+ catch( IOException ioe )
+ {
+ final String error =
+ "Unexpected exception while attempting to resolve parameters from src: "
+ + xparams;
+ throw new ParameterException( error );
+ }
+ }
+ else
+ {
+ params = null;
+ }
+
//
// build the type
//
- return xmlTypeFactory.createType( classname, xinfo, defaults );
+ return xmlTypeFactory.createType( classname, xinfo, defaults, params );
}
private Configuration resolveConfiguration( ClassLoader classloader, Configuration config )
Modified: avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
==============================================================================
--- avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java (original)
+++ avalon/trunk/runtime/meta/impl/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java Sat Jul 31 10:20:26 2004
@@ -22,6 +22,7 @@
import java.util.Properties;
import org.apache.avalon.framework.Version;
+import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -79,7 +80,24 @@
final InputSource input = new InputSource( inputStream );
final Configuration xinfo = ConfigurationBuilder.build( input );
- return createType( classname, xinfo, (Configuration) null );
+ return createType( classname, xinfo, (Configuration) null, null );
+ }
+
+ /**
+ * Create an {@link Type} object for a specified classname from
+ * specified configuration data.
+ *
+ * @param classname The classname of Component
+ * @param info the Type configuration
+ * @param defaults the default configuration
+ * @return the created Type
+ * @throws BuildException if an error occurs
+ */
+ public Type createType(
+ final String classname, final Configuration info, final Configuration defaults )
+ throws BuildException
+ {
+ return createType( classname, info, defaults, null );
}
/**
@@ -89,11 +107,13 @@
* @param classname The classname of Component
* @param info the Type configuration
* @param defaults the default configuration
+ * @param params the default static parameters
* @return the created Type
- * @throws Exception if an error occurs
+ * @throws BuildException if an error occurs
*/
public Type createType(
- final String classname, final Configuration info, final Configuration defaults )
+ final String classname, final Configuration info, final Configuration defaults,
+ Parameters params )
throws BuildException
{
final String topLevelName = info.getName();
@@ -149,14 +169,14 @@
return new Type(
descriptor, security, loggers, context, services, dependencies, phases,
- extensions, defaults );
+ extensions, defaults, params );
}
/**
* Utility function to create a set of phase descriptor from a configuration.
* @param config a configuration containing 0..n phase elements
* @return an array of phase descriptors
- * @exception Exception if a build error occurs
+ * @exception BuildException if a build error occurs
*/
protected StageDescriptor[] buildStages( Configuration config )
throws BuildException
@@ -175,7 +195,7 @@
* Utility function to create a set of phase descriptor from a configuration.
* @param config a configuration containing 0..n phase elements
* @return an array of phase descriptors
- * @exception Exception if a build error occurs
+ * @exception BuildException if a build error occurs
*/
protected StageDescriptor buildPhase( Configuration config )
throws BuildException
@@ -214,7 +234,7 @@
*
* @param service the service Configuration
* @return the created ReferenceDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
protected ReferenceDescriptor buildReferenceDescriptor( final Configuration service )
throws BuildException
@@ -229,7 +249,7 @@
* @param service the service Configuration
* @param classname the default type classname
* @return the created ReferenceDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
protected ReferenceDescriptor buildReferenceDescriptor( final Configuration service, String classname )
throws BuildException
@@ -257,7 +277,7 @@
*
* @param configuration the loggers configuration
* @return the created CategoryDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
protected CategoryDescriptor[] buildLoggers( final Configuration configuration )
throws BuildException
@@ -280,7 +300,7 @@
*
* @param logger the Logger configuration
* @return the created CategoryDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
private CategoryDescriptor buildLogger( Configuration logger )
throws BuildException
@@ -296,7 +316,7 @@
*
* @param configuration the dependencies configuration
* @return the created DependencyDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
public DependencyDescriptor[] buildDependencies( final Configuration configuration )
throws BuildException
@@ -335,8 +355,7 @@
final boolean optional =
dependency.getAttributeAsBoolean( "optional", false );
- final int index =
- dependency.getAttributeAsInteger( "index", -1 );
+
final Properties attributes =
buildAttributes( dependency.getChild( "attributes" ) );
@@ -358,7 +377,7 @@
*
* @param context the dependency configuration
* @return the created ContextDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
protected ContextDescriptor buildContext( final Configuration context )
throws BuildException
@@ -381,7 +400,7 @@
*
* @param servicesSet the services configuration
* @return the created ServiceDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
public ServiceDescriptor[] buildServices( final Configuration servicesSet )
throws BuildException
@@ -404,7 +423,7 @@
*
* @param service the service Configuration
* @return the created ServiceDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
public ServiceDescriptor buildService( final Configuration service )
throws BuildException
@@ -422,7 +441,7 @@
* @param classname The classname of Component (used to create descriptor)
* @param info the component info configuration fragment
* @return the created InfoDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
public InfoDescriptor buildInfoDescriptor(
final String classname, final Configuration info )
@@ -452,7 +471,7 @@
*
* @param config the security configuration fragment
* @return the created SecurityDescriptor
- * @throws ConfigurationException if an error occurs
+ * @throws BuildException if an error occurs
*/
public SecurityDescriptor buildSecurityDescriptor( final Configuration config )
throws BuildException
@@ -531,7 +550,7 @@
* Utility function to create a set of phase descriptor from a configuration.
* @param config a configuration containing 0..n phase elements
* @return an array of phase descriptors
- * @exception Exception if a build error occurs
+ * @exception BuildException if a build error occurs
*/
protected ExtensionDescriptor[] buildExtensions( Configuration config )
throws BuildException
@@ -549,7 +568,7 @@
* Utility function to create an extension descriptor from a configuration.
* @param config a configuration containing the extension definition
* @return the extension descriptor
- * @exception Exception if a build error occurs
+ * @exception BuildException if a build error occurs
*/
protected ExtensionDescriptor buildExtension( Configuration config )
throws BuildException
Modified: avalon/trunk/runtime/meta/spi/src/java/org/apache/avalon/meta/info/builder/TypeFactory.java
==============================================================================
--- avalon/trunk/runtime/meta/spi/src/java/org/apache/avalon/meta/info/builder/TypeFactory.java (original)
+++ avalon/trunk/runtime/meta/spi/src/java/org/apache/avalon/meta/info/builder/TypeFactory.java Sat Jul 31 10:20:26 2004
@@ -19,6 +19,7 @@
import org.apache.avalon.meta.info.Type;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.parameters.Parameters;
/**
* Simple interface used to create {@link Type}
@@ -43,5 +44,19 @@
*/
Type createType( String path, Configuration xinfo, Configuration defaults )
throws Exception;
+
+ /**
+ * Create a {@link Type} using a supplied type configuration and default configuration
+ *
+ * @param path the class resource name of component type that we are looking up
+ * @param xinfo the configuration fragment for the type
+ * @param defaults the configuration fragment for the default configuration
+ * @param params the default parameters
+ * @return the newly created {@link Type}
+ * @exception Exception if an error occurs
+ */
+ Type createType( String path, Configuration xinfo, Configuration defaults, Parameters params )
+ throws Exception;
+
}
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.