mcconnell 2003/06/03 22:27:11
Added: merlin/merlin-smp/src/tutorial/contextualization .cvsignore
build.xml
merlin/merlin-smp/src/tutorial/contextualization/src/config
block.xml
merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial
Contextualizable.java ContextualizationHandler.java
ContextualizationHandler.xinfo
StandardComponent.java StandardComponent.xinfo
StandardContext.java StandardContext.xservice
StandardContextImp.java StandardService.java
StandardService.xservice
Log:
Addition of src context supporting the custom contexualizer tutorial.
Revision Changes Path
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/.cvsignore
Index: .cvsignore
===================================================================
build
logs
tutorial.jar
composition-api-1.0.jar
composition-application-1.0.jar
composition-location-1.0.jar
composition-publisher-1.0.jar
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/build.xml
Index: build.xml
===================================================================
<!--
Test application
-->
<project name="tutorial" default="jar" basedir=".">
<property name="src.dir" value="${basedir}/src" />
<property name="java.dir" value="${src.dir}/java" />
<property name="build.dir" value="${basedir}/build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="config.dir" value="${src.dir}/config" />
<property environment="env"/>
<property name="merlin.home" value="${env.MERLIN_HOME}"/>
<property name="framework.jar"
value="${merlin.home}/lib/shared/avalon-framework-4.1.4.jar" />
<property name="meta-spi.jar"
value="${merlin.home}/lib/shared/avalon-meta-spi-1.0.jar" />
<property name="assembly-spi.jar"
value="${merlin.home}/lib/shared/avalon-assembly-spi-1.0.jar" />
<path id="project.class.path">
<pathelement path="${java.class.path}" />
<pathelement location="${framework.jar}"/>
<pathelement location="${meta-spi.jar}"/>
<pathelement location="${assembly-spi.jar}"/>
<fileset dir="${classes.dir}"/>
</path>
<target name="compile" >
<mkdir dir="${classes.dir}" />
<copy toDir="${classes.dir}">
<fileset dir="${java.dir}">
<include name="**/*.xinfo"/>
<include name="**/*.xprofile"/>
</fileset>
</copy>
<mkdir dir="${classes.dir}/BLOCK-INF" />
<copy toDir="${classes.dir}/BLOCK-INF">
<fileset dir="${config.dir}">
<include name="*.xml"/>
</fileset>
</copy>
<mkdir dir="${classes.dir}" />
<javac debug="on" destdir="${classes.dir}" >
<classpath>
<path refid="project.class.path"/>
</classpath>
<src path="${src.dir}" />
</javac>
</target>
<target name="jar" depends="compile">
<jar jarfile="tutorial.jar" basedir="${classes.dir}"/>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
<delete file="tutorial.jar"/>
</target>
</project>
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/config/block.xml
Index: block.xml
===================================================================
<!--
Demonstration of an component providing a custom contextualization phase.
-->
<block>
<info>
<name>tutorial</name>
</info>
<implementation>
<component name="standard"
class="tutorial.StandardComponent" activation="startup"/>
</implementation>
</block>
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/Contextualizable.java
Index: Contextualizable.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 tutorial;
import org.apache.avalon.framework.context.ContextException;
/**
* Definition of an alternative contexulization interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public interface Contextualizable
{
//=======================================================================
// Contextualization (custom variant)
//=======================================================================
/**
* Contextualization of the component.
* @param context the containement context
* @exception ContextException if a contextualization error occurs
*/
void contextualize( StandardContext context )
throws ContextException;
}
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/ContextualizationHandler.java
Index: ContextualizationHandler.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 tutorial;
import java.lang.reflect.Constructor;
import java.util.Map;
import org.apache.avalon.assembly.lifecycle.Contextualization;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.meta.model.ContextDirective;
/**
* Definition of an extension handler that handles the Expoitable
* extension stage interface.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public class ContextualizationHandler implements Contextualization
{
//=======================================================================
// Extension
//=======================================================================
/**
* Handle the contextualization stage of a component lifecycle.
* @param loader the classloader
* @param directive the context directitive
* @param object the object to contextualize
* @param map the map of context entries
* @exception ContextException if a contextualization error occurs
*/
public void contextualize(
ClassLoader loader, ContextDirective directive, Object object, Map map )
throws ContextException
{
//
// based on the supplied context directives, the container supplied
// map of base context entries and a classloader, build and apply
// a context object to the supplied target object
//
if( object instanceof Contextualizable )
{
Object context =
createContextArgument( loader, directive, StandardContextImp.class,
map );
if( context instanceof StandardContext )
{
( (Contextualizable)object ).contextualize( (StandardContext)
context );
}
else
{
final String error =
"Supplied context does not implement the StandardContext
interface.";
throw new ContextException( error );
}
}
else
{
final String error =
"Target object does not implement the "
+ Contextualizable.class.getName() + " interface.";
throw new ContextException( error );
}
}
/**
* Returns a instance of a class established using the supplied map as a
* constructor argument.
*
* @param descriptor the context descriptor
* @param clazz the default class if no class defined in the descriptor
* @param map the context entry map
* @return the context argument value
*/
private Object createContextArgument(
ClassLoader loader, ContextDirective directive, Class clazz, Map map )
throws ContextException
{
if( directive == null )
{
throw new NullPointerException( "directive" );
}
if( clazz == null )
{
throw new NullPointerException( "clazz" );
}
if( map == null )
{
throw new NullPointerException( "map" );
}
String classname = directive.getClassname();
Class base;
if( classname != null )
{
try
{
base = loader.loadClass( classname );
}
catch( ClassNotFoundException cnfe )
{
throw new ContextException(
"Could not find context class: " + classname, cnfe );
}
}
else
{
base = clazz;
}
try
{
Constructor constructor = base.getConstructor(
new Class[]{ Map.class } );
return constructor.newInstance( new Object[]{ map } );
}
catch( NoSuchMethodException e )
{
final String error =
"Custom context class: [" + classname
+ "] does not implement a constructor pattern <init>{ Map }.";
throw new ContextException( error, e );
}
catch( Throwable e )
{
throw new ContextException(
"Unexpected exception while creating context from "
+ base.getName(), e );
}
}
}
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/ContextualizationHandler.xinfo
Index: ContextualizationHandler.xinfo
===================================================================
<?xml version="1.0"?>
<!DOCTYPE type
PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
"http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
<!--
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.
@author Avalon Development Team
@version 1.0 12/03/2001
-->
<!--
Definition of the extension type phase support.
-->
<type>
<info>
<name>context</name>
</info>
<!--
Declaration of the lifecycle support phases that this manager provides.
-->
<extensions>
<extension type="tutorial.Contextualizable" />
</extensions>
</type>
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardComponent.java
Index: StandardComponent.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 tutorial;
import java.io.File;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
/**
* This is a minimal demonstration component that implements the
* <code>BasicService</code> interface and has no dependencies.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public class StandardComponent extends AbstractLogEnabled
implements Contextualizable, Initializable, Disposable, StandardService
{
private File m_home;
private File m_work;
private String m_name;
private String m_partition;
private String m_message;
//=======================================================================
// Contextualizable
//=======================================================================
/**
* Supply of the the component context to the component type.
* @param context the context value
*/
public void contextualize( StandardContext context )
{
m_home = context.getHomeDirectory();
m_work = context.getWorkingDirectory();
m_name = context.getName();
m_partition = context.getPartitionName();
}
//=======================================================================
// Initializable
//=======================================================================
/**
* Initialization of the component type by its container.
*/
public void initialize() throws Exception
{
m_message =
" home: " + m_home
+ "\n work: " + m_work
+ "\n name: " + m_name
+ "\n partition: " + m_partition;
printMessage();
}
//=======================================================================
// Disposable
//=======================================================================
/**
* Dispose of the component.
*/
public void dispose()
{
getLogger().debug( "dispose" );
}
//=======================================================================
// BasicService
//=======================================================================
/**
* Service interface implementation.
*/
public void printMessage()
{
getLogger().info( "context\n"
+ " contextualization using a custom hander\n"
+ m_message + "\n");
}
}
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardComponent.xinfo
Index: StandardComponent.xinfo
===================================================================
<?xml version="1.0"?>
<!DOCTYPE type
PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
"http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
<!--
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.
@author Avalon Development Team
@version 1.0 12/03/2001
-->
<type>
<info>
<name>standard</name>
</info>
<!--
Declaration of the contextualization service, context type and
entries. The provider value is a component implementing the
Contextualizer interface. The type value is a interface that
the component implementation can narrow a supplied context value
to.
-->
<context>
<attributes>
<attribute key="urn:assembly:lifecycle.context.strategy"
value="tutorial.Contextualizable"/>
</attributes>
</context>
<services>
<service type="tutorial.StandardService:1.1" />
</services>
</type>
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardContext.java
Index: StandardContext.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 tutorial;
import java.io.File;
import org.apache.avalon.framework.context.Context;
/**
* Simple non-standard Context interface to demonstration context
* management at the level of different context types.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public interface StandardContext extends Context
{
public static final String NAME_KEY = "urn:avalon:name";
public static final String PARTITION_KEY = "urn:avalon:partition";
public static final String WORKING_KEY = "urn:avalon:work";
public static final String HOME_KEY = "urn:avalon:home";
/**
* Return the name assigned to the component
* @return the name
*/
String getName();
/**
* Return the partition name assigned to the component
* @return the partition name
*/
String getPartitionName();
/**
* @return a file representing the home directory
*/
File getHomeDirectory();
/**
* @return a file representing the working directory
*/
File getWorkingDirectory();
}
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardContext.xservice
Index: StandardContext.xservice
===================================================================
<?xml version="1.0"?>
<!DOCTYPE type
PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
"http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
<!--
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.
@author Avalon Development Team
@version 1.0 12/03/2001
-->
<service>
<version>1.0</version>
<entries>
<entry key="urn:avalon:name"/>
<entry key="urn:avalon:partition"/>
<entry key="urn:avalon:home" type="java.io.File"/>
<entry key="urn:avalon:work" type="java.io.File"/>
</entries>
</service>
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardContextImp.java
Index: StandardContextImp.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 tutorial;
import java.io.File;
import java.util.Map;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
/**
* This is example of a custom context class. It is used in the demonsteation
* of a context management fraework to show how a context class can be
* supplied to a component declaring a context interface criteria.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public class StandardContextImp extends DefaultContext implements StandardContext
{
//-----------------------------------------------------------------
// constructor
//-----------------------------------------------------------------
/**
* Creation of a new custom context instance.
* @param map the context name/value map
* @param parent a possibly parent context
*/
public StandardContextImp( Map map ) throws ContextException
{
super( map );
}
//-----------------------------------------------------------------
// StandardContext
//-----------------------------------------------------------------
/**
* Return the name assigned to the component
* @return the name
*/
public String getName()
{
try
{
return (String)super.get( StandardContext.NAME_KEY );
}
catch( Throwable e )
{
throw new IllegalStateException( StandardContext.NAME_KEY );
}
}
/**
* Return the partition name assigned to the component
* @return the partition name
* @exception IllegalStateException if the partition name is undefined
*/
public String getPartitionName()
{
try
{
return (String)super.get( StandardContext.PARTITION_KEY );
}
catch( Throwable e )
{
throw new IllegalStateException( StandardContext.PARTITION_KEY );
}
}
/**
* Returns the home directory for this component.
* @return the home directory
*/
public File getHomeDirectory()
{
try
{
return (File)super.get( StandardContext.HOME_KEY );
}
catch( Throwable e )
{
throw new IllegalStateException( StandardContext.HOME_KEY );
}
}
/**
* @return the working directory
*/
public File getWorkingDirectory()
{
try
{
return (File)super.get( StandardContext.WORKING_KEY );
}
catch( Throwable e )
{
throw new IllegalStateException( StandardContext.WORKING_KEY );
}
}
}
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardService.java
Index: StandardService.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 tutorial;
/**
* The <code>StandardService</code> prints a message.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
*/
public interface StandardService
{
/**
* Execute the prime objective of this services.
*/
void printMessage();
}
1.1
avalon-sandbox/merlin/merlin-smp/src/tutorial/contextualization/src/java/tutorial/StandardService.xservice
Index: StandardService.xservice
===================================================================
<?xml version="1.0"?>
<!DOCTYPE type
PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
"http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
<!--
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.
@author Avalon Development Team
@version 1.0 12/03/2001
-->
<service>
<version>1.1</version>
<attributes>
<attribute key="urn:avalon:service.name" value="standard"/>
<attribute key="urn:avalon:service.description">
A demonstration service used within the scope of the
tutorial package.
</attribute>
</attributes>
</service>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]