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 2003/10/04 11:52:24 UTC

cvs commit: avalon/merlin/platform/tutorials/selection/src/java/tutorial HelloComponent.java RandomGenerator.java RandomGeneratorProvider.java RandomGeneratorProvider.xprofile

mcconnell    2003/10/04 02:52:24

  Added:       merlin/platform/tutorials/selection .cvsignore project.xml
               merlin/platform/tutorials/selection/conf block.xml
               merlin/platform/tutorials/selection/src/java/tutorial
                        HelloComponent.java RandomGenerator.java
                        RandomGeneratorProvider.java
                        RandomGeneratorProvider.xprofile
  Log:
  Addition of profile selection tutorial content.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/platform/tutorials/selection/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build
  target
  tutorial.jar
  
  
  
  1.1                  avalon/merlin/platform/tutorials/selection/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <project>
  
    <extend>${basedir}/../project.xml</extend>
  
    <id>merlin-tutorial-selection</id>
    <name>Merlin Profiles Selection Tutorial</name>
    <package>tutorial</package>
  
    <currentVersion>1.0</currentVersion>
    <inceptionYear>2003</inceptionYear>
    <shortDescription>Merlin Profile Selection 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>
    
  </project>
  
  
  
  1.1                  avalon/merlin/platform/tutorials/selection/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"/>
  
     <component name="randomizer" 
       class="tutorial.RandomGeneratorProvider" profile="secondary"/>
  
  </container>
  
  
  
  1.1                  avalon/merlin/platform/tutorials/selection/src/java/tutorial/HelloComponent.java
  
  Index: HelloComponent.java
  ===================================================================
  package tutorial;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  
  /**
   * Demonstration component that will be provided with a 
   * service established via a named profile.
   * @avalon.component name="hello" lifestyle="singleton"
   */
  public class HelloComponent extends AbstractLogEnabled 
    implements Serviceable
  {
  
     /**
      * Servicing of the component by the container during 
      * which service dependencies declared under the component
      * can be resolved using the supplied service manager.
      *
      * @avalon.dependency type="tutorial.RandomGenerator" key="random"
      */
      public void service( ServiceManager manager )
        throws ServiceException
      {
          RandomGenerator random = (RandomGenerator) manager.lookup( "random" );
          getLogger().info( "supplied random: " + random.getRandom() );
      }
  }
  
  
  
  1.1                  avalon/merlin/platform/tutorials/selection/src/java/tutorial/RandomGenerator.java
  
  Index: RandomGenerator.java
  ===================================================================
  
  package tutorial;
  
  /**
   * A service that provides access to a random number.
   */
  public interface RandomGenerator
  {
  
     /**
      * Return a random integer
      * @return the random number
      */
      int getRandom();
  
  }
  
  
  
  1.1                  avalon/merlin/platform/tutorials/selection/src/java/tutorial/RandomGeneratorProvider.java
  
  Index: RandomGeneratorProvider.java
  ===================================================================
  
  package tutorial;
  
  import java.util.Random;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  /**
   * An implementation of a random number generator.
   * @avalon.component name="random-provider" lifestyle="singleton"
   * @avalon.service type="tutorial.RandomGenerator"
   */
  public class RandomGeneratorProvider extends AbstractLogEnabled 
    implements Configurable, RandomGenerator
  {
  
      private Random m_random = null;
  
     /**
      * Configuration of the component by the container.  The 
      * implementation get a child element named 'source' and 
      * assigns the value of the element to a local variable.
      *
      * @param config the component configuration
      * @exception ConfigurationException if a configuration error occurs
      */
      public void configure( Configuration config ) throws ConfigurationException
      {
          getLogger().info( "configuration stage" );
          long seed = config.getChild( "seed" ).getValueAsLong( 0 );
          getLogger().info( "seed: " + seed );
          m_random = new Random( System.currentTimeMillis() * seed );
      }
  
     /**
      * Return a random integer
      * @return the random number
      */
      public int getRandom()
      {
          return m_random.nextInt();
      }
  }
  
  
  
  1.1                  avalon/merlin/platform/tutorials/selection/src/java/tutorial/RandomGeneratorProvider.xprofile
  
  Index: RandomGeneratorProvider.xprofile
  ===================================================================
  <?xml version="1.0"?>
  
  <profiles>
  
    <profile name="primary">
      <configuration>
        <seed>1024</seed>
      </configuration>
    </profile>
  
    <profile name="secondary">
      <configuration>
        <seed>2048</seed>
      </configuration>
    </profile>
  
  </profiles>
  
  
  

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