avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/merlin-smp/src/tutorial/005/src/java/tutorial DemoContext.java DemoContextProvider.java HelloComponent.java HelloComponent.xinfo
Date Fri, 04 Apr 2003 12:14:29 GMT
mcconnell    2003/04/04 04:14:29

  Added:       merlin/merlin-smp/src/tutorial/005 .cvsignore build.xml
               merlin/merlin-smp/src/tutorial/005/src/config block.xml
               merlin/merlin-smp/src/tutorial/005/src/java/tutorial
                        DemoContext.java DemoContextProvider.java
                        HelloComponent.java HelloComponent.xinfo
  Log:
  Tutorial content for lesson 005.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/005/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  build
  logs
  tutorial.jar
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/005/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" />
  
    <path id="project.class.path">
      <pathelement path="${java.class.path}" />
      <pathelement location="${framework.jar}"/>
      <fileset dir="${classes.dir}"/>
    </path>
  
    <target name="compile" >
      <mkdir dir="${classes.dir}" />
      <copy toDir="${classes.dir}">
        <fileset dir="${java.dir}">
          <include name="**/*.xinfo"/>
        </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/005/src/config/block.xml
  
  Index: block.xml
  ===================================================================
  
  <block name="tutorial">
     <container>
       <component name="hello" class="tutorial.HelloComponent" activation="startup">
         <context class="tutorial.DemoContextProvider"/>
       </component>
    </container>
  </block>
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/005/src/java/tutorial/DemoContext.java
  
  Index: DemoContext.java
  ===================================================================
  
  package tutorial;
  
  import java.io.File;
  
  import org.apache.avalon.framework.context.Context;
  
  /**
   * An example of an convinience interface that extends the 
   * standard Avalon Context interface.
   */
  public interface DemoContext extends Context
  {
  
     /**
      * Return the component name.
      * @return the component name
      */
      String getName();
  
     /**
      * Return the name of the partition assigned to the component.
      * @return the partition name
      */
      String getPartition();
  
     /**
      * Return the home directory.
      * @return the directory
      */
      File getHomeDirectory();
  
     /**
      * Return the temporary working directory.
      * @return the directory
      */
      File getWorkingDirectory();
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/005/src/java/tutorial/DemoContextProvider.java
  
  Index: DemoContextProvider.java
  ===================================================================
  
  package tutorial;
  
  import java.util.Map;
  import java.io.File;
  
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.context.ContextException;
  
  
  /**
   * A demonstration class that that we will instantiate via 
   * context directives within the component declaration.
   */
  public class DemoContextProvider extends DefaultContext implements DemoContext
  {
  
     /**
      * A custom context type implementation must provide
      * the following constructor.
      * @param entries a map of context entries
      */
      public DemoContextProvider( Map entries )
      {
          super( entries );
      }
   
     /**
      * Return the component name.
      * @return the component name
      */
      public String getName()
      {
          try
          {
              return (String) super.get( "urn:avalon:name" );
          }
          catch( ContextException ce )
          {
              // should not happen 
              throw new RuntimeException( ce.toString() );
          }
      }
  
     /**
      * Return the name of the partition assigned to the component.
      * @return the partition name
      */
      public String getPartition()
      {
          try
          {
              return (String) super.get( "urn:avalon:partition" );
          }
          catch( ContextException ce )
          {
              // should not happen 
              throw new RuntimeException( ce.toString() );
          }
      }
  
     /**
      * Return the home directory.
      * @return the home directory
      */
      public File getHomeDirectory()
      {
          try
          {
              return (File) super.get( "urn:avalon:home" );
          }
          catch( ContextException ce )
          {
              // should not happen 
              throw new RuntimeException( ce.toString() );
          }
      }
  
  
     /**
      * Return the temporary working directory.
      * @return the temp directory
      */
      public File getWorkingDirectory()
      {
          try
          {
              return (File) super.get( "urn:avalon:work" );
          }
          catch( ContextException ce )
          {
              // should not happen 
              throw new RuntimeException( ce.toString() );
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/005/src/java/tutorial/HelloComponent.java
  
  Index: HelloComponent.java
  ===================================================================
  package tutorial;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  
  public class HelloComponent extends AbstractLogEnabled 
    implements Contextualizable
  {
  
     /**
      * Contextualization of the component using a context
      * class that implements a domain specific context interface.
      */
      public void contextualize( Context context )
        throws ContextException
      {
          DemoContext c = (DemoContext) context;
          getLogger().info( "name: " + c.getName() );
          getLogger().info( "partition: " + c.getPartition() );
          getLogger().info( "home: " + c.getHomeDirectory() );
          getLogger().info( "temp: " + c.getWorkingDirectory() );
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/005/src/java/tutorial/HelloComponent.xinfo
  
  Index: HelloComponent.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE type
        PUBLIC "-//AVALON/Type DTD Version 1.0//EN"
               "http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
  <type>
    <info>
      <name>hello</name>
      <version>1.0</version>
    </info>
    <context type="tutorial.DemoContext"/>
  </type>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message