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 13:59:31 UTC
cvs commit: avalon/merlin/platform/tutorials/context/injection/src/java/tutorial HelloComponent.java
mcconnell 2004/03/11 04:59:31
Added: merlin/platform/tutorials/context/injection .cvsignore
README.TXT project.xml
merlin/platform/tutorials/context/injection/conf block.xml
merlin/platform/tutorials/context/injection/src/java/tutorial
HelloComponent.java
Log:
Addition of an example that uses constructor based injection of a context.
Revision Changes Path
1.1 avalon/merlin/platform/tutorials/context/injection/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build
target
tutorial.jar
1.1 avalon/merlin/platform/tutorials/context/injection/README.TXT
Index: README.TXT
===================================================================
Constructor Injection of a Context.
-----------------------------------
This tutorial covers usage of standard context entries using
a constructor supplied context (as opposed to the classic
Contextualization delivery mecahanism).
$ maven
$ merlin -execute target\classes
[INFO ] (tutorial.hello): standard context entries
name: hello
home: [your-directory]\home\tutorial\hello
temp: C:\TEMP\tutorial\hello
partition: /tutorial/
1.1 avalon/merlin/platform/tutorials/context/injection/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project>
<extend>${basedir}/../../project.xml</extend>
<id>merlin-tutorial-context-standard</id>
<name>Merlin Context Standard Tutorial</name>
<package>tutorial</package>
<currentVersion>1.0</currentVersion>
<inceptionYear>2003</inceptionYear>
<shortDescription>Merlin Context Standard Tutorial.</shortDescription>
<dependencies>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/java</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/conf</directory>
<targetPath>BLOCK-INF</targetPath>
<includes>
<include>block.xml</include>
</includes>
</resource>
</resources>
<jars></jars>
</build>
</project>
1.1 avalon/merlin/platform/tutorials/context/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"/>
</container>
1.1 avalon/merlin/platform/tutorials/context/injection/src/java/tutorial/HelloComponent.java
Index: HelloComponent.java
===================================================================
/*
* Copyright 2004 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 java.io.File;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
/**
* Component demonstrating access to standard context entries.
* @avalon.component name="demo" lifestyle="singleton"
*/
public class HelloComponent
{
//------------------------------------------------------
// immutable state
//------------------------------------------------------
private final Logger m_logger;
private final File m_home;
private final File m_temp;
private final String m_name;
private final String m_partition;
/**
* Creation of a new HelloComponent instance using a
* container supplied logging channel and context.
* The context supplied by the container holds the
* standard context entries for the home and
* working directories, component name and partition.
*
* @avalon.context
* @avalon.entry key="urn:avalon:name"
* @avalon.entry key="urn:avalon:partition"
* @avalon.entry key="urn:avalon:home" type="java.io.File"
* @avalon.entry key="urn:avalon:temp" type="java.io.File"
*/
public HelloComponent( Logger logger, Context context )
throws ContextException
{
m_logger = logger;
m_home = (File) context.get( "urn:avalon:home" );
m_temp = (File) context.get( "urn:avalon:temp" );
m_name = (String) context.get( "urn:avalon:name" );
m_partition = (String) context.get( "urn:avalon:partition" );
StringBuffer buffer = new StringBuffer( "standard context entries" );
buffer.append( "\n name: " + m_name );
buffer.append( "\n home: " + m_home );
buffer.append( "\n temp: " + m_temp );
buffer.append( "\n partition: " + m_partition );
m_logger.info( buffer.toString() );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org