mcconnell 2004/03/03 23:28:19
Added: merlin/platform/tutorials/main .cvsignore README.txt
maven.xml merlin.properties project.properties
project.xml
merlin/platform/tutorials/main/conf demo.block
merlin/platform/tutorials/main/src/java/tutorial Main.java
Log:
Addition of a tutorial the introduces the embedding of a merlin kernel inside a main
method.
Revision Changes Path
1.1 avalon/merlin/platform/tutorials/main/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build.xml
build.properties
target
maven.log
working
.classpath
.project
1.1 avalon/merlin/platform/tutorials/main/README.txt
Index: README.txt
===================================================================
Embedding Tutorial
==================
Overview
--------
The tutorial includes a single class tutorial.Main. This class
contains a single main method that demonstrates the creation of
a merlin kernel. Details of the embedding and activation
process are included in the source.
Build
-----
Build the project using the following command:
$ maven
The above command triggers the default goal jar:jar which will
create a jar file under the target directory named
merlin-main-1.0.jar.
Runtime
-------
To run the main class execute the following command from the
merlin/platform/tutorials/main directory:
$ java -jar target/merlin-main-1.0.jar
1.1 avalon/merlin/platform/tutorials/main/maven.xml
Index: maven.xml
===================================================================
<project default="jar:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core"
xmlns:util="jelly:util" xmlns:ant="jelly:ant">
<preGoal name="jar:jar">
<j:forEach var="dep" items="${pom.dependencies}">
<unzip src="${pom.getDependencyPath( dep.getId() )}"
dest="${maven.build.dir}/classes">
<patternset>
<exclude name="META-INF/**"/>
<exclude name="*.meta"/>
</patternset>
</unzip>
</j:forEach>
</preGoal>
</project>
1.1 avalon/merlin/platform/tutorials/main/merlin.properties
Index: merlin.properties
===================================================================
merlin.info = true
merlin.debug = false
1.1 avalon/merlin/platform/tutorials/main/project.properties
Index: project.properties
===================================================================
maven.jar.mainclass = tutorial.Main
1.1 avalon/merlin/platform/tutorials/main/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<extend>${basedir}/../project.xml</extend>
<groupId>merlin/main</groupId>
<id>merlin-main</id>
<name>Merlin Embedding Tutorials</name>
<package>tutorial</package>
<currentVersion>1.0</currentVersion>
<inceptionYear>2003</inceptionYear>
<shortDescription>Merlin Embedding Tutorial</shortDescription>
<description>
Tutorial demonstrating the embedding of a merlin kernel under a
main method. The objective of the tutorial is to demonsrate the
basic requirements for embedding merlin within another application.
</description>
<dependencies>
<dependency>
<groupId>avalon-repository</groupId>
<artifactId>avalon-repository-main</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
1.1 avalon/merlin/platform/tutorials/main/conf/demo.block
Index: demo.block
===================================================================
<container name="tutorial">
<classloader>
<classpath>
<repository>
<resource id="merlin/tutorial:hello" version="1.1"/>
</repository>
</classpath>
</classloader>
<component name="hello" class="tutorial.HelloComponent"/>
</container>
1.1
avalon/merlin/platform/tutorials/main/src/java/tutorial/Main.java
Index: Main.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 java.util.Map;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.provider.Builder;
import org.apache.avalon.repository.provider.Factory;
import org.apache.avalon.repository.provider.InitialContextFactory;
import org.apache.avalon.repository.provider.InitialContext;
import org.apache.avalon.repository.main.DefaultInitialContextFactory;
import org.apache.avalon.repository.Artifact;
/**
* An example of the embedding of a merlin kernel inside a main
* method. The objective of the example is to demonstrate a
* simple embedded scenario.
*/
public class Main
{
public static void main( String[] args ) throws Exception
{
//
// Create the initial context factory. This establishes
// the application group from which properties will
// be resolved. It also provides operations supporting
// customization of the application environment.
//
InitialContextFactory initial =
new DefaultInitialContextFactory( "merlin" );
File home = initial.getHomeDirectory();
initial.setCacheDirectory( new File( home, "system" ) );
InitialContext context = initial.createInitialContext();
//
// Using the initial context we can now load any repository
// application using an artifact specification. Meta
// information associated with the artifact is used to
// construct the classloader that the application needs in
// order to execute.
//
String spec = "artifact:merlin/merlin-impl#3.3-SNAPSHOT";
Artifact artifact = Artifact.createArtifact( spec );
Builder builder = context.newBuilder( artifact );
//
// With the classloader established we can go ahead and
// and get the application factory. The factory has already
// been parameterized with defaults derived from properties
// based on the application group. We can provide
// overriding values by setting the factory criteria to
// application specific values following which we instantiate
// the application.
//
Factory factory = builder.getFactory();
Map criteria = factory.createDefaultCriteria();
criteria.put( "merlin.deployment", "conf/demo.block" );
factory.create( criteria );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]