mcconnell 2003/08/08 15:12:19
Modified: merlin/composition/src/java/org/apache/avalon/composition/model/impl
DefaultContainmentModel.java
Added: merlin/composition/src/java/org/apache/avalon/composition/data/builder
SerializedTargetsCreator.java TargetsBuilder.java
XMLTargetsCreator.java
merlin/composition/src/test/conf targets-config.xml
targets.xml
merlin/composition/src/test/org/apache/avalon/composition/model/test
TargetsTestCase.java
merlin/composition/src/test/org/apache/avalon/composition/model/testa
ConfigurableComponent.java
ConfigurableComponent.xinfo
merlin/composition-spi/src/java/org/apache/avalon/composition/data
TargetDirective.java Targets.java
Log:
Add customization targets for Merlin 3.
Revision Changes Path
1.1
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/SerializedTargetsCreator.java
Index: SerializedTargetsCreator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, 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", "Apache Avalon", "Avalon Framework" 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 (INCLU-
DING, 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.avalon.composition.data.builder;
import java.io.InputStream;
import java.io.ObjectInputStream;
import org.apache.avalon.composition.data.Targets;
import org.apache.avalon.composition.data.builder.TargetsCreator;
/**
* Create [EMAIL PROTECTED] ContainmentProfile} from stream made up of
* serialized object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/08/08 22:12:18 $
*/
public class SerializedTargetsCreator
implements TargetsCreator
{
/**
* Create a [EMAIL PROTECTED] Targets} instance from a stream.
*
* @param inputStream the stream that the resource is loaded from
* @return the target directive
* @exception Exception if a error occurs during directive creation
*/
public Targets createTargets( InputStream inputStream )
throws Exception
{
final ObjectInputStream ois = new ObjectInputStream( inputStream );
return (Targets)ois.readObject();
}
}
1.1
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/TargetsBuilder.java
Index: TargetsBuilder.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, 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", "Apache Avalon", "Avalon Framework" 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 (INCLU-
DING, 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.avalon.composition.data.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.avalon.meta.ConfigurationBuilder;
import org.apache.avalon.composition.data.Targets;
import org.apache.avalon.composition.data.TargetDirective;
import org.apache.avalon.composition.data.MetaDataException;
import org.apache.avalon.composition.data.MetaDataRuntimeException;
import org.apache.avalon.composition.data.builder.TargetsCreator;
import org.xml.sax.InputSource;
/**
* A TargetsBuilderis responsible for building [EMAIL PROTECTED] Targets}
* objects from a configuration object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/08/08 22:12:18 $
*/
public final class TargetsBuilder implements TargetsCreator
{
private static final Resources REZ =
ResourceManager.getPackageResources( TargetsBuilder.class );
private XMLTargetsCreator m_xml =
new XMLTargetsCreator( );
private final SerializedTargetsCreator m_serial =
new SerializedTargetsCreator();
/**
* Create a [EMAIL PROTECTED] TargetDirective} from a stream.
*
* @param inputStream the stream that the resource is loaded from
* @return the target directive
* @exception Exception if a error occurs during directive creation
*/
public Targets createTargets( InputStream inputStream )
throws Exception
{
try
{
final Targets directive = buildFromSerDescriptor( inputStream);
if( null != directive )
{
return directive;
}
}
catch( Throwable e )
{
// exception case here is not clear - basically we get a
// java.io.StreamCorruptedException if wthe input stream is
// referencing an XML stream - for the moment just go ahead
// and see if we can resolve the source as an XML input but
// sooner or later we will need to update the serialized
// to return null if the source isn' a serialized source
}
return buildFromXMLDescriptor( inputStream );
}
/**
* Build Targets from the serialized format.
*
* @throws Exception if an error occurs
*/
private Targets buildFromSerDescriptor( InputStream inputStream )
throws Exception
{
return m_serial.createTargets( inputStream );
}
/**
* Build Targets from an XML descriptor.
*
* @throws Exception if an error occurs
*/
private Targets buildFromXMLDescriptor( InputStream inputStream )
throws Exception
{
final InputSource inputSource = new InputSource( inputStream );
Configuration config = ConfigurationBuilder.build( inputSource );
return m_xml.createTargets( config );
}
}
1.1
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java
Index: XMLTargetsCreator.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.avalon.composition.data.builder;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
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.composition.data.CategoriesDirective;
import org.apache.avalon.composition.data.TargetDirective;
import org.apache.avalon.composition.data.Targets;
import org.apache.avalon.composition.data.builder.TargetsCreator;
/**
* Handles internalization of an XML based description of a [EMAIL PROTECTED]
Targets}
* instance from a Configuration object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/08/08 22:12:18 $
*/
public class XMLTargetsCreator extends XMLDeploymentProfileCreator
{
/**
* Create a set of target directives from the confiugration.
* @param config the targets configuration
*/
public Targets createTargets( Configuration config )
throws Exception
{
Configuration[] children = config.getChildren( "target" );
TargetDirective[] targets = new TargetDirective[ children.length ];
for( int i=0; i<children.length; i++ )
{
targets[i] = createTargetDirective( children[i] );
}
return new Targets( targets );
}
/**
* Create a [EMAIL PROTECTED] TargetDirective} from a configuration
*
* @param config the configuration
* @return the target directive
* @exception Exception if a error occurs during profile creation
*/
private TargetDirective createTargetDirective( Configuration config )
throws Exception
{
final String name = config.getAttribute( "name" );
final Configuration conf = config.getChild( "configuration" );
CategoriesDirective categories =
getCategoriesDirective( config.getChild( "categories", false ), name );
return new TargetDirective( name, conf, categories );
}
}
1.21 +59 -4
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Index: DefaultContainmentModel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DefaultContainmentModel.java 31 Jul 2003 22:52:47 -0000 1.20
+++ DefaultContainmentModel.java 8 Aug 2003 22:12:18 -0000 1.21
@@ -464,7 +464,7 @@
/**
* Create a containment model that is derived from an external
- * source profile defition.
+ * source profile defintion.
*
* @param directive the block include directive
* @return the containment model established by the include
@@ -505,9 +505,64 @@
* Return a immediate child model relative to a supplied name.
* @return the named model or null if the name is unknown
*/
- public Model getModel( String name )
+ public Model getModel( String path )
{
- return (Model) m_models.get( name );
+ if( path.startsWith( "/" ) )
+ {
+ return getModel( path.substring( 1, path.length() ) );
+ }
+
+ int j = path.indexOf( "/" );
+ if( j > -1 )
+ {
+ String key = path.substring( 0, j );
+ if( key.equals( "" ) )
+ {
+ return this;
+ }
+ else
+ {
+ String remainder = path.substring( j+1 );
+ Model model = getModel( key );
+ if( model == null )
+ {
+ final String error =
+ "Unknown child: " + key + " in " + getQualifiedName();
+ throw new IllegalArgumentException( error );
+ }
+ else if( model instanceof ContainmentModel )
+ {
+ return ((ContainmentModel)model).getModel( remainder );
+ }
+ else
+ {
+ final String error =
+ "Bad path element: " + key + " in path: " + path;
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+ else
+ {
+ if( path.equals( "" ) )
+ {
+ return this;
+ }
+ else
+ {
+ Model model = (Model) m_models.get( path );
+ if( model == null )
+ {
+ final String error =
+ "Unknown entry: '" + path + "'.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ return model;
+ }
+ }
+ }
}
/**
1.1
avalon-sandbox/merlin/composition/src/test/conf/targets-config.xml
Index: targets-config.xml
===================================================================
<targets>
<target name="/aaa">
<configuration>
<source>External configuration target for AAA.</source>
</configuration>
</target>
<target name="/ccc/sss/xxx">
<configuration>
<source>External configuration target for XXX.</source>
</configuration>
</target>
</targets>
1.1 avalon-sandbox/merlin/composition/src/test/conf/targets.xml
Index: targets.xml
===================================================================
<container>
<classloader>
<classpath>
<fileset dir="ext">
<include>test-a.jar</include>
</fileset>
</classpath>
</classloader>
<component
class="org.apache.avalon.composition.model.testa.ConfigurableComponent"
name="aaa"/>
<component
class="org.apache.avalon.composition.model.testa.ConfigurableComponent"
name="bbb"/>
<container name="ccc">
<container name="sss">
<component
class="org.apache.avalon.composition.model.testa.ConfigurableComponent"
name="xxx"/>
</container>
</container>
</container>
1.1
avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/test/TargetsTestCase.java
Index: TargetsTestCase.java
===================================================================
package org.apache.avalon.composition.model.test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import org.apache.avalon.composition.model.Model;
import org.apache.avalon.composition.model.ContainmentModel;
import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.composition.model.DependencyModel;
import org.apache.avalon.composition.model.AbstractTestCase;
import org.apache.avalon.composition.data.Targets;
import org.apache.avalon.composition.data.TargetDirective;
import org.apache.avalon.composition.util.ExceptionHelper;
import org.apache.avalon.composition.data.builder.XMLTargetsCreator;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.excalibur.configuration.ConfigurationUtil;
import org.apache.avalon.meta.info.DependencyDescriptor;
public class TargetsTestCase extends AbstractTestCase
{
//-------------------------------------------------------
// constructor
//-------------------------------------------------------
public TargetsTestCase()
{
super( "targets.xml" );
}
//-------------------------------------------------------
// tests
//-------------------------------------------------------
/**
* Validate the the included block was created.
*/
public void testTargetsApplication() throws Exception
{
try
{
File source =
new File( getTestDir(), "/test-classes/conf/targets-config.xml" );
TargetDirective[] targets = loadTargets( source ).getTargets();
for( int i=0; i<targets.length; i++ )
{
TargetDirective target = targets[i];
final String path = target.getPath();
Model model = m_model.getModel( path );
if( model instanceof DeploymentModel )
{
DeploymentModel deployment = (DeploymentModel) model;
deployment.setConfiguration( target.getConfiguration() );
getLogger().debug( "model: " + deployment );
getLogger().debug(
ConfigurationUtil.list( deployment.getConfiguration() ) );
}
else
{
final String warning =
"Cannot apply target: " + path + " to a containment model.";
getLogger().warn( warning );
}
}
}
catch( Throwable e )
{
final String error = "Test failure.";
final String message = ExceptionHelper.packException( error, e, true );
getLogger().error( message );
throw new Exception( message );
}
}
private Targets loadTargets( File file )
throws Exception
{
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration config = builder.buildFromFile( file );
XMLTargetsCreator creator = new XMLTargetsCreator();
return creator.createTargets( config );
}
}
1.1
avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/testa/ConfigurableComponent.java
Index: ConfigurableComponent.java
===================================================================
package org.apache.avalon.composition.model.testa;
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.logger.AbstractLogEnabled;
import org.apache.excalibur.configuration.ConfigurationUtil;
public class ConfigurableComponent extends AbstractLogEnabled
implements Configurable
{
public void configure( Configuration config ) throws ConfigurationException
{
getLogger().info( "setting config to:"
+ ConfigurationUtil.list( config ) );
}
}
1.1
avalon-sandbox/merlin/composition/src/test/org/apache/avalon/composition/model/testa/ConfigurableComponent.xinfo
Index: ConfigurableComponent.xinfo
===================================================================
<type>
<info>
<name>conf-test</name>
<lifestyle>singleton</lifestyle>
</info>
</type>
1.1
avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/data/TargetDirective.java
Index: TargetDirective.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.avalon.composition.data;
import java.io.Serializable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.composition.data.CategoriesDirective;
/**
* <p>A target is a tagged configuration fragment. The tag is a path
* seperated by "/" charaters qualifying the component that the target
* configuration is to be applied to.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2003/08/08 22:12:19 $
*/
public class TargetDirective implements Serializable
{
//========================================================================
// immutable state
//========================================================================
/**
* The path.
*/
private final String m_path;
/**
* The configuration.
*/
private final Configuration m_config;
/**
* The configuration.
*/
private final CategoriesDirective m_categories;
//========================================================================
// constructors
//========================================================================
/**
* Create a new null Target instance.
*
* @param path target path
* @param configuration the configuration
*/
public TargetDirective( final String path )
{
this( path, null );
}
/**
* Create a new Target instance.
*
* @param path target path
* @param configuration the configuration
*/
public TargetDirective( final String path, final Configuration configuration )
{
this( path, configuration, null );
}
/**
* Create a new Target instance.
*
* @param path target path
* @param configuration the configuration
* @param categories the logging category directives
*/
public TargetDirective(
final String path,
final Configuration configuration,
final CategoriesDirective categories )
{
m_path = path;
m_config = configuration;
m_categories = categories;
}
//========================================================================
// implementation
//========================================================================
/**
* Return the target path.
*
* @return the target path
*/
public String getPath()
{
return m_path;
}
/**
* Return the target configuration.
*
* @return the target configuration
*/
public Configuration getConfiguration()
{
return m_config;
}
/**
* Return the logging categories directive.
*
* @return the logging categories (possibly null)
*/
public CategoriesDirective getCategoriesDirective()
{
return m_categories;
}
/**
* Return a string representation of the target.
* @return a string representing the target instance
*/
public String toString()
{
return "[target: " + getPath() + ", "
+ (getConfiguration() != null ) + ", "
+ (getCategoriesDirective() != null ) + ", "
+ " ]";
}
}
1.1
avalon-sandbox/merlin/composition-spi/src/java/org/apache/avalon/composition/data/Targets.java
Index: Targets.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.avalon.composition.data;
import java.util.ArrayList;
/**
* <p>A target is a tagged configuration fragment. The tag is a path
* seperated by "/" charaters qualifying the component that the target
* configuration is to be applied to.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2003/08/08 22:12:19 $
*/
public class Targets
{
//========================================================================
// state
//========================================================================
/**
* The set of targets.
*/
private final TargetDirective[] m_targets;
//========================================================================
// constructors
//========================================================================
/**
* Create a new Targets instance.
*
* @param targets the set of targets
*/
public Targets( final TargetDirective[] targets )
{
m_targets = targets;
}
//========================================================================
// implementation
//========================================================================
/**
* Return all targets.
*
* @return all the targets in this targets instance.
*/
public TargetDirective[] getTargets()
{
return m_targets;
}
/**
* Return a matching target.
*
* @return the target or null if no matching target
*/
public TargetDirective getTarget( String path )
{
final String key = getKey( path );
for( int i=0; i<m_targets.length; i++ )
{
TargetDirective target = m_targets[i];
if( target.getPath().equals( key ) )
{
return target;
}
}
return null;
}
/**
* Return a set of targets relative to the supplied path.
*
* @param the path
* @return the set of relative targets
*/
public Targets getTargets( String path )
{
final String key = getKey( path );
ArrayList list = new ArrayList();
for( int i=0; i<m_targets.length; i++ )
{
TargetDirective target = m_targets[i];
if( target.getPath().startsWith( key ) )
{
String name = target.getPath().substring( key.length() );
if( name.length() > 0 )
{
list.add(
new TargetDirective(
getKey( name ),
target.getConfiguration(),
target.getCategoriesDirective() ) );
}
}
}
return new Targets(
(TargetDirective[]) list.toArray( new TargetDirective[0] ) );
}
/**
* Convert the supplied path to a valid path.
* @param path the path to convert
* @return a good path value
*/
private String getKey( final String path ) throws IllegalArgumentException
{
if( !path.startsWith("/") )
{
return "/" + path;
}
return path;
}
/**
* Return a string representation of the target.
* @return a string representing the target instance
*/
public String toString()
{
StringBuffer buffer = new StringBuffer( "[targets: " );
for( int i=0; i<m_targets.length; i++ )
{
buffer.append( m_targets[i] );
if( i < ( m_targets.length -1 ) )
{
buffer.append( ", " );
}
}
buffer.append( " ]" );
return buffer.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]