You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/04/20 14:19:52 UTC
cvs commit: avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/container Targets.java Target.java ContainmentProfile.java
mcconnell 2003/04/20 05:19:52
Added: merlin/merlin-core/src/java/org/apache/avalon/merlin/container
Targets.java Target.java ContainmentProfile.java
Log:
Seperated out functionality dealing with configuration fragments.
Revision Changes Path
1.1 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/container/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 apache@apache.org.
*
* 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.merlin.container;
import java.util.ArrayList;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.meta.info.Type;
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.meta.model.ContextDirective;
import org.apache.avalon.meta.model.LoggingDirective;
import org.apache.avalon.meta.model.Mode;
import org.apache.avalon.meta.model.Profile;
/**
* <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:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2003/04/20 12:19:52 $
*/
public class Targets
{
//========================================================================
// state
//========================================================================
/**
* The parent.
*/
private final Targets m_parent;
/**
* The set of targets.
*/
private final Target[] m_targets;
//========================================================================
// constructors
//========================================================================
/**
* Create a new Targets instance.
*
* @param targets the set of targets
*/
public Targets( final Target[] targets )
{
this( null, targets );
}
/**
* Create a new Targets instance.
*
* @param targets the set of targets
*/
public Targets( final Targets parent, final Target[] targets )
{
m_targets = targets;
m_parent = parent;
}
//========================================================================
// implementation
//========================================================================
/**
* Return all targets.
*
* @return all the targets in this targets instance.
*/
protected Target[] getTargets()
{
return m_targets;
}
/**
* Return a matching target.
*
* @return the target or null if no matching target
*/
public Target getTarget( String path )
{
final String key = getKey( path );
if( m_parent != null )
{
Target t = m_parent.getTarget( key );
if( t.getConfiguration() != null )
{
return t;
}
}
for( int i=0; i<m_targets.length; i++ )
{
Target target = m_targets[i];
if( target.getPath().equals( key ) )
{
return target;
}
}
return new Target( key, 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++ )
{
Target target = m_targets[i];
if( target.getPath().startsWith( key ) )
{
String name = target.getPath().substring( key.length() );
if( name.length() > 0 )
{
if( target.getConfiguration() != null )
{
Target t = new Target( getKey( name ), target.getConfiguration() );
list.add( t );
}
}
}
}
Target[] result = (Target[]) list.toArray( new Target[0] );
if( m_parent != null )
{
return new Targets( m_parent.getTargets( key ), result );
}
return new Targets( result );
}
/**
* 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: " );
if( m_parent != null )
{
buffer.append( m_parent.toString() );
}
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();
}
}
1.1 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/container/Target.java
Index: Target.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 apache@apache.org.
*
* 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.merlin.container;
import java.util.ArrayList;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.meta.info.Type;
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.meta.model.ContextDirective;
import org.apache.avalon.meta.model.LoggingDirective;
import org.apache.avalon.meta.model.Mode;
import org.apache.avalon.meta.model.Profile;
import org.apache.excalibur.configuration.ConfigurationUtil;
/**
* <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:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2003/04/20 12:19:52 $
*/
public class Target
{
//========================================================================
// state
//========================================================================
/**
* The path.
*/
private final String m_path;
/**
* The configuration.
*/
private final Configuration m_config;
//========================================================================
// constructors
//========================================================================
/**
* Create a new Target instance.
*
* @param path target path
* @param configuration the configuration
*/
public Target( final String path, final Configuration configuration )
{
if( !path.startsWith("/") )
{
final String error =
"Supplied target path '" + path
+ "' does not commence with the path delimiter '/'.";
throw new IllegalArgumentException( error );
}
m_path = path;
m_config = configuration;
}
//========================================================================
// implementation
//========================================================================
/**
* Return the target path.
*
* @return the target path
*/
public String getPath()
{
return m_path;
}
/**
* Return the target configuration.
*
* @return the target path
*/
public Configuration getConfiguration()
{
return m_config;
}
/**
* Return a string representation of the target.
* @return a string representing the target instance
*/
public String toString()
{
return "[target: " + getPath() + ", " + (getConfiguration() != null ) + " ]";
}
}
1.1 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/container/ContainmentProfile.java
Index: ContainmentProfile.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 apache@apache.org.
*
* 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.merlin.container;
import java.util.ArrayList;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.meta.info.Type;
import org.apache.avalon.meta.info.DependencyDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.meta.model.ContextDirective;
import org.apache.avalon.meta.model.LoggingDirective;
import org.apache.avalon.meta.model.Mode;
import org.apache.avalon.meta.model.Profile;
import org.apache.avalon.assembly.engine.EngineClassLoader;
/**
* <p>A container descriptor is a description of the crieria supporting the
* construction of a container. It may may include multiple
* component profile declarations, and multiple nested container declarations.</p>
*
* <p><b>XML</b><p>
* A single container element is required within a kernel defintion. Multiple
* container declarations may appear within an enclosing container.
* <pre>
* <font color="gray"><i><!--
* Definition of a container. The name attribute declares bother the container
* name and the base logging category that will be supplied to the container
* by its parent. Logging category defintions declared within the container
* declaration are relative to the container name.
* --></i></font>
*
* <container name="<font color="darkred">root</font>">
*
* <engine>
*
* <font color="gray"><i><!--
* Classpath declaration. Classes accessible to a component are constrained
* to the classes available in the jar files declared within the immediate
* classpath, together with and resources declared in any parent container.
* --></i></font>
*
* <classpath>
* <fileset dir="<font color="darkred">dist</font>">
* <include name="<font color="darkred">demo.jar</font>"/>
* <include name="<font color="darkred">new-application-1.0.jar</font>"/>
* </fileset>
* </classpath>
*
* </engine>
*
* <font color="gray"><i><!--
* Logging categories declaration. Logging categories are relative to the name of the
* enaclosing container. Logging priorities and targets will default to the parent
* containtains values if undefined.
* --></i></font>
*
* <categories priority="<font color="darkred">INFO</font>">
* <category name="<font color="darkred">profiles</font>" />
* <category name="<font color="darkred">lifecycle</font>" />
* <category name="<font color="darkred">verifier</font>" />
* </categories>
*
* <font color="gray"><i><!--
* Multiple component profile declarations. If a component declares dependecies,
* the container will attempt to resolve the dependency locally relative to any
* other declared components, otherwise, the container will attempt to resolve
* the dependecy using services established (explicitly or implicitly) in the
* parent containers before attempting a local implicit solution.
* --></i></font>
*
* <component name="<font color="darkred">my-component</font>"
* class="<font color="darkred">org.apache.excalibur.playground.SimpleComponent</font>" />
*
* <font color="gray"><i><!--
* Multiple subsidiary container declarations.
* --></i></font>
*
* <container name="<font color="darkred">child</font>">
* <component name="<font color="darkred">demo-component</font>" class="<font color="darkred">org.apache.excalibur.playground.BasicComponent</font>" />
* <container>
*
* </container>
* </pre>
*
* @see org.apache.avalon.meta.model.Profile
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/04/20 12:19:52 $
*/
public class ContainmentProfile extends Profile
{
//========================================================================
// static
//========================================================================
/**
* Container path delimiter.
*/
public static final String DELIMITER = "/";
//========================================================================
// state
//========================================================================
/**
* The component described within the scope of the container.
*/
private final ArrayList m_components = new ArrayList();
/**
* The containers described within the scope of the container.
*/
private final ArrayList m_containers = new ArrayList();
/**
* Virtual services.
*/
private ServiceDescriptor[] m_services;
/**
* Virtual dependencies.
*/
private DependencyDescriptor[] m_dependencies;
/**
* Assigned classloader.
*/
private EngineClassLoader m_engine;
//========================================================================
// constructors
//========================================================================
/**
* Create a ContainmentProfile instance.
*
* @param name the abstract name of profile
* @param parameters the parameters instance to use during type instantiation
* @param configuration the configuration instance to use during type instantiation
* @param context the context instance to use during type instantiation
* @param categories the logging categories descriptor
* @param type the type of component that this profile qualifies
* @param mode the creation mode (either IMPLICIT, PACKAGED, or EXPLICIT)
* @param services virtual services exposed by the container
* @param dependencies virtual dependencies
* @param engine assigned classloader
* @param components embedded component profiles
* @param containers embedded containers profiles
*/
public ContainmentProfile( final String name,
final Parameters parameters,
final Configuration configuration,
final ContextDirective context,
final LoggingDirective categories,
final Type type,
final Mode mode )
{
super( name, parameters, configuration, context, categories, type, mode );
/*
m_services = services;
m_dependencies = dependencies;
m_engine = engine;
for( int i=0; i<components.length; i++ )
{
m_components.add( components[i] );
}
for( int i=0; i<containers.length; i++ )
{
m_containers.add( containers[i] );
}
*/
}
//========================================================================
// implementation
//========================================================================
/**
* Set the block virtual services.
* @param services the services provided by the block
*/
public void setServices( ServiceDescriptor[] services )
{
if( m_services != null )
{
final String error =
"Illegal attempt to modify service descriptor state.";
throw new IllegalStateException( error );
}
m_services = services;
}
/**
* Set the block virtual dependecies.
* @param dependecies the dependecies consumed by the block
*/
public void setDependencies( DependencyDescriptor[] dependencies )
{
if( m_dependencies != null )
{
final String error =
"Illegal attempt to modify dependecies descriptor state.";
throw new IllegalStateException( error );
}
m_dependencies = dependencies;
}
/**
* Set the engine classloader.
* @param engine the engine
*/
public void setEngine( EngineClassLoader engine )
{
if( m_engine != null )
{
final String error =
"Illegal attempt to modify engine state.";
throw new IllegalStateException( error );
}
m_engine = engine;
}
/**
* Return the engine.
*
* @return the block engine.
*/
public EngineClassLoader getEngine()
{
return m_engine;
}
/**
* Add a set of component profile to this container.
*
* @param components the component profiles to add to the container
*/
public void addComponents( Profile[] components )
{
for( int i=0; i<components.length; i++ )
{
addComponent( components[i] );
}
}
/**
* Add a component profile to this container.
*
* @param component the component profile to add to the container
*/
public void addComponent( Profile component )
{
if( !m_components.contains( component ) )
{
m_components.add( component );
}
}
/**
* Return the set of component descriptors contained within this container.
*
* @return the target descriptors
*/
public Profile[] getComponents()
{
return (Profile[])m_components.toArray( new Profile[ 0 ] );
}
/**
* Return the set of component descriptors contained within this container matching
* the supplied mode.
*
* @param mode one of enumerated value {@link Mode#IMPLICIT}, {@link Mode#PACKAGED},
* or {@link Mode#EXPLICIT}
* @param enabled TRUE to select enabled components, FALSE returns disabled components
* @return the profiles matching the supplied creation mode
*/
public Profile[] getComponents( Mode mode )
{
Profile[] components = getComponents( );
return selectComponentsByMode( components, mode );
}
/**
* Returns a sub-set of the supplied containers matching the supplied creation mode.
* @param components the compoennts to select from
* @param mode the creation mode to retrict the returned selection to
* @param the subset of the supplied components with a creation mode matching
* the supplied mode value
*/
private Profile[] selectComponentsByMode( Profile[] components, Mode mode )
{
ArrayList list = new ArrayList();
for( int i = 0; i < components.length; i++ )
{
Profile component = components[ i ];
if( component.getMode().equals( mode ) )
{
list.add( component );
}
}
return (Profile[])list.toArray( new Profile[ 0 ] );
}
/**
* Add a container profile to this container.
*
* @param containers the container profiles to add to the container
*/
public void addContainers( ContainmentProfile[] containers )
{
for( int i=0; i<containers.length; i++ )
{
addContainer( containers[i] );
}
}
/**
* Add a container profile to this container.
*
* @param container the container profile to add to the container
*/
public void addContainer( ContainmentProfile container )
{
if( !m_containers.contains( container ) )
{
m_containers.add( container );
}
}
/**
* Return the set of container descriptors contained within this container.
*
* @return the container descriptors
*/
public ContainmentProfile[] getContainers()
{
return (ContainmentProfile[])m_containers.toArray( new ContainmentProfile[ 0 ] );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org