avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/tutorials/context/alias/src/java/tutorial HelloComponent.java
Date Wed, 05 May 2004 19:59:21 GMT
mcconnell    2004/05/05 12:59:21

  Added:       tutorials/context/alias .cvsignore README.TXT project.xml
               tutorials/context/alias/conf block.xml
               tutorials/context/alias/src/java/tutorial
                        HelloComponent.java
  Log:
  add a context example using alias entries
  
  Revision  Changes    Path
  1.1                  avalon/tutorials/context/alias/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build
  target
  tutorial.jar
  
  
  
  1.1                  avalon/tutorials/context/alias/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/tutorials/context/alias/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <project>
  
    <extend>${basedir}/../../master.xml</extend>
  
    <id>merlin-tutorial-context-alias</id>
    <name>Merlin Context Alias Tutorial</name>
    <package>tutorial</package>
  
    <currentVersion>1.0</currentVersion>
    <inceptionYear>2003</inceptionYear>
    <shortDescription>Merlin Context Alias 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/tutorials/context/alias/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/tutorials/context/alias/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.entry key="urn:avalon:name" alias="name"
      * @avalon.entry key="urn:avalon:partition" alias="partition"
      * @avalon.entry key="urn:avalon:home" type="java.io.File" alias="home"
      * @avalon.entry key="urn:avalon:temp" type="java.io.File" alias="temp"
      */
      public HelloComponent( Logger logger, Context context )
        throws ContextException
      {
          m_logger = logger;
  
          m_home = (File) context.get( "home" );
          m_temp = (File) context.get( "temp" );
          m_name = (String) context.get( "name" );
          m_partition = (String) context.get( "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


Mime
View raw message