avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/runtime/impl DefaultRuntimeFactory.java Resources.properties
Date Sat, 07 Feb 2004 22:46:42 GMT
mcconnell    2004/02/07 14:46:42

  Modified:    merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl
                        AbstractAppliance.java
               merlin/composition/api/src/java/org/apache/avalon/composition/model
                        SystemContext.java
               merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
                        DefaultContainmentModel.java
                        DefaultSystemContext.java Scanner.java
               merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
                        DefaultFactory.java DefaultKernel.java
  Added:       merlin/composition/impl/src/java/org/apache/avalon/composition/runtime/impl
                        DefaultRuntimeFactory.java Resources.properties
  Removed:     merlin/composition/api/src/java/org/apache/avalon/composition/model
                        RuntimeFactory.java
               merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
                        DelegatingSystemContext.java
  Log:
  Getting into dangerouse territory - adding a runtime factory to the model.
  
  Revision  Changes    Path
  1.5       +5 -5      avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/AbstractAppliance.java
  
  Index: AbstractAppliance.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/appliance/impl/AbstractAppliance.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractAppliance.java	24 Jan 2004 23:25:21 -0000	1.4
  +++ AbstractAppliance.java	7 Feb 2004 22:46:42 -0000	1.5
  @@ -61,6 +61,10 @@
   
       public AbstractAppliance( DeploymentModel model )
       {
  +        if( null == m_model ) 
  +        {
  +            throw new NullPointerException( "model" );
  +        }
           enableLogging( model.getLogger() );
           m_model = model;
           m_model.setHandler( this );
  @@ -76,10 +80,6 @@
        */
       public DeploymentModel getModel()
       {
  -        if( null == m_model ) 
  -        {
  -            throw new NullPointerException( "model" );
  -        }
           return m_model;
       }
   
  
  
  
  1.7       +3 -1      avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/SystemContext.java
  
  Index: SystemContext.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/SystemContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SystemContext.java	7 Feb 2004 14:03:42 -0000	1.6
  +++ SystemContext.java	7 Feb 2004 22:46:42 -0000	1.7
  @@ -19,6 +19,8 @@
   
   import java.io.File;
   
  +import org.apache.avalon.composition.runtime.RuntimeFactory;
  +
   import org.apache.avalon.logging.provider.LoggingManager;
   
   import org.apache.avalon.repository.Repository;
  
  
  
  1.30      +5 -9      avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
  
  Index: DefaultContainmentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- DefaultContainmentModel.java	7 Feb 2004 20:21:03 -0000	1.29
  +++ DefaultContainmentModel.java	7 Feb 2004 22:46:42 -0000	1.30
  @@ -705,11 +705,9 @@
               }
               catch( Throwable e )
               {
  -                final String message = 
  -                  "A composition listener raised an exception";
                   final String error = 
  -                  ExceptionHelper.packException( message, e, true );
  -                getLogger().warn( error );
  +                  "A composition listener raised an exception";
  +                getLogger().warn( error, e );
               }
           }
       }
  @@ -727,11 +725,9 @@
               }
               catch( Throwable e )
               {
  -                final String message = 
  -                  "A composition listener raised an exception";
                   final String error = 
  -                  ExceptionHelper.packException( message, e, true );
  -                getLogger().warn( error );
  +                  "A composition listener raised an exception";
  +                getLogger().warn( error, e );
               }
           }
       }
  
  
  
  1.15      +16 -6     avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContext.java
  
  Index: DefaultSystemContext.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContext.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DefaultSystemContext.java	7 Feb 2004 14:03:42 -0000	1.14
  +++ DefaultSystemContext.java	7 Feb 2004 22:46:42 -0000	1.15
  @@ -25,9 +25,10 @@
   import org.apache.avalon.logging.data.CategoryDirective;
   
   import org.apache.avalon.composition.model.ModelFactory;
  -import org.apache.avalon.composition.model.RuntimeFactory;
   import org.apache.avalon.composition.model.SystemContext;
   import org.apache.avalon.composition.model.ContainmentModel;
  +import org.apache.avalon.composition.runtime.RuntimeFactory;
  +import org.apache.avalon.composition.runtime.impl.DefaultRuntimeFactory;
   
   import org.apache.avalon.repository.Artifact;
   import org.apache.avalon.repository.Repository;
  @@ -82,6 +83,8 @@
   
       private ModelFactory m_factory;
   
  +    private RuntimeFactory m_runtime;
  +
       private final long m_timeout;
   
       private boolean m_secure;
  @@ -109,9 +112,15 @@
       * @param trace flag indicating if internal logging is enabled
       */
       public DefaultSystemContext( 
  -      LoggingManager logging, File base, File home, File temp, 
  -      Repository repository, String category, boolean trace, 
  -      long timeout, boolean secure )
  +      LoggingManager logging, 
  +      File base, 
  +      File home, 
  +      File temp, 
  +      Repository repository, 
  +      String category, 
  +      boolean trace, 
  +      long timeout, 
  +      boolean secure )
       {
           if( base == null )
           {
  @@ -145,6 +154,7 @@
           m_system = SystemContext.class.getClassLoader();
           m_common = Logger.class.getClassLoader();
           m_factory = new DefaultModelFactory( this );
  +        m_runtime = new DefaultRuntimeFactory( this );
       }
   
       //--------------------------------------------------------------
  @@ -168,7 +178,7 @@
       */
       public RuntimeFactory getRuntimeFactory()
       {
  -        throw new UnsupportedOperationException( "getRuntimeFactory" );
  +        return m_runtime;
       }
   
      /**
  
  
  
  1.6       +38 -15    avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/Scanner.java
  
  Index: Scanner.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/Scanner.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Scanner.java	24 Jan 2004 23:25:28 -0000	1.5
  +++ Scanner.java	7 Feb 2004 22:46:42 -0000	1.6
  @@ -357,7 +357,9 @@
               if( getLogger().isWarnEnabled() )
               {
                   final String error = 
  -                  REZ.getString( "scanner.type.verification.ncdf.failure", classname, e.getMessage()
);
  +                  REZ.getString( 
  +                    "scanner.type.verification.ncdf.failure", 
  +                    classname, e.getMessage() );
                   getLogger().warn( error );
               }
           }
  @@ -366,7 +368,9 @@
               if( getLogger().isWarnEnabled() )
               {
                   final String error = 
  -                  REZ.getString( "scanner.type.verification.failure", classname );
  +                  REZ.getString( 
  +                    "scanner.type.verification.failure", 
  +                    classname );
                   getLogger().warn( ExceptionHelper.packException( 
                     error, e, getLogger().isDebugEnabled() ) );
               }
  @@ -376,14 +380,17 @@
       private void addService( List list, String name ) throws Exception
       {
           String classname = parseResourceName( name );
  -        Service service = SERVICE_BUILDER.build( classname, m_classloader );
  +        Service service = 
  +          SERVICE_BUILDER.build( classname, m_classloader );
           try
           {
               verifyService( service );
               if( getLogger().isDebugEnabled() )
               {
                   final String message =
  -                  REZ.getString( "scanner.service.addition", classname );
  +                  REZ.getString( 
  +                    "scanner.service.addition", 
  +                    classname );
                   getLogger().debug( message );
               }
               list.add( service );
  @@ -393,7 +400,9 @@
               if( getLogger().isWarnEnabled() )
               {
                   final String error = 
  -                  REZ.getString( "scanner.service.verification.failure", classname );
  +                  REZ.getString( 
  +                    "scanner.service.verification.failure", 
  +                    classname );
                   getLogger().warn( ExceptionHelper.packException( 
                     error, e, getLogger().isDebugEnabled() ) );
               }
  @@ -430,13 +439,17 @@
           {
               String ref = parseResourceName( ncdf.getMessage() );
               final String error = 
  -              REZ.getString( "scanner.service.bad-class.error", classname, ref );
  +              REZ.getString( 
  +                "scanner.service.bad-class.error", 
  +                classname, ref );
               throw new ModelException( error );
           }
           catch( ClassNotFoundException cnfe )
           {
               final String error = 
  -              REZ.getString( "scanner.service.missing-class.error", classname );
  +              REZ.getString( 
  +                "scanner.service.missing-class.error", 
  +                classname );
               throw new ModelException( error );
           }
       }
  @@ -460,7 +473,8 @@
               ServiceDescriptor service = services[i];
               if( (service.getAttribute(
                 "urn:avalon:service.protocol", "native" ).equals( "native" ))
  -              && (service.getAttribute( "urn:avalon:service.accessor", null ) ==
null) )
  +              && ( service.getAttribute( 
  +                "urn:avalon:service.accessor", null ) == null) )
               {
                   list.add( getServiceClass( services[i] ) );
               }
  @@ -500,13 +514,16 @@
           {
               String ref = parseResourceName( ncdf.getMessage() );
               final String error = 
  -              REZ.getString( "scanner.type.bad-class.error", classname, ref );
  +              REZ.getString( 
  +                "scanner.type.bad-class.error", 
  +                classname, ref );
               throw new ModelException( error );
           }
           catch( ClassNotFoundException cnfe )
           {
               final String error = 
  -              REZ.getString( "scanner.type.missing-class.error", classname );
  +              REZ.getString( 
  +                "scanner.type.missing-class.error", classname );
               throw new ModelException( error );
           }
       }
  @@ -528,13 +545,15 @@
           {
               String ref = parseResourceName( ncdf.getMessage() );
               final String error = 
  -              REZ.getString( "scanner.service.bad-class.error", classname, ref );
  +              REZ.getString( 
  +                "scanner.service.bad-class.error", classname, ref );
               throw new ModelException( error );
           }
           catch( ClassNotFoundException cnfe )
           {
               final String error = 
  -              REZ.getString( "scanner.service.missing-class.error", classname );
  +              REZ.getString( 
  +                "scanner.service.missing-class.error", classname );
               throw new ModelException( error );
           }
       }
  @@ -556,7 +575,9 @@
               return file;
           }
           final String error = 
  -          REZ.getString( "scanner.url-not-a-directory.error", url.toString() );
  +          REZ.getString( 
  +            "scanner.url-not-a-directory.error", 
  +            url.toString() );
           throw new IllegalArgumentException( error );
       }
   
  @@ -567,7 +588,9 @@
               return new File( url.toString().substring( 5 ) );
           }
           final String error = 
  -          REZ.getString( "scanner.not-file-protocol.error", url.toString() );
  +          REZ.getString( 
  +            "scanner.not-file-protocol.error", 
  +            url.toString() );
           throw new IllegalArgumentException( error );
       }
   
  
  
  
  1.25      +1 -34     avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultFactory.java	7 Feb 2004 20:23:32 -0000	1.24
  +++ DefaultFactory.java	7 Feb 2004 22:46:42 -0000	1.25
  @@ -248,40 +248,7 @@
             createApplicationModel( systemContext, appConfig );
   
           //
  -        // Create the containment model describing all of the 
  -        // system facilities. These facilities may include model 
  -        // listeners and dependent components that facilitate the
  -        // customization of the runtime merlin system.  The 
  -        // facilities model receives a privaliged system context
  -        // that contains a reference to the root application model
  -        // enabling listeners to register themselves for model 
  -        // changes.
  -        // 
  -
  -        //getLogger().info( "facilities deployment" );
  -        //Configuration facilitiesConfig = 
  -        //  config.getChild( "facilities" );
  -        //Logger facilitiesLogger = getLogger();
  -
  -        //DelegatingSystemContext system = 
  -        //  new DelegatingSystemContext( systemContext );
  -        //system.put( "urn:composition:dir", criteria.getWorkingDirectory() );
  -        //system.put( "urn:composition:anchor", criteria.getAnchorDirectory() );
  -        //system.put( "urn:composition:application", application );
  -        //system.makeReadOnly();
  -
  -        //ContainmentModel facilities = 
  -        //  createFacilitiesModel( 
  -        //    system, facilitiesLogger, facilitiesConfig );
  -
  -        //
  -        // Assembly of the system containment model. Note .. its not sure
  -        // if this function should be a part of the kernel initialization
  -        // or if this belongs here in the factory.  The current view is
  -        // the factory does the work of constructing the artifacts for
  -        // the kernel and the kernel implements the kernel 
  -        // startup/shutdown behaviour and the embeddor handles any post
  -        // kernel management logic.
  +        // create the kernel
           //
   
           KernelContext kernelContext = 
  
  
  
  1.9       +3 -3      avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultKernel.java	7 Feb 2004 20:23:32 -0000	1.8
  +++ DefaultKernel.java	7 Feb 2004 22:46:42 -0000	1.9
  @@ -402,8 +402,8 @@
                   catch( Throwable e )
                   {
                       final String error = 
  -                      ExceptionHelper.packException( e, true );
  -                    getLogger().warn( error );
  +                      "Kernel listener raised an exception.";
  +                    getLogger().warn( error, e );
                   }
               }
           }
  
  
  
  1.1                  avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/runtime/impl/DefaultRuntimeFactory.java
  
  Index: DefaultRuntimeFactory.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 org.apache.avalon.composition.runtime.impl;
  
  import java.util.Map;
  import java.util.Hashtable;
  
  import org.apache.avalon.composition.model.ModelException;
  import org.apache.avalon.composition.model.ModelRuntimeException;
  import org.apache.avalon.composition.model.DeploymentModel;
  import org.apache.avalon.composition.model.ComponentModel;
  import org.apache.avalon.composition.model.ContainmentModel;
  import org.apache.avalon.composition.model.SystemContext;
  import org.apache.avalon.composition.runtime.RuntimeFactory;
  import org.apache.avalon.composition.runtime.Commissionable;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  /**
   * A factory enabling the establishment of runtime handlers.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/02/07 22:46:42 $
   */
  public class DefaultRuntimeFactory implements RuntimeFactory
  {
      //-------------------------------------------------------------------
      // static
      //-------------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( 
          DefaultRuntimeFactory.class );
  
      //-------------------------------------------------------------------
      // immutable state
      //-------------------------------------------------------------------
  
      private final SystemContext m_system;
  
      private final Map m_map = new Hashtable();
  
      //-------------------------------------------------------------------
      // constructor
      //-------------------------------------------------------------------
  
      public DefaultRuntimeFactory( SystemContext system )
      {
          m_system = system;
      }
  
      //-------------------------------------------------------------------
      // RuntimeFactory
      //-------------------------------------------------------------------
  
     /**
      * Resolve a runtime handler for a model.
      * @param model the deployment model
      * @return the runtime appliance
      */
      public Commissionable getRuntime( DeploymentModel model ) 
      {
          synchronized( m_map )
          {
  
              Commissionable runtime = getRegisteredRuntime( model );
              if( null != runtime ) return runtime;
  
              //
              // create the runtime
              //
  
              if( model instanceof ComponentModel )
              {
                  ComponentModel component = (ComponentModel) model;
                  runtime = newComponentRuntime( component );
              }
              else if( model instanceof ContainmentModel )
              {
                  ContainmentModel containment = (ContainmentModel) model;
                  runtime = newContainmentRuntime( containment );
              }
              else
              {
                  final String error = 
                    REZ.getString( 
                      "runtime.error.unknown-model", 
                      model.toString(),
                      model.getClass().getName() );
                    throw new ModelRuntimeException( error );
              }
  
              registerRuntime( model, runtime );
              return runtime;
          }
      }
  
      //-------------------------------------------------------------------
      // private implementation
      //-------------------------------------------------------------------
  
     /**
      * Resolve a runtime handler for a component model.
      * @param model the containment model
      * @return the runtime handler
      */
      private Commissionable newComponentRuntime( ComponentModel  model )
        throws ModelRuntimeException
      {
          throw new UnsupportedOperationException( "getComponentRuntime" );
      }
  
     /**
      * Resolve a runtime handler for a containment model.
      * @param model the containment model
      * @return the runtime handler
      */
      private Commissionable newContainmentRuntime( ContainmentModel model )
        throws ModelRuntimeException
      {
          throw new UnsupportedOperationException( "getContainmentRuntime" );
      }
  
     /**
      * Lookup a runtime relative to the model name.
      * @param model the deployment model
      * @return the matching runtime (possibly null)
      */
      private Commissionable getRegisteredRuntime( DeploymentModel model )
      {
          String name = model.getQualifiedName();
          return (Commissionable) m_map.get( name );
      }
  
      private void registerRuntime( DeploymentModel model, Commissionable runtime )
      {
          String name = model.getQualifiedName();
          m_map.put( name, runtime );
      }
  }
  
  
  1.1                  avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/runtime/impl/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  
  #
  # DefaultRuntimeFactory
  # =====================
  runtime.error.unknown-model=Deployment model {0} class [{1}] is not supported.
  
  

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


Mime
View raw message