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/assembly/src/java/org/apache/avalon/assembly/lifecycle/context AbstractContextualizer.java AvalonContextualizer.java ComponentInvocationHandler.java Contextualization.java ContextualizationService.java DefaultCompositionService.java DefaultContextualizationService.java DefaultContextualizer.java WrapperComponentManager.java
Date Thu, 24 Apr 2003 12:23:04 GMT
mcconnell    2003/04/24 05:23:04

  Modified:    merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle
                        DefaultDeploymentService.java
               merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context
                        AbstractContextualizer.java
                        AvalonContextualizer.java
                        ComponentInvocationHandler.java
                        Contextualization.java
                        ContextualizationService.java
                        DefaultCompositionService.java
                        DefaultContextualizationService.java
                        DefaultContextualizer.java
                        WrapperComponentManager.java
  Log:
  Updating of the contextualization handling to (a) explicity pass a classloader when resolving
narrowable context classes and (b) simplification of the contextulization process when dealing
with locator based contextualization.
  
  Revision  Changes    Path
  1.5       +4 -3      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/DefaultDeploymentService.java
  
  Index: DefaultDeploymentService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/DefaultDeploymentService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultDeploymentService.java	20 Apr 2003 12:08:43 -0000	1.4
  +++ DefaultDeploymentService.java	24 Apr 2003 12:23:04 -0000	1.5
  @@ -223,11 +223,12 @@
           try
           {
               m_logging.enableLogging( appliance, instance );
  -            m_contextualization.contextualize( appliance, instance );
  +            m_contextualization.contextualize( classloader, appliance, instance );
               m_configuration.configure( appliance, instance );
               m_initialization.initialize( appliance, instance );
               return instance;
  -        } catch( Throwable e )
  +        } 
  +        catch( Throwable e )
           {
               final String error =
                 "Component deployment failure in appliance: "
  
  
  
  1.3       +15 -9     avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/AbstractContextualizer.java
  
  Index: AbstractContextualizer.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/AbstractContextualizer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractContextualizer.java	11 Apr 2003 19:52:12 -0000	1.2
  +++ AbstractContextualizer.java	24 Apr 2003 12:23:04 -0000	1.3
  @@ -82,8 +82,9 @@
        * @param map a map of context entries
        * @exception ContextException if a contextualization error occurs
        */
  -    public abstract void contextualize( ContextDirective directive, Object object, Map
map )
  -            throws ContextException;
  +    public abstract void contextualize( 
  +      ClassLoader loader, ContextDirective directive, Object object, Map map )
  +      throws ContextException;
   
       /**
        * Returns a instance of a class established using the supplied map as a
  @@ -94,8 +95,9 @@
        * @param map the context entry map
        * @return the context argument value
        */
  -    public Object createContextArgument( ContextDirective directive, Class clazz, Map map
)
  -            throws ContextException
  +    public Object createContextArgument( 
  +      ClassLoader loader, ContextDirective directive, Class clazz, Map map )
  +      throws ContextException
       {
           if( directive == null )
           {
  @@ -116,13 +118,15 @@
           {
               try
               {
  -                base = Thread.currentThread().getContextClassLoader().loadClass( classname
);
  -            } catch( ClassNotFoundException cnfe )
  +                base = loader.loadClass( classname );
  +            } 
  +            catch( ClassNotFoundException cnfe )
               {
                   throw new ContextException(
                           "Could not find context class: " + classname, cnfe );
               }
  -        } else
  +        } 
  +        else
           {
               base = clazz;
           }
  @@ -132,13 +136,15 @@
               Constructor constructor = base.getConstructor(
                       new Class[]{Map.class} );
               return constructor.newInstance( new Object[]{map} );
  -        } catch( NoSuchMethodException e )
  +        } 
  +        catch( NoSuchMethodException e )
           {
               final String error =
                       "Custom context class: [" + classname
                       + "] does not implement a constructor pattern <init>{ Map }.";
               throw new ContextException( error, e );
  -        } catch( Throwable e )
  +        } 
  +        catch( Throwable e )
           {
               throw new ContextException(
                       "Unexpected exception while creating context from "
  
  
  
  1.3       +7 -4      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/AvalonContextualizer.java
  
  Index: AvalonContextualizer.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/AvalonContextualizer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AvalonContextualizer.java	11 Apr 2003 19:52:12 -0000	1.2
  +++ AvalonContextualizer.java	24 Apr 2003 12:23:04 -0000	1.3
  @@ -92,21 +92,24 @@
       /**
        * Handle the contextualization stage of a component lifecycle.
        *
  +     * @param loader the classloader
        * @param descriptor the context descriptor
        * @param object the object to contextualize
        * @param map a map of context entries
        * @exception ContextException if a contextualization error occurs
        */
  -    public void contextualize( ContextDirective directive, Object object, Map map )
  -            throws ContextException
  +    public void contextualize( 
  +      ClassLoader loader, ContextDirective directive, Object object, Map map )
  +      throws ContextException
       {
           if( object instanceof Contextualizable )
           {
  -            Object context = createContextArgument( directive, DefaultContext.class, map
);
  +            Object context = createContextArgument( loader, directive, DefaultContext.class,
map );
               if( context instanceof Context )
               {
                   ((Contextualizable) object).contextualize( (Context) context );
  -            } else
  +            } 
  +            else
               {
                   final String error =
                           "Requested context implementation " + context.getClass().getName()
  
  
  
  1.4       +2 -2      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/ComponentInvocationHandler.java
  
  Index: ComponentInvocationHandler.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/ComponentInvocationHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ComponentInvocationHandler.java	11 Apr 2003 19:52:12 -0000	1.3
  +++ ComponentInvocationHandler.java	24 Apr 2003 12:23:04 -0000	1.4
  @@ -127,7 +127,7 @@
       {
           if( null == m_object )
           {
  -            throw new IllegalStateException( "Invalid proxy." );
  +            throw new IllegalStateException( "Object has not been initialized." );
           }
   
           try
  
  
  
  1.3       +2 -5      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/Contextualization.java
  
  Index: Contextualization.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/Contextualization.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Contextualization.java	11 Apr 2003 19:52:12 -0000	1.2
  +++ Contextualization.java	24 Apr 2003 12:23:04 -0000	1.3
  @@ -68,18 +68,15 @@
    */
   public interface Contextualization
   {
  -    //=======================================================================
  -    // Extension
  -    //=======================================================================
  -
       /**
        * Handle the contextualization stage of a component lifecycle.
        *
  +     * @param loader the classloader
        * @param directive the context directive
        * @param object the object to contextualize
        * @param map a map of context entries
        * @exception ContextException if a contextualization error occurs
        */
  -    void contextualize( ContextDirective directive, Object object, Map map )
  +    void contextualize( ClassLoader loader, ContextDirective directive, Object object,
Map map )
               throws ContextException;
   }
  
  
  
  1.4       +4 -3      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/ContextualizationService.java
  
  Index: ContextualizationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/ContextualizationService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ContextualizationService.java	20 Apr 2003 12:08:43 -0000	1.3
  +++ ContextualizationService.java	24 Apr 2003 12:23:04 -0000	1.4
  @@ -66,10 +66,11 @@
   
       /**
        * Contextualize the supplied object.
  -     * @param appliance the object to contextualize
  +     * @param classloader the classloader
  +     * @param appliance the appliance
        * @param object the object to contextualize
        */
       void contextualize(
  -            Appliance appliance, Object object )
  +            ClassLoader loader, Appliance appliance, Object object )
               throws Exception;
   }
  
  
  
  1.4       +4 -3      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultCompositionService.java
  
  Index: DefaultCompositionService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultCompositionService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultCompositionService.java	11 Apr 2003 19:52:12 -0000	1.3
  +++ DefaultCompositionService.java	24 Apr 2003 12:23:04 -0000	1.4
  @@ -74,9 +74,10 @@
        * @param appliance the appliance
        * @param object the object to service
        */
  -    public void contextualize( Appliance appliance, Object object ) throws Exception
  +    public void contextualize( 
  +      ClassLoader loader, Appliance appliance, Object object ) throws Exception
       {
  -        super.contextualize( appliance, object );
  +        super.contextualize( loader, appliance, object );
   
           if( object instanceof Serviceable )
           {
  
  
  
  1.4       +49 -19    avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizationService.java
  
  Index: DefaultContextualizationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizationService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultContextualizationService.java	11 Apr 2003 19:52:12 -0000	1.3
  +++ DefaultContextualizationService.java	24 Apr 2003 12:23:04 -0000	1.4
  @@ -77,12 +77,19 @@
        * @param appliance the appliace
        * @param object the object to contextualize
        */
  -    public void contextualize( Appliance appliance, Object object ) throws Exception
  +    public void contextualize( 
  +      ClassLoader loader, Appliance appliance, Object object ) throws Exception
       {
  +        if( loader == null )
  +        {
  +            throw new NullPointerException( "loader" );
  +        }
  +
           if( appliance == null )
           {
               throw new NullPointerException( "appliance" );
           }
  +
           if( object == null )
           {
               throw new NullPointerException( "object" );
  @@ -112,7 +119,8 @@
                   try
                   {
                       Contextualization handler = (Contextualization) provider.resolve( this
);
  -                    handler.contextualize( appliance.getContextDirective(), object, context
);
  +                    handler.contextualize( 
  +                      loader, appliance.getContextDirective(), object, context );
                       provider.release( handler, this );
                       return;
                   } catch( Throwable e )
  @@ -125,24 +133,21 @@
   
               if( object instanceof Contextualizable )
               {
  -
                   //
                   // its classic Avalon contextulization
                   //
  -
  +                Contextualization contextualizer = new AvalonContextualizer();
                   if( getLogger().isDebugEnabled() )
                   {
  -                    final String message = appliance.toString();
  +                    final String message = appliance.toString() + " (Avalon Policy)";
                       getLogger().debug( message );
                   }
                   try
                   {
  -                    Contextualization contextualizer = new AvalonContextualizer();
                       contextualizer.contextualize(
  -                            appliance.getContextDirective(), object, context );
  -
  -                    //((Contextualizable)object).contextualize( new DefaultContext( context
) );
  -                } catch( ContextException e )
  +                      loader, appliance.getContextDirective(), object, context );
  +                }
  +                catch( ContextException e )
                   {
                       //
                       // this could be improved if the framework ContextException
  @@ -150,9 +155,9 @@
                       //
   
                       final String error =
  -                            "Target component is requesting a context entry that has not
been declared."
  -                            + " Please check component xinfo descriptor context criteria
in type: "
  -                            + appliance.getType();
  +                       "Target component is requesting a context entry that has not been
declared."
  +                       + " Please check component xinfo descriptor context criteria in
type: "
  +                       + appliance.getType();
                       throw new ContextException( error, e );
                   } catch( Throwable e )
                   {
  @@ -160,18 +165,43 @@
                               "Unexpected exception during contextualization of target: "
+ appliance;
                       throw new ContextException( error, e );
                   }
  -            } else
  +            }
  +            else if( object instanceof org.apache.avalon.assembly.locator.Contextualizable
)
  +            {
  +                //
  +                // locator contextulization
  +                //
  +
  +                Contextualization contextualizer = new DefaultContextualizer();
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    final String message = appliance.toString() + " (Locator Policy)";
  +                    getLogger().debug( message );
  +                }
  +                try
  +                {
  +                    contextualizer.contextualize(
  +                      loader, appliance.getContextDirective(), object, context );
  +                }
  +                catch( Throwable e )
  +                {
  +                    final String error =
  +                      "Unexpected exception during contextualization of target: " + appliance;
  +                    throw new ContextException( error, e );
  +                }
  +            }
  +            else
               {
                   //
                   // the appliance has established a context argument for classic Avalon
                   // contextualization but the target object does not implement the
  -                // Avalon Contextualization interface
  +                // Avalon or Locator Contextualization interface
                   //
   
                   final String error =
  -                        "Appliance "
  -                        + appliance
  -                        + " is handling an object that is declaring a contextualization
dependency but does not implement the Avalon Contextualization interface.";
  +                  "Appliance "
  +                  + appliance
  +                  + " is handling an object that is declaring a contextualization dependency
but does not implement the Avalon or Locator Contextualization interface.";
                   throw new ContextException( error );
               }
           }
  
  
  
  1.3       +8 -6      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizer.java
  
  Index: DefaultContextualizer.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultContextualizer.java	11 Apr 2003 19:52:12 -0000	1.2
  +++ DefaultContextualizer.java	24 Apr 2003 12:23:04 -0000	1.3
  @@ -97,20 +97,22 @@
        * @param map a map of context entries
        * @exception ContextException if a contextualization error occurs
        */
  -    public void contextualize( ContextDirective directive, Object object, Map map )
  -            throws ContextException
  +    public void contextualize( 
  +      ClassLoader loader, ContextDirective directive, Object object, Map map )
  +      throws ContextException
       {
           if( object instanceof Contextualizable )
           {
  -            Object context = createContextArgument( directive, DefaultLocator.class, map
);
  +            Object context = createContextArgument( loader, directive, DefaultLocator.class,
map );
               if( context instanceof Locator )
               {
                   ((Contextualizable) object).contextualize( (Locator) context );
  -            } else
  +            } 
  +            else
               {
                   final String error =
  -                        "Requested context implementation class " + context.getClass().getName()
  -                        + " does not implement the Locator interface.";
  +                  "Requested context implementation class " + context.getClass().getName()
  +                  + " does not implement the Locator interface.";
                   throw new ContextException( error );
               }
           }
  
  
  
  1.4       +16 -12    avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/WrapperComponentManager.java
  
  Index: WrapperComponentManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/WrapperComponentManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WrapperComponentManager.java	11 Apr 2003 19:52:12 -0000	1.3
  +++ WrapperComponentManager.java	24 Apr 2003 12:23:04 -0000	1.4
  @@ -100,12 +100,14 @@
               if( object instanceof ServiceSelector )
               {
                   return new WrapperComponentSelector( key, (ServiceSelector) object );
  -            } else
  +            } 
  +            else
               {
                   if( object instanceof Component )
                   {
                       return (Component) object;
  -                } else
  +                } 
  +                else
                   {
                       //
                       // use the services defined by the type and use them to
  @@ -117,21 +119,22 @@
                       if( !(loader instanceof Engine) )
                       {
                           final String error =
  -                                "Resolved component is not contained within an engine classloader.
"
  -                                + "Cannot build a Component interface proxy.";
  +                          "Resolved component is not contained within an engine classloader.
"
  +                          + "Cannot build a Component interface proxy.";
                           throw new ComponentException( key, error );
                       }
   
                       Type type =
  -                            ((Engine) loader).getRepository().getTypeManager()
  -                            .getType( clazz );
  +                      ((Engine) loader).getRepository().getTypeRepository().getType( clazz
);
                       return new ComponentInvocationHandler( object, type ).getProxy();
                   }
               }
  -        } catch( final ServiceException se )
  +        } 
  +        catch( final ServiceException se )
           {
               throw new ComponentException( se.getKey(), se.getMessage(), se.getCause() );
  -        } catch( final Throwable e )
  +        } 
  +        catch( final Throwable e )
           {
               final String error =
                       "Unexpected error while handling component lookup request.";
  @@ -163,9 +166,10 @@
       {
           if( component instanceof WrapperComponentSelector )
           {
  -            m_manager.
  -                    release( ((WrapperComponentSelector) component).getWrappedSelector()
);
  -        } else
  +            m_manager.release( 
  +              ((WrapperComponentSelector) component).getWrappedSelector() );
  +        } 
  +        else
           {
               m_manager.release( component );
           }
  
  
  

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


Mime
View raw message