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/004/src/java/tutorial HelloComponent.java HelloComponent.xinfo NumberCruncher.java
Date Fri, 04 Apr 2003 12:10:43 GMT
mcconnell    2003/04/04 04:10:43

  Added:       merlin/merlin-smp/src/tutorial/004 .cvsignore build.xml
               merlin/merlin-smp/src/tutorial/004/src/config block.xml
               merlin/merlin-smp/src/tutorial/004/src/java/tutorial
                        HelloComponent.java HelloComponent.xinfo
                        NumberCruncher.java
  Log:
  Tutorial content for lesson 004.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/004/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  build
  logs
  tutorial.jar
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/004/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/004/src/config/block.xml
  
  Index: block.xml
  ===================================================================
  
  <block name="tutorial">
     <container>
       <component name="hello" class="tutorial.HelloComponent" activation="startup">
         <context>
           <entry key="cruncher" class="tutorial.NumberCruncher">
             <parameter class="java.lang.Integer">7</parameter>
             <parameter class="java.lang.Double">1.5</parameter>
           </entry>
         </context>
       </component>
    </container>
  </block>
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/004/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 by the container.
      * The context supplied by the container shall contain
      * a NumberCruncher instance as declared in the xinfo resource.
      */
      public void contextualize( Context context )
        throws ContextException
      {
          NumberCruncher cruncher = 
            (NumberCruncher) context.get( "cruncher" );
          float value = cruncher.crunch();
          getLogger().info( "result: " + value );
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/004/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>
      <entry key="cruncher" type="tutorial.NumberCruncher"/>
    </context>
  </type>
  
  
  
  1.1                  avalon-sandbox/merlin/merlin-smp/src/tutorial/004/src/java/tutorial/NumberCruncher.java
  
  Index: NumberCruncher.java
  ===================================================================
  
  package tutorial;
  
  /**
   * A demonstration class that that we will instantiate via 
   * context directives within the component declaration.
   */
  public class NumberCruncher
  {
      private final int m_primary;
      private final float m_secondary;
  
      public NumberCruncher( Integer primary, Double secondary )
      {
          m_primary = primary.intValue();
          m_secondary = secondary.floatValue();
      }
   
     /**
      * Multiply the supplied constructor arguments together and 
      * return the value.
      */
      public float crunch()
      {
         return ( m_secondary * m_primary );
      }
  }
  
  
  

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


Mime
View raw message