mcconnell 2002/06/10 20:26:56
Modified: merlin build.xml
merlin/src/conf MANIFEST.MF
merlin/src/java/org/apache/excalibur/merlin
ServiceLoader.java ServiceLoader.xinfo
UnitInfo.java
Added: merlin/src/java/org/apache/excalibur/assembly/demo
BasicComponent.java BasicComponent.xinfo
BasicService.java ComplexComponent.java
ComplexComponent.xinfo SimpleComponent.java
SimpleComponent.xinfo SimpleService.java
merlin/src/java/org/apache/excalibur/configuration
CascadingConfiguration.java ConfigurationUtil.java
package.html
merlin/src/java/org/apache/excalibur/context
ContextUtility.java
Log:
no message
Revision Changes Path
1.5 +18 -4 jakarta-avalon-excalibur/merlin/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/merlin/build.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- build.xml 12 May 2002 13:43:54 -0000 1.4
+++ build.xml 11 Jun 2002 03:26:55 -0000 1.5
@@ -14,14 +14,11 @@
<pathelement location="${build.classes}"/>
<pathelement location="${avalon-framework.jar}"/>
<pathelement location="${logkit.jar}"/>
- <pathelement location="${excalibur-configuration.jar}"/>
- <pathelement location="${excalibur-context.jar}"/>
- <pathelement location="${logkit.jar}"/>
- <pathelement location="${checkstyle.jar}"/>
<pathelement path="${java.class.path}"/>
</path>
<path id="tools.class.path">
+ <pathelement location="${checkstyle.jar}"/>
<pathelement location="${junit.jar}"/>
<pathelement location="${tools.jar}"/>
<fileset dir="${tools.dir}/lib"/>
@@ -133,6 +130,7 @@
compress="${build.compress}"
manifest="${build.conf}/MANIFEST.MF">
<exclude name="**/test/**"/>
+ <exclude name="**/demo/**"/>
<zipfileset dir="${build.conf}" prefix="META-INF/">
<include name="LICENSE.txt"/>
</zipfileset>
@@ -140,6 +138,22 @@
<!-- add Merlin specific properties file -->
<zipfileset dir="${conf.dir}">
<include name="merlin.properties"/>
+ </zipfileset>
+ </jar>
+ <jar jarfile="${build.lib}/excalibur-configuration-1.0.jar"
+ basedir="${build.classes}"
+ compress="${build.compress}">
+ <include name="**/configuration/**"/>
+ <zipfileset dir="${build.conf}" prefix="META-INF/">
+ <include name="LICENSE.txt"/>
+ </zipfileset>
+ </jar>
+ <jar jarfile="${build.lib}/demo.jar"
+ basedir="${build.classes}"
+ compress="${build.compress}">
+ <include name="**/demo/**"/>
+ <zipfileset dir="${build.conf}" prefix="META-INF/">
+ <include name="LICENSE.txt"/>
</zipfileset>
</jar>
</target>
1.3 +1 -1 jakarta-avalon-excalibur/merlin/src/conf/MANIFEST.MF
Index: MANIFEST.MF
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/merlin/src/conf/MANIFEST.MF,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MANIFEST.MF 14 May 2002 07:27:52 -0000 1.2
+++ MANIFEST.MF 11 Jun 2002 03:26:55 -0000 1.3
@@ -4,7 +4,7 @@
Implementation-Vendor: Apache Software Foundation
Implementation-Version: @package-version@
Main-Class: org.apache.excalibur.merlin.ServiceLoader
-Class-Path: excalibur-configuration.jar excalibur-context.jar
+Class-Path: avalon-framework.jar logkit.jar
Name: org/apache/excalibur/merlin/ServiceLoader.class
Avalon-Block: true
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/BasicComponent.java
Index: BasicComponent.java
===================================================================
package org.apache.excalibur.assembly.demo;
import java.io.File;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Executable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configuration;
/**
* This is a minimal demonstration service that has no dependencies.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class BasicComponent extends AbstractLogEnabled
implements BasicService
{
//=======================================================================
// BasicService
//=======================================================================
public void doPrimeObjective()
{
getLogger().info("executing basic objective");
}
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/BasicComponent.xinfo
Index: BasicComponent.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<block>
<name>basic-component</name>
</block>
<services>
<service name="org.apache.excalibur.assembly.demo.BasicService"/>
</services>
</blockinfo>
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/BasicService.java
Index: BasicService.java
===================================================================
/*
*/
package org.apache.excalibur.assembly.demo;
import org.apache.avalon.framework.activity.Executable;
/**
* <code>BasicService</code>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public interface BasicService
{
/**
* Execute the prime objective of this services.
*/
void doPrimeObjective();
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/ComplexComponent.java
Index: ComplexComponent.java
===================================================================
/*
* ExampleBlock.java
*/
package org.apache.excalibur.assembly.demo;
import java.io.File;
import org.apache.avalon.framework.CascadingException;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.LogEnabled;
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.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.activity.Executable;
/**
* This is a minimal demonstration component that has a single dependency.
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class ComplexComponent extends AbstractLogEnabled
implements Serviceable, Initializable, Executable, Disposable
{
private ServiceManager m_manager;
private SimpleService m_simple;
//=================================================================
// Serviceable
//=================================================================
/**
* Pass the <code>ServiceManager</code> to the <code>Serviceable</code>.
* The <code>Serviceable</code> implementation uses the specified
* <code>ServiceManager</code> to acquire the services it needs for
* execution.
*
* @param manager The <code>ServiceManager</code> which this
* <code>Serviceable</code> uses.
*/
public void service( ServiceManager manager )
throws ServiceException
{
m_manager = manager;
}
//=======================================================================
// Initializable
//=======================================================================
public void initialize()
throws Exception
{
//
// verify current state
//
if( getLogger() == null ) throw new IllegalStateException(
"Logging channel has not been assigned.");
if( m_manager == null ) throw new IllegalStateException(
"Manager has not been declared.");
//
// lookup the primary service
//
m_simple = (SimpleService) m_manager.lookup( "simple" );
}
//=======================================================================
// Executable
//=======================================================================
public void execute()
{
getLogger().info("executing complex action");
m_simple.doPrimeObjective();
}
//=======================================================================
// Disposable
//=======================================================================
public void dispose()
{
m_simple = null;
m_manager = null;
}
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/ComplexComponent.xinfo
Index: ComplexComponent.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<block>
<name>complex-component</name>
</block>
<dependencies>
<dependency>
<role>simple</role>
<service name="org.apache.excalibur.assembly.demo.SimpleService"/>
</dependency>
<dependency>
<role>basic</role>
<service name="org.apache.excalibur.assembly.demo.BasicService"/>
</dependency>
</dependencies>
</blockinfo>
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/SimpleComponent.java
Index: SimpleComponent.java
===================================================================
package org.apache.excalibur.assembly.demo;
import java.io.File;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Executable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configuration;
/**
* This is a minimal demonstration service that has no dependencies.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class SimpleComponent extends AbstractLogEnabled
implements SimpleService
{
//=======================================================================
// PrimaryService
//=======================================================================
public void doPrimeObjective()
{
getLogger().info("executing prime objective");
}
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/SimpleComponent.xinfo
Index: SimpleComponent.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<block>
<name>simple-component</name>
</block>
<services>
<service name="org.apache.excalibur.assembly.demo.SimpleService"/>
</services>
<dependencies>
<dependency>
<role>basic</role>
<service name="org.apache.excalibur.assembly.demo.BasicService"/>
</dependency>
</dependencies>
</blockinfo>
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/assembly/demo/SimpleService.java
Index: SimpleService.java
===================================================================
/*
*/
package org.apache.excalibur.assembly.demo;
import org.apache.avalon.framework.activity.Executable;
/**
* <code>SimpleService</code>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public interface SimpleService
{
/**
* Execute the prime objective of this services.
*/
void doPrimeObjective();
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/configuration/CascadingConfiguration.java
Index: CascadingConfiguration.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.
*
* Original contribution by OSM SARL, http://www.osm.net
*/
package org.apache.excalibur.configuration;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
/**
* The CascadingConfiguration is a classic Configuration backed by parent
* Configuration. Operations such as getChild return a CascadingConfiguration
* encapsulating both a primary and parent configuration. Requests for
attribute
* values are resolved against the base configuration initially. If the
result
* of the resolution is unsucessful, the request is applied against the parent
* configuration. As a parent may also be a CascadingConfiguration, the
evaluation
* will be applied until a value is resolved against a class parent
Configuration.
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
public class CascadingConfiguration implements Configuration
{
//=============================================================================
// state
//=============================================================================
/**
* The primary configuration.
*/
private final Configuration m_base;
/**
* The fallback configuration.
*/
private final Configuration m_parent;
//=============================================================================
// constructors
//=============================================================================
/**
* Create a CascadingConfiguration with specified parent. The base
* configuration shall override a parent configuration on request for
* attribute values and configuration body values. Unresolved request
* are redirected up the parent chain until a classic configuration is
* reached. Request for child configurations will return a
* new CascadingConfiguration referencing the child of the base and
* the child of the primary (i.e. a child configuration chain).
*
* @param base the base Configuration
* @param parent the parent Configuration
*/
public CascadingConfiguration( final Configuration base, final
Configuration parent )
{
if( base == null )
{
m_base = new DefaultConfiguration( "-", null );
}
else
{
m_base = base;
}
if( parent == null )
{
m_parent = new DefaultConfiguration( "-", null );
}
else
{
m_parent = parent;
}
}
//=============================================================================
// Configuration
//=============================================================================
/**
* Return the name of the base node.
* @return name of the <code>Configuration</code> node.
*/
public String getName()
{
return m_base.getName();
}
/**
* Return a string describing location of the base Configuration.
* Location can be different for different mediums (ie "file:line" for
normal XML files or
* "table:primary-key" for DB based configurations);
*
* @return a string describing location of Configuration
*/
public String getLocation()
{
return m_base.getLocation();
}
/**
* Returns the namespace the main Configuration node
* belongs to.
* @exception ConfigurationException may be thrown by the underlying
configuration
* @since 4.1
* @return a Namespace identifying the namespace of this Configuration.
*/
public String getNamespace() throws ConfigurationException
{
return m_base.getNamespace();
}
/**
* Return a new <code>CascadingConfiguration</code> instance
encapsulating the
* specified child node of the base and parent node.
*
* @param child The name of the child node.
* @return Configuration
*/
public Configuration getChild( String child )
{
return new CascadingConfiguration( m_base.getChild( child ),
m_parent.getChild( child ) );
}
/**
* Return a <code>Configuration</code> instance encapsulating the
specified
* child node.
*
* @param child The name of the child node.
* @param createNew If <code>true</code>, a new <code>Configuration</code>
* will be created and returned if the specified child does not exist in
either
* the base or parent configuratioin. If <code>false</code>,
<code>null</code>
* will be returned when the specified child doesn't exist in either the
base or
* the parent.
* @return Configuration
*/
public Configuration getChild( String child, boolean createNew )
{
if( createNew )
{
return getChild( child );
}
Configuration c = m_base.getChild( child, false );
if( child != null )
{
return c;
}
return m_parent.getChild( child, false );
}
/**
* Return an <code>Array</code> of <code>Configuration</code>
* elements containing all node children of both base and parent
configurations.
* The array order will reflect the order in the source config file,
commencing
* with the base configuration.
*
* @return All child nodes
*/
public Configuration[] getChildren()
{
Configuration[] b = m_base.getChildren();
Configuration[] p = m_parent.getChildren();
Configuration[] result = new Configuration[ b.length + p.length ];
System.arraycopy( b, 0, result, 0, b.length );
System.arraycopy( p, 0, result, b.length, p.length );
return result;
}
/**
* Return an <code>Array</code> of <code>Configuration</code>
* elements containing all node children with the specified name from
* both base and parent configurations. The array
* order will reflect the order in the source config file commencing
* with the base configuration.
*
* @param name The name of the children to get.
* @return The child nodes with name <code>name</code>
*/
public Configuration[] getChildren( String name )
{
Configuration[] b = m_base.getChildren( name );
Configuration[] p = m_parent.getChildren( name );
Configuration[] result = new Configuration[ b.length + p.length ];
System.arraycopy( b, 0, result, 0, b.length );
System.arraycopy( p, 0, result, b.length, p.length );
return result;
}
/**
* Return an array of all attribute names in both base and parent.
* <p>
* <em>The order of attributes in this array can not be relied on.</em> As
* with XML, a <code>Configuration</code>'s attributes are an
* <em>unordered</em> set. If your code relies on order, eg
* <tt>conf.getAttributeNames()[0]</tt>, then it is liable to break if a
* different XML parser is used.
* </p>
* @return an array of all attribute names
*/
public String[] getAttributeNames()
{
java.util.Vector vector = new java.util.Vector();
String[] names = m_base.getAttributeNames();
String[] names2 = m_parent.getAttributeNames();
for( int i = 0; i < names.length; i++ )
{
vector.add( names[ i ] );
}
for( int i = 0; i < names2.length; i++ )
{
if( vector.indexOf( names2[ i ] ) < 0 )
{
vector.add( names2[ i ] );
}
}
return (String[])vector.toArray( new String[ 0 ] );
}
/**
* Return the value of specified attribute. If the base configuration
* does not contain the attribute, the equivialent operation is applied to
* the parent configuration.
*
* @param paramName The name of the parameter you ask the value of.
* @return String value of attribute.
* @exception ConfigurationException If no attribute with that name
exists.
*/
public String getAttribute( String paramName ) throws
ConfigurationException
{
try
{
return m_base.getAttribute( paramName );
}
catch( ConfigurationException e )
{
return m_parent.getAttribute( paramName );
}
}
/**
* Return the <code>int</code> value of the specified attribute contained
* in this node or the parent.
* @param paramName The name of the parameter you ask the value of.
* @return int value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to <code>int</code>
fails.
*/
public int getAttributeAsInteger( String paramName ) throws
ConfigurationException
{
try
{
return m_base.getAttributeAsInteger( paramName );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsInteger( paramName );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>long</code>.
*
* @param name The name of the parameter you ask the value of.
* @return long value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to
<code>long</code> fails.
*/
public long getAttributeAsLong( String name ) throws
ConfigurationException
{
try
{
return m_base.getAttributeAsLong( name );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsLong( name );
}
}
/**
* Return the <code>float</code> value of the specified parameter
contained
* in this node.
* @param paramName The name of the parameter you ask the value of.
* @return float value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to
<code>float</code> fails.
*/
public float getAttributeAsFloat( String paramName ) throws
ConfigurationException
{
try
{
return m_base.getAttributeAsFloat( paramName );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsFloat( paramName );
}
}
/**
* Return the <code>boolean</code> value of the specified parameter
contained
* in this node.<br>
*
* @param paramName The name of the parameter you ask the value of.
* @return boolean value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to
<code>boolean</code> fails.
*/
public boolean getAttributeAsBoolean( String paramName ) throws
ConfigurationException
{
try
{
return m_base.getAttributeAsBoolean( paramName );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsBoolean( paramName );
}
}
/**
* Return the <code>String</code> value of the node.
*
* @return the value of the node.
* @exception ConfigurationException May be raised by underlying
* base or parent configuration.
*/
public String getValue() throws ConfigurationException
{
try
{
return m_base.getValue();
}
catch( ConfigurationException e )
{
return m_parent.getValue();
}
}
/**
* Return the <code>int</code> value of the node.
* @return int the value as an integer
* @exception ConfigurationException If conversion to <code>int</code>
fails.
*/
public int getValueAsInteger() throws ConfigurationException
{
try
{
return m_base.getValueAsInteger();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsInteger();
}
}
/**
* Return the <code>float</code> value of the node.
*
* @return the value of the node.
* @exception ConfigurationException If conversion to <code>float</code>
fails.
*/
public float getValueAsFloat() throws ConfigurationException
{
try
{
return m_base.getValueAsFloat();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsFloat();
}
}
/**
* Return the <code>boolean</code> value of the node.
*
* @return the value of the node.
* @exception ConfigurationException If conversion to
<code>boolean</code> fails.
*/
public boolean getValueAsBoolean() throws ConfigurationException
{
try
{
return m_base.getValueAsBoolean();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsBoolean();
}
}
/**
* Return the <code>long</code> value of the node.<br>
*
* @return the value of the node.
* @exception ConfigurationException If conversion to <code>long</code>
fails.
*/
public long getValueAsLong() throws ConfigurationException
{
try
{
return m_base.getValueAsLong();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsLong();
}
}
/**
* Returns the value of the configuration element as a
<code>String</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @param defaultValue The default value desired.
* @return String value of the <code>Configuration</code>, or default
* if none specified.
*/
public String getValue( String defaultValue )
{
try
{
return m_base.getValue();
}
catch( ConfigurationException e )
{
return m_parent.getValue( defaultValue );
}
}
/**
* Returns the value of the configuration element as an <code>int</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @param defaultValue The default value desired.
* @return int value of the <code>Configuration</code>, or default
* if none specified.
*/
public int getValueAsInteger( int defaultValue )
{
try
{
return m_base.getValueAsInteger();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsInteger( defaultValue );
}
}
/**
* Returns the value of the configuration element as a <code>long</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @param defaultValue The default value desired.
* @return long value of the <code>Configuration</code>, or default
* if none specified.
*/
public long getValueAsLong( long defaultValue )
{
try
{
return m_base.getValueAsLong();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsLong( defaultValue );
}
}
/**
* Returns the value of the configuration element as a <code>float</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @param defaultValue The default value desired.
* @return float value of the <code>Configuration</code>, or default
* if none specified.
*/
public float getValueAsFloat( float defaultValue )
{
try
{
return m_base.getValueAsFloat();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsFloat( defaultValue );
}
}
/**
* Returns the value of the configuration element as a
<code>boolean</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @param defaultValue The default value desired.
* @return boolean value of the <code>Configuration</code>, or default
* if none specified.
*/
public boolean getValueAsBoolean( boolean defaultValue )
{
try
{
return m_base.getValueAsBoolean();
}
catch( ConfigurationException e )
{
return m_parent.getValueAsBoolean( defaultValue );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>String</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return String value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
public String getAttribute( String name, String defaultValue )
{
try
{
return m_base.getAttribute( name );
}
catch( ConfigurationException e )
{
return m_parent.getAttribute( name, defaultValue );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>int</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return int value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
public int getAttributeAsInteger( String name, int defaultValue )
{
try
{
return m_base.getAttributeAsInteger( name );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsInteger( name, defaultValue );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>long</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return long value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
public long getAttributeAsLong( String name, long defaultValue )
{
try
{
return m_base.getAttributeAsLong( name );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsLong( name, defaultValue );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>float</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return float value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
public float getAttributeAsFloat( String name, float defaultValue )
{
try
{
return m_base.getAttributeAsFloat( name );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsFloat( name, defaultValue );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>boolean</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return boolean value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
public boolean getAttributeAsBoolean( String name, boolean defaultValue )
{
try
{
return m_base.getAttributeAsBoolean( name );
}
catch( ConfigurationException e )
{
return m_parent.getAttributeAsBoolean( name, defaultValue );
}
}
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/configuration/ConfigurationUtil.java
Index: ConfigurationUtil.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.
*
* Original contribution by OSM SARL, http://www.osm.net
*/
package org.apache.excalibur.configuration;
import org.apache.avalon.framework.configuration.Configuration;
/**
* General utility supporting static operations for generating string
* representations of a configuration suitable for debugging.
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
public class ConfigurationUtil
{
/**
* Returns a simple string representation of the the supplied
configuration.
* @param config a configuration
* @return a simplified text representation of a configuration suitable
* for debugging
*/
public static String list( Configuration config )
{
final StringBuffer buffer = new StringBuffer();
list( buffer, " ", config );
buffer.append( "\n" );
return buffer.toString();
}
private static void list( StringBuffer buffer, String lead, Configuration
config )
{
buffer.append( "\n" + lead + "<" + config.getName() );
String[] names = config.getAttributeNames();
if( names.length > 0 )
{
for( int i = 0; i < names.length; i++ )
{
buffer.append( " "
+ names[ i ] + "=\""
+ config.getAttribute( names[ i ], "???" ) +
"\"" );
}
}
Configuration[] children = config.getChildren();
if( children.length > 0 )
{
buffer.append( ">" );
for( int j = 0; j < children.length; j++ )
{
list( buffer, lead + " ", children[ j ] );
}
buffer.append( "\n" + lead + "</" + config.getName() + ">" );
}
else
{
if( config.getValue( null ) != null )
{
buffer.append( ">...</" + config.getName() + ">" );
}
else
{
buffer.append( "/>" );
}
}
}
}
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/configuration/package.html
Index: package.html
===================================================================
<body>
<p>Resource supporting extended configuration management.</p>
</body>
1.1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/context/ContextUtility.java
Index: ContextUtility.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.context;
import java.lang.reflect.Constructor;
import java.util.Hashtable;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.Logger;
/**
* @version $Id: ContextUtility.java,v 1.1 2002/06/11 03:26:55 mcconnell Exp $
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
public class ContextUtility
{
//==========================================================
// context utilities
//==========================================================
/**
* Create context-attributes from entrys within <context/>-tag in config
* @param config the context configuration
* @return Context a context instance
* @exception ConfigurationException if a context related error occurs
*/
public static Context createContextFromConfiguration( Configuration
config )
throws ConfigurationException
{
return createContextFromConfiguration( null, config );
}
/**
* Create context-attributes from entrys within <context/>-tag in config
* @param parent the parent context
* @param config the configuration element describing the context
parameters
* @return Context a context instance
* @exception ConfigurationException if a context related error occurs
*/
public static Context createContextFromConfiguration(
Context parent, Configuration config )
throws ConfigurationException
{
return createContextFromConfiguration( parent, config, null );
}
/**
* Create context-attributes from entrys within <context/>-tag in config
* @param parent the parent context
* @param config the configuration element describing the context
parameters
* @param log a logging channel
* @return Context a context instance
* @exception ConfigurationException if a context related error occurs
*/
public static Context createContextFromConfiguration(
Context parent, Configuration config, Logger log )
throws ConfigurationException
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String contextClassName = config.getAttribute( "class",
"org.apache.avalon.framework.context.DefaultContext" );
Class contextClass = null;
try
{
contextClass = loader.loadClass( contextClassName );
}
catch( ClassNotFoundException cnfe )
{
throw new ConfigurationException(
"Could not find context class " + contextClassName, cnfe );
}
Map map = new Hashtable();
Context context = null;
try
{
Constructor constructor = contextClass.getConstructor(
new Class[]{Map.class, Context.class} );
context = (Context)constructor.newInstance( new Object[]{map,
parent} );
}
catch( Throwable e )
{
throw new ConfigurationException(
"Unexpected exception while creating custom context form "
+ contextClassName, e );
}
final Configuration[] entrys = config.getChildren( "entry" );
for( int i = 0; i < entrys.length; i++ )
{
final String className = entrys[ i ].getAttribute(
"type", "java.lang.String" );
final String paramName = entrys[ i ].getAttribute(
"name", null );
if( paramName == null )
{
throw new ConfigurationException(
"missing name for context-entry" );
}
try
{
Class[] params;
Object[] values;
Configuration entry = entrys[ i ];
if( entry.getAttribute( "value", null ) != null )
{
// Single argument String-constructor
params = new Class[ 1 ];
params[ 0 ] = Class.forName( "java.lang.String" );
Class[] consObjects = {Class.forName( "java.lang.String"
)};
Constructor cons = params[ 0 ].getConstructor(
consObjects );
values = new Object[ 1 ];
Object[] consValues = {
getContextValue( map, entry.getAttribute( "value" ) )
};
values[ 0 ] = cons.newInstance( consValues );
if( log != null )
{
log.debug( "add context-attr '" + paramName
+ "' class '" + className
+ "' with value '" + consValues[ 0 ] + "'"
);
}
}
else
{
// Multiple argument constructor
Configuration[] entryChilds = entry.getChildren(
"parameter" );
params = new Class[ entryChilds.length ];
values = new Object[ entryChilds.length ];
if( log != null )
{
log.debug( "add context-attr '" + paramName
+ "' class '" + className + "' with "
+ entryChilds.length + " values" );
}
for( int p = 0; p < entryChilds.length; p++ )
{
String paramClassName = entryChilds[ p ].getAttribute(
"type", "java.lang.String" );
String paramValue = entryChilds[ p ].getAttribute(
"value", null );
if( paramValue == null )
{
if( log != null )
{
log.debug( "value" + ( p + 1 ) + ": class '"
+ paramClassName + "' no value" );
}
}
else
{
paramValue = getContextValue( map, paramValue );
if( log != null )
{
log.debug( "value" + ( p + 1 ) + ": class '"
+ paramClassName + "' value '" +
paramValue + "'" );
}
}
try
{
params[ p ] = loader.loadClass( paramClassName );
if( paramValue == null )
{
values[ p ] = params[ p ].newInstance();
}
else
{
Class[] consObjects = {Class.forName(
"java.lang.String" )};
Constructor cons = params[ p
].getConstructor( consObjects );
Object[] consValues = {paramValue};
values[ p ] = cons.newInstance( consValues );
}
}
catch( ClassNotFoundException e )
{
// Class not found
// -> perhaps a primitve class?
if( paramClassName.equals( "int" ) )
{
params[ p ] = int.class;
values[ p ] = new Integer( paramValue );
}
else if( paramClassName.equals( "short" ) )
{
params[ p ] = short.class;
values[ p ] = new Short( paramValue );
}
else if( paramClassName.equals( "long" ) )
{
params[ p ] = long.class;
values[ p ] = new Long( paramValue );
}
else if( paramClassName.equals( "byte" ) )
{
params[ p ] = byte.class;
values[ p ] = new Byte( paramValue );
}
else if( paramClassName.equals( "double" ) )
{
params[ p ] = double.class;
values[ p ] = new Double( paramValue );
}
else if( paramClassName.equals( "float" ) )
{
params[ p ] = float.class;
values[ p ] = new Float( paramValue );
}
else if( paramClassName.equals( "char" ) )
{
params[ p ] = char.class;
values[ p ] = new Character(
paramValue.charAt( 0 ) );
}
else if( paramClassName.equals( "boolean" ) )
{
params[ p ] = boolean.class;
values[ p ] = new Boolean( paramValue );
}
else
{
throw new ConfigurationException(
"incorrect type '" + paramClassName
+ "' for context-attribute '" + paramName
+ "'", e );
}
}
}
}
Class paramClass;
try
{
paramClass = loader.loadClass( className );
}
catch( final ClassNotFoundException e )
{
throw new ConfigurationException(
"incorrect type '" + className
+ "' for context-attribute '" + paramName + "'",
e );
}
Object paramInstance;
if( params.length > 0 )
{
// using param contructor
Constructor cons = paramClass.getConstructor( params );
paramInstance = cons.newInstance( values );
}
else
{
// using default constructor
paramInstance = paramClass.newInstance();
}
map.put( paramName, paramInstance );
}
catch( ConfigurationException e )
{
throw e;
}
catch( Exception e )
{
throw new ConfigurationException(
"Error add context-attribute '" + paramName
+ "' from Configuration", e );
}
}
return context;
}
/**
* Resolving an attribute value by replacing ${context-param} with
* the corresponding param out of current context.
* @param map a map
* @param rawValue a raw value
* @return String the context attribute value
* @exception ConfigurationException if context-param does not exists
*/
private static String getContextValue( Map map, String rawValue )
throws ConfigurationException
{
StringBuffer result = new StringBuffer( "" );
int i = 0;
int j = -1;
while( ( j = rawValue.indexOf( "${", i ) ) > -1 )
{
if( i < j )
{
result.append( rawValue.substring( i, j ) );
}
int k = rawValue.indexOf( '}', j );
final String ctxName = rawValue.substring( j + 2, k );
final Object ctx = map.get( ctxName );
if( ctx == null )
{
throw new ConfigurationException(
"missing entry '" + ctxName + "' in Context" );
}
result.append( ctx.toString() );
i = k + 1;
}
if( i < rawValue.length() )
{
result.append( rawValue.substring( i, rawValue.length() ) );
}
return result.toString();
}
}
1.6 +18 -1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/ServiceLoader.java
Index: ServiceLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/ServiceLoader.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServiceLoader.java 12 May 2002 13:46:57 -0000 1.5
+++ ServiceLoader.java 11 Jun 2002 03:26:55 -0000 1.6
@@ -22,6 +22,7 @@
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.activity.Executable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
@@ -513,7 +514,7 @@
* Handles association of a shutdown hook prior to execution of a normal
* pipeline process.
* @param target the name of the component class
- * @param policy if TRUE then terminate following initialization
+ * @param policy if TRUE then execute and terminate following
initialization
* @exception PipelineException if a component execution error occurs
*/
private void pipeline( String target, boolean policy ) throws
PipelineException
@@ -554,6 +555,17 @@
{
if( object != null )
{
+ if( object instanceof Executable )
+ {
+ try
+ {
+ ((Executable)object).execute();
+ }
+ catch( Throwable e )
+ {
+ getLogger().error( "execution failure:", e );
+ }
+ }
terminate( object );
dispose();
return;
@@ -674,6 +686,11 @@
PipelineClassLoader()
{
super( new URL[ 0 ],
Thread.currentThread().getContextClassLoader() );
+ }
+
+ PipelineClassLoader( ClassLoader loader )
+ {
+ super( new URL[ 0 ], loader );
}
protected void addURL( URL url )
1.2 +2 -1
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/ServiceLoader.xinfo
Index: ServiceLoader.xinfo
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/ServiceLoader.xinfo,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceLoader.xinfo 10 May 2002 17:53:09 -0000 1.1
+++ ServiceLoader.xinfo 11 Jun 2002 03:26:55 -0000 1.2
@@ -2,7 +2,8 @@
<blockinfo>
- <block name="merlin">
+ <block>
+ <name>merlin</name>
<version>1.0</version>
</block>
1.5 +18 -0
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/UnitInfo.java
Index: UnitInfo.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/UnitInfo.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- UnitInfo.java 15 May 2002 05:45:29 -0000 1.4
+++ UnitInfo.java 11 Jun 2002 03:26:55 -0000 1.5
@@ -214,6 +214,24 @@
Context context = new ServiceContext( new String[ 0 ], root );
Configuration contextConfig = xinfo.getChild( "context", false );
+
+ // get any context declarations from the runtime profile
+
+ Configuration contextConfig2 = conf.getChild( m_name ).getChild(
"context", false );
+ if( contextConfig2 != null )
+ {
+ if( contextConfig != null )
+ {
+ contextConfig = new CascadingConfiguration( contextConfig,
contextConfig2 );
+ }
+ else
+ {
+ contextConfig = contextConfig2;
+ }
+ }
+
+ // create the context value
+
if( contextConfig != null )
{
m_context = ContextUtility.createContextFromConfiguration(
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>