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 2004/03/11 14:21:17 UTC
cvs commit: avalon/merlin/platform/tutorials/configuration/injection/src/java/tutorial HelloComponent.java HelloComponent.xconfig
mcconnell 2004/03/11 05:21:17
Added: merlin/platform/tutorials/configuration/injection .cvsignore
README.TXT project.xml
merlin/platform/tutorials/configuration/injection/conf
block.xml
merlin/platform/tutorials/configuration/injection/src/java/tutorial
HelloComponent.java HelloComponent.xconfig
Log:
Add example of configuration via injection.
Revision Changes Path
1.1 avalon/merlin/platform/tutorials/configuration/injection/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build.properties
target
logs
1.1 avalon/merlin/platform/tutorials/configuration/injection/README.TXT
Index: README.TXT
===================================================================
Configuration Management (constructor injection)
------------------------------------------------
This tutorial demonstrates the injection of a configuration
via a component constructor.
Build using:
$ maven jar
$ merlin target\classes -execute
1.1 avalon/merlin/platform/tutorials/configuration/injection/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<extend>${basedir}/../../project.xml</extend>
<id>merlin-injected-configuration</id>
<name>Injected Configuration Tutorial</name>
<dependencies>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</project>
1.1 avalon/merlin/platform/tutorials/configuration/injection/conf/block.xml
Index: block.xml
===================================================================
<container name="tutorial">
<classloader>
<classpath>
<repository>
<resource id="avalon-framework:avalon-framework-impl" version="4.1.5"/>
</repository>
</classpath>
</classloader>
<component name="hello" class="tutorial.HelloComponent" activation="startup">
<configuration>
<source>explicit configuration within block</source>
</configuration>
</component>
</container>
1.1 avalon/merlin/platform/tutorials/configuration/injection/src/java/tutorial/HelloComponent.java
Index: HelloComponent.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tutorial;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* A configurable component using constructor based injection of
* a configuration.
*
* @avalon.component version="1.0" name="simple" lifestyle="singleton"
*/
public class HelloComponent
{
/**
* Configuration of the component by the container. The
* implementation get a child element named 'source' and
* assigns the value of the element to a local variable.
*
* @param config the component configuration
* @exception ConfigurationException if a configuration error occurs
*/
public HelloComponent( Logger logger, Configuration config ) throws ConfigurationException
{
logger.info( "instantiation" );
final String source = config.getChild( "source" ).getValue( "unknown" );
final String message = "source: " + source;
logger.info( message );
}
}
1.1 avalon/merlin/platform/tutorials/configuration/injection/src/java/tutorial/HelloComponent.xconfig
Index: HelloComponent.xconfig
===================================================================
<?xml version="1.0"?>
<!--
This is an example of a configuration packaged with a component
type. Configuration declarations of this kind are normally used
to establish default configuration values required by an
implementation. The Merlin container will use this information
to construct a cascading configuration where this configuration
is placed as the configuration of last resort.
-->
<configuration>
<source>packaged default</source>
</configuration>
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org