mcconnell    2003/11/24 00:10:36

  Modified:    kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultCriteria.java DefaultFactory.java
                        DefaultKernelContext.java
  Added:       kernel/impl/src/java/org/apache/avalon/merlin/kernel
                        KernelCriteria.java
  Log:
  Synchronization witth repo updates.
  
  Revision  Changes    Path
  1.1                  
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java
  
  Index: KernelCriteria.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.merlin.kernel;
  
  import java.net.URL;
  import java.io.File;
  
  import org.apache.avalon.repository.criteria.Criteria;
  import org.apache.avalon.repository.criteria.Parameter;
  
  
  /**
   * A service that provides access to versioned resources.
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2003/11/24 08:10:36 $
   */
  public interface KernelCriteria extends Criteria
  {
     /**
      * Repository parameter descriptor.
      */
      public static final Parameter MERLIN_REPOSITORY_DIR = 
        new Parameter( 
          "urn:merlin:repository.dir",
          File.class.getName(),
          false );
  
     /**
      * Library path parameter descriptor.
      */
      public static final Parameter MERLIN_LIBRARY_DIR = 
        new Parameter( 
          "urn:merlin:library.dir",
          File.class.getName(),
          false );
  
     /**
      * Home directory parameter descriptor.
      */
      public static final Parameter MERLIN_HOME_DIR = 
        new Parameter( 
          "urn:merlin:home.dir",
          File.class.getName(),
          false );
  
     /**
      * Base directory parameter descriptor.
      */
      public static final Parameter MERLIN_BASE_DIR = 
        new Parameter( 
          "urn:merlin:base.dir",
          File.class.getName(),
          false );
  
     /**
      * Kernel url parameter descriptor.
      */
      public static final Parameter MERLIN_KERNEL_URL = 
        new Parameter( 
          "urn:merlin:kernel.url",
          URL.class.getName(),
          false );
  
     /**
      * Info policy parameter descriptor.
      */
      public static final Parameter MERLIN_POLICY_INFO = 
        new Parameter( 
          "urn:merlin:policy.info",
          Boolean.class.getName(),
          false );
  
     /**
      * Debug policy parameter descriptor.
      */
      public static final Parameter MERLIN_POLICY_DEBUG = 
        new Parameter( 
          "urn:merlin:policy.debug",
          Boolean.class.getName(),
          false );
  
     /**
      * Server model parameter descriptor.
      */
      public static final Parameter MERLIN_POLICY_SERVER = 
        new Parameter( 
          "urn:merlin:policy.server",
          Boolean.class.getName(),
          false );
  
     /**
      * The factory parameters template.
      */
      public static final Parameter[] PARAMS = 
        new Parameter[]{
             MERLIN_REPOSITORY_DIR,
             MERLIN_LIBRARY_DIR,
             MERLIN_HOME_DIR,
             MERLIN_BASE_DIR,
             MERLIN_KERNEL_URL,
             MERLIN_POLICY_INFO,
             MERLIN_POLICY_DEBUG,
             MERLIN_POLICY_SERVER };
  
  }
  
  
  
  1.2       +64 -28    
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java
  
  Index: DefaultCriteria.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultCriteria.java      23 Nov 2003 00:47:06 -0000      1.1
  +++ DefaultCriteria.java      24 Nov 2003 08:10:36 -0000      1.2
  @@ -50,6 +50,7 @@
   
   package org.apache.avalon.merlin.kernel.impl;
   
  +import org.apache.avalon.merlin.kernel.KernelCriteria;
   import org.apache.avalon.repository.criteria.Criteria;
   import org.apache.avalon.repository.criteria.Template;
   import org.apache.avalon.repository.criteria.ValidationException;
  @@ -65,32 +66,15 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
    * @version $Revision$
    */
  -public class DefaultCriteria implements Criteria
  +public class DefaultCriteria implements KernelCriteria
   {
       //--------------------------------------------------------------
       // state
       //--------------------------------------------------------------
   
  -     private final Template m_template;
        private final Hashtable m_bindings = new Hashtable();
   
       //--------------------------------------------------------------
  -    // constructor
  -    //--------------------------------------------------------------
  -
  -    /**
  -     * Creation of a new criteria.
  -     * @param template the template containing the validation parameters
  -     */
  -    public DefaultCriteria( Template template )
  -    {
  -        if( null == template ) 
  -         throw new NullPointerException( "template" ); 
  -
  -        m_template = template;
  -    }
  -
  -    //--------------------------------------------------------------
       // Criteria
       //--------------------------------------------------------------
   
  @@ -98,9 +82,9 @@
       * Return the template backing the criteria.
       * @return the template
       */
  -    public Template getTemplate()
  +    public Parameter[] getParameters()
       {
  -        return m_template;
  +        return PARAMS;
       }
   
      /**
  @@ -113,8 +97,8 @@
       public void setValue( final String key, final Object value ) 
         throws ValidationException
       {
  -        Parameter p = m_template.getParameter( key );
  -        p.verify( value );
  +        Parameter p = getParameter( key );
  +        verify( p, value );
           m_bindings.put( key, value );
       }
   
  @@ -124,7 +108,7 @@
       */
       public Object getValue( final String key )
       {
  -        m_template.getParameter( key ); // verify key
  +        getParameter( key ); // verify key
           return m_bindings.get( key );
       }
   
  @@ -135,11 +119,10 @@
       public Map getMap()
       {
           Hashtable map = new Hashtable();
  -        String[] keys = getTemplate().getKeys();
  -        for( int i=0; i<keys.length; i++ )
  +        for( int i=0; i<PARAMS.length; i++ )
           {
  -            final String key = keys[i];
  -            Object value = getValue( key );
  +            final String key = PARAMS[i].getKey();
  +            Object value = m_bindings.get( key );
               if( value != null )
               {
                   map.put( key, value );
  @@ -152,4 +135,57 @@
       {
           return "[merlin: " + getMap() + "]";
       }
  +
  +   /**
  +    * Verify a value relative to the parameter constraints.
  +    * @param value the value to verify
  +    * @exception ValidationException if the value is invalid
  +    */
  +    public void verify( Parameter param, Object value )
  +      throws ValidationException
  +    {
  +        Class c = getParameterClass( param );
  +        if( value == null ) return;
  +        if( !c.isInstance( value ) )
  +        {
  +            final String error =
  +              "Value of class: [" 
  +              + value.getClass().getName() 
  +              + "] supplied for key [" 
  +              + param.getKey() 
  +              + "] is not an instance of type: [" 
  +              + param.getClassname()
  +              + "].";
  +            throw new ValidationException( error );
  +        }
  +    }
  +
  +    private Class getParameterClass( Parameter param ) 
  +      throws ValidationException
  +    {
  +        try
  +        {
  +            ClassLoader loader = Thread.currentThread().getContextClassLoader();
  +            return loader.loadClass( param.getClassname() );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Unable to resolve parameter class: " 
  +              + param.getClassname();
  +            throw new ValidationException( error, e );
  +        }
  +    }
  +
  +    public Parameter getParameter( final String key )
  +    {
  +        for( int i=0; i<PARAMS.length; i++ )
  +        {
  +            Parameter parameter = PARAMS[i];
  +            if( parameter.getKey().equals( key ) ) return parameter;
  +        }
  +        final String error = "Unknown key: [" + key + "].";
  +        throw new IllegalArgumentException( error );
  +    }
  +
   }
  
  
  
  1.3       +11 -100   
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultFactory.java       23 Nov 2003 02:26:20 -0000      1.2
  +++ DefaultFactory.java       24 Nov 2003 08:10:36 -0000      1.3
  @@ -27,116 +27,27 @@
       private static Resources REZ =
           ResourceManager.getPackageResources( DefaultFactory.class );
   
  -   /**
  -    * Repository parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_REPOSITORY_DIR = 
  -      new Parameter( 
  -        "urn:merlin:repository.dir",
  -        File.class.getName(),
  -        false,
  -        REZ.getString( "template-repository-dir" ) );
  -
  -   /**
  -    * Library path parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_LIBRARY_DIR = 
  -      new Parameter( 
  -        "urn:merlin:library.dir",
  -        File.class.getName(),
  -        false,
  -        REZ.getString( "template-library-dir" ) );
  -
  -   /**
  -    * Home directory parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_HOME_DIR = 
  -      new Parameter( 
  -        "urn:merlin:home.dir",
  -        File.class.getName(),
  -        false,
  -        REZ.getString( "template-home-dir" ) );
  -
  -   /**
  -    * Base directory parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_BASE_DIR = 
  -      new Parameter( 
  -        "urn:merlin:base.dir",
  -        File.class.getName(),
  -        false,
  -        REZ.getString( "template-base-dir" ) );
  -
  -   /**
  -    * Kernel url parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_KERNEL_URL = 
  -      new Parameter( 
  -        "urn:merlin:kernel.url",
  -        URL.class.getName(),
  -        false,
  -        REZ.getString( "template-kernel-url" ) );
  -
  -   /**
  -    * Info policy parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_POLICY_INFO = 
  -      new Parameter( 
  -        "urn:merlin:policy.info",
  -        Boolean.class.getName(),
  -        false,
  -        REZ.getString( "template-info-policy" ) );
  -
  -   /**
  -    * Debug policy parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_POLICY_DEBUG = 
  -      new Parameter( 
  -        "urn:merlin:policy.debug",
  -        Boolean.class.getName(),
  -        false,
  -        REZ.getString( "template-debug-policy" ) );
  -
  -   /**
  -    * Server model parameter descriptor.
  -    */
  -    public static final Parameter MERLIN_POLICY_SERVER = 
  -      new Parameter( 
  -        "urn:merlin:policy.server",
  -        Boolean.class.getName(),
  -        false,
  -        REZ.getString( "template-server-policy" ) );
  -
  -   /**
  -    * The factory parameters template.
  -    */
  -    public static final Template TEMPLATE = 
  -      new Template(
  -        REZ.getString( "template-description" ),
  -        new Parameter[]
  -        {
  -           MERLIN_REPOSITORY_DIR,
  -           MERLIN_LIBRARY_DIR,
  -           MERLIN_HOME_DIR,
  -           MERLIN_BASE_DIR,
  -           MERLIN_KERNEL_URL,
  -           MERLIN_POLICY_INFO,
  -           MERLIN_POLICY_DEBUG,
  -           MERLIN_POLICY_SERVER
  -        } );
  -
       //--------------------------------------------------------------------------
       // Factory
       //--------------------------------------------------------------------------
   
       public Criteria createDefaultCriteria()
       {
  -        return new DefaultCriteria( TEMPLATE );
  +        return new DefaultCriteria();
       }
   
  -    public Object create( Map map )
  +    public Object create()
  +    {
  +        return create( createDefaultCriteria() );
  +    }
  +
  +    public Object create( Criteria criteria )
       {
  +        return create( criteria.getMap() );
  +    }
   
  +    public Object create( Map map )
  +    {
           //
           // Alex - over to you.  The supplied map
           // has a set of values bound to keys defined in 
  
  
  
  1.3       +2 -2      
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelContext.java
  
  Index: DefaultKernelContext.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultKernelContext.java 23 Nov 2003 00:47:06 -0000      1.2
  +++ DefaultKernelContext.java 24 Nov 2003 08:10:36 -0000      1.3
  @@ -83,7 +83,7 @@
   import org.apache.avalon.merlin.kernel.KernelException;
   import org.apache.avalon.merlin.kernel.KernelRuntimeException;
   import org.apache.avalon.repository.Repository;
  -import org.apache.avalon.repository.ProxyContext;
  +import org.apache.avalon.repository.impl.ProxyContext;
   import org.apache.avalon.repository.impl.DefaultAuthenticator;
   import org.apache.avalon.repository.impl.DefaultFileRepository;
   import org.apache.excalibur.configuration.ConfigurationUtil;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to