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/impl AbstractContextualizer.java AvalonContextualizer.java AvalonContextualizer.xinfo AvalonServiceManager.java ComponentInvocationHandler.java Contextualization.java ContextualizationService.java DefaultCompositionService.java DefaultContextualizationService.java DefaultContextualizer.java DefaultContextualizer.xinfo WrapperComponentManager.java WrapperComponentSelector.java DefaultDeploymentService.java
Date Tue, 29 Apr 2003 00:55:46 GMT
mcconnell    2003/04/28 17:55:46

  Modified:    merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl
                        DefaultDeploymentService.java
  Added:       merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl
                        AbstractContextualizer.java
                        AvalonContextualizer.java
                        AvalonContextualizer.xinfo
                        AvalonServiceManager.java
                        ComponentInvocationHandler.java
                        Contextualization.java
                        ContextualizationService.java
                        DefaultCompositionService.java
                        DefaultContextualizationService.java
                        DefaultContextualizer.java
                        DefaultContextualizer.xinfo
                        WrapperComponentManager.java
                        WrapperComponentSelector.java
  Removed:     merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/context
                        AbstractContextualizer.java
                        AvalonContextualizer.java
                        AvalonContextualizer.xinfo
                        AvalonServiceManager.java
                        ComponentInvocationHandler.java
                        Contextualization.java
                        ContextualizationService.java
                        DefaultCompositionService.java
                        DefaultContextualizationService.java
                        DefaultContextualizer.java
                        DefaultContextualizer.xinfo
                        WrapperComponentManager.java
                        WrapperComponentSelector.java package.html
  Log:
  Consolidating context under impl.
  
  Revision  Changes    Path
  1.4       +3 -3      avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultDeploymentService.java
  
  Index: DefaultDeploymentService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultDeploymentService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultDeploymentService.java	29 Apr 2003 00:49:00 -0000	1.3
  +++ DefaultDeploymentService.java	29 Apr 2003 00:55:46 -0000	1.4
  @@ -53,8 +53,8 @@
   import org.apache.avalon.assembly.appliance.Appliance;
   import org.apache.avalon.assembly.lifecycle.DeploymentException;
   import org.apache.avalon.assembly.lifecycle.DeploymentService;
  -import org.apache.avalon.assembly.lifecycle.context.ContextualizationService;
  -import org.apache.avalon.assembly.lifecycle.context.DefaultCompositionService;
  +import org.apache.avalon.assembly.lifecycle.impl.ContextualizationService;
  +import org.apache.avalon.assembly.lifecycle.impl.DefaultCompositionService;
   //import org.apache.avalon.assembly.lifecycle.initialization.DefaultInitializationService;
   //import org.apache.avalon.assembly.lifecycle.initialization.ExtendedInitializationService;
   //import org.apache.avalon.assembly.lifecycle.initialization.InitializationService;
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/AbstractContextualizer.java
  
  Index: AbstractContextualizer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.assembly.lifecycle.impl;
  
  import java.lang.reflect.Constructor;
  import java.util.Map;
  
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.meta.model.ContextDirective;
  
  /**
   * The abstract contextualizer class is a utility class that provides
   * support for the establishment of a custom context argument based on
   * mata info supplied under a context descriptor.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public abstract class AbstractContextualizer implements Contextualization
  {
      //=======================================================================
      // Extension
      //=======================================================================
  
      /**
       * Handle the contextualization stage of a component lifecycle.
       *
       * @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 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
       * constructor argument.
       *
       * @param descriptor the context descriptor
       * @param clazz the default class if no class defined in the descriptor
       * @param map the context entry map
       * @return the context argument value
       */
      public Object createContextArgument( 
        ClassLoader loader, ContextDirective directive, Class clazz, Map map )
        throws ContextException
      {
          if( directive == null )
          {
              throw new NullPointerException( "directive" );
          }
          if( clazz == null )
          {
              throw new NullPointerException( "clazz" );
          }
          if( map == null )
          {
              throw new NullPointerException( "map" );
          }
  
          String classname = directive.getClassname();
          Class base;
          if( classname != null )
          {
              try
              {
                  base = loader.loadClass( classname );
              } 
              catch( ClassNotFoundException cnfe )
              {
                  throw new ContextException(
                          "Could not find context class: " + classname, cnfe );
              }
          } 
          else
          {
              base = clazz;
          }
  
          try
          {
              Constructor constructor = base.getConstructor(
                      new Class[]{Map.class} );
              return constructor.newInstance( new Object[]{map} );
          } 
          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 )
          {
              throw new ContextException(
                      "Unexpected exception while creating context from "
                      + base.getName(), e );
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/AvalonContextualizer.java
  
  Index: AvalonContextualizer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.assembly.lifecycle.impl;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.meta.model.ContextDirective;
  
  /**
   * Definition of an strategy handler that handles the Contextualization
   * process. This implementation is provided as a template for alternative
   * context handlers.  The requirements for introduction of an alternative
   * handler include:
   * <ul>
   * <li>A class implementing the {@link Contextualization} handler interface.</li>
   * <li>Declaration in the classes xinfo of the extension type where the
   *       type attribute value is a version interface reference corresponding
   *       to the interface that the target component must implement.</li>
   * <li>Declaration by the target component in it's xinfo atttributes
   *       of the criteria for a custom context handler under the attribute
   *       key "urn:assembly:lifecycle.context.strategy" and value
   *       corresponding to the strategy type. </li>
   * <li>Implementation of the strategy type interface by the target
   *       component.</li>
   * </ul>
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public class AvalonContextualizer extends AbstractContextualizer
  {
      //=======================================================================
      // Extension
      //=======================================================================
  
      /**
       * 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( 
        ClassLoader loader, ContextDirective directive, Object object, Map map )
        throws ContextException
      {
          if( object instanceof Contextualizable )
          {
              Object context = createContextArgument( loader, directive, DefaultContext.class, map );
              if( context instanceof Context )
              {
                  ((Contextualizable) object).contextualize( (Context) context );
              } 
              else
              {
                  final String error =
                          "Requested context implementation " + context.getClass().getName()
                          + " does not implement the Context interface.";
                  throw new ContextException( error );
              }
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/AvalonContextualizer.xinfo
  
  Index: AvalonContextualizer.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE type
        PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
               "http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
  
  <!--  
  Copyright (C) The Apache Software Foundation. All rights reserved.
  This software is published under the terms of the Apache Software License
  version 1.1, a copy of which has been included with this distribution in
  the LICENSE.txt file.
  
  @author  Avalon Development Team
  @version 1.0 12/03/2001
  -->
  
  <!--
  Definition of the extension type phase support.
  -->
  
  <type>
  
    <info>
      <name>context</name>
    </info>
  
    <!--
    Declaration of the lifecycle support phases that this manager provides. 
    -->
    <extensions>
      <extension type="org.apache.avalon.framework.context.Contextualizable:4.1" phase="CONTEXT" />
    </extensions>
  
  </type>
  
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/AvalonServiceManager.java
  
  Index: AvalonServiceManager.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.assembly.lifecycle.impl;
  
  import java.util.Hashtable;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.meta.info.DependencyDescriptor;
  
  /**
   * Helper class the implements the <code>ServiceManager</code> interface and
   * is supplied to componets during lifecyle processing.
   * @author Stephen McConnell <mcconnell@osm.net>
   */
  public class AvalonServiceManager extends AbstractLogEnabled implements ServiceManager
  {
  
      //========================================================================
      // state
      //========================================================================
  
      /**
       * The appliance from which provide appliances are resolved.
       */
      private Appliance m_appliance;
  
      /**
       * A table of appliance instances keyed by the object that was provided
       * by the appliance so that we can locate the correct appliance when
       * releasing the object.
       */
      private Hashtable m_table = new Hashtable();
  
      //========================================================================
      // constructor
      //========================================================================
  
      /**
       * Construct a new ServiceManager.
       * @param profile the component profile
       */
      public AvalonServiceManager( Appliance appliance )
      {
          m_appliance = appliance;
      }
  
      //========================================================================
      // ServiceManager
      //========================================================================
  
      /**
       * Returns true if a provider exists for the supplied role.
       * @param role the service identifier
       * @return boolean TRUE if the service is available else FALSE
       */
      public boolean hasService( String role )
      {
          return (m_appliance.getServiceProvider( role ) != null);
      }
  
      /**
       * Retrieve Object by role from ComponentLocator.
       * @param role the role
       * @return the Object
       * @throws ServiceException if an error occurs
       */
      public Object lookup( String role ) throws ServiceException
      {
          if( role == null )
          {
              throw new NullPointerException( "role" );
          }
  
          DependencyDescriptor dependency =
                  m_appliance.getType().getDependency( role );
          Appliance provider = m_appliance.getServiceProvider( role );
          if( provider == null )
          {
              final String error =
                      "Internal error - incorrect assembly in appliance: " + m_appliance
                      + ". A null provider was retured for the dependency: " + dependency;
              throw new ServiceException( role, error );
          }
  
          try
          {
              //Object object = provider.access( dependency );
              Object object = provider.resolve( this );
              m_table.put( object, provider );
              return object;
          } catch( Throwable e )
          {
              final String error =
                      "Unexpected internal error while accessing a service provider in appliance: "
                      + m_appliance
                      + " for the role: " + role;
              throw new ServiceException( role, error, e );
          }
      }
  
      /**
       * Release a pooled object.
       * @param object a pooled object
       */
      public void release( Object object )
      {
          Appliance provider = (Appliance) m_table.get( object );
          if( provider == null )
          {
              if( getLogger().isWarnEnabled() )
              {
                  final String warning =
                          "Inconsistent release request - the object: "
                          + object.getClass().getName()
                          + "/" + System.identityHashCode( object )
                          + " was not provided by this manager.";
                  getLogger().warn( warning );
              }
          } else
          {
              //provider.release( object );
              provider.release( object, this );
              m_table.remove( object );
          }
      }
  }
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/ComponentInvocationHandler.java
  
  Index: ComponentInvocationHandler.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 apache@apache.org.
  
   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.assembly.lifecycle.impl;
  
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.lang.reflect.Proxy;
  
  import org.apache.avalon.assembly.lifecycle.LifecycleException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.meta.info.ServiceDescriptor;
  import org.apache.avalon.meta.info.Type;
  
  /**
   * This makes a dynamic proxy for an object.  The object can be represented
   * by one, some or all of it's interfaces.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/04/29 00:55:46 $
   */
  final class ComponentInvocationHandler
          implements InvocationHandler
  {
      private transient Object m_object;
      private transient Component m_proxy;
  
      /**
       * Create a proxy object that has interfaces implemented by proxy defined by the component type.
       *
       * @param object the underlying object
       * @param type the component type
       * @exception if an invocation handler establishment error occurs
       */
      protected ComponentInvocationHandler( final Object object, Type type )
              throws Exception
      {
          final ClassLoader loader = object.getClass().getClassLoader();
  
          Class[] interfaces = getClasses( type, loader );
  
          m_object = object;
          m_proxy = (Component) Proxy.newProxyInstance( loader, interfaces, this );
      }
  
      /**
       * Invalidate Proxy making it impossible to call methods
       * of real-object.
       */
      public void invalidate()
      {
          m_object = null;
          m_proxy = null;
      }
  
      /**
       * Return the proxy object.
       *
       * @return the proxy object
       */
      public Component getProxy()
      {
          return m_proxy;
      }
  
      /**
       * Invoke the specified method on underlying object.
       * This is called by proxy object.
       *
       * @param proxy the proxy object
       * @param method the method invoked on proxy object
       * @param args the arguments supplied to method
       * @return the return value of method
       * @throws Throwable if an error occurs
       */
      public Object invoke( final Object proxy,
              final Method method,
              final Object[] args )
              throws Throwable
      {
          if( null == m_object )
          {
              throw new IllegalStateException( "Object has not been initialized." );
          }
  
          try
          {
              return method.invoke( m_object, args );
          } catch( final InvocationTargetException ite )
          {
              throw ite.getTargetException();
          }
      }
  
      private Class[] getClasses( Type type, ClassLoader loader ) throws Exception
      {
          try
          {
              ServiceDescriptor[] services = type.getServices();
              Class[] classes = new Class[services.length + 1];
              for( int i = 0; i < services.length; i++ )
              {
                  classes[i] = loader.loadClass( services[i].getReference().getClassname() );
              }
              classes[services.length] = Component.class;
              return classes;
          } catch( Throwable e )
          {
              final String error =
                      "Unable to create a Component proxy for an type: " + type;
              throw new LifecycleException( error, e );
          }
      }
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/Contextualization.java
  
  Index: Contextualization.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.assembly.lifecycle.impl;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.meta.model.ContextDirective;
  
  /**
   * Definition of an extension handler that handles the Contextualize
   * stage of a component lifecycle.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public interface Contextualization
  {
      /**
       * 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( ClassLoader loader, ContextDirective directive, Object object, Map map )
              throws ContextException;
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/ContextualizationService.java
  
  Index: ContextualizationService.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 apache@apache.org.
  
   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.assembly.lifecycle.impl;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  
  
  /**
   * A context service is responsible for the contextualization of a component
   * in response to a request from a lifestyle manager.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/29 00:55:46 $
   */
  public interface ContextualizationService
  {
       static final String KEY = "urn:assembly:lifecycle.context";
  
      /**
       * Contextualize the supplied object.
       * @param classloader the classloader
       * @param appliance the appliance
       * @param object the object to contextualize
       */
      void contextualize(
              ClassLoader loader, Appliance appliance, Object object )
              throws Exception;
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultCompositionService.java
  
  Index: DefaultCompositionService.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 apache@apache.org.
  
   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.assembly.lifecycle.impl;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.service.Serviceable;
  
  /**
   * A assembly service is responsible for the resolution of a component
   * service depedencies, and the construction supply of a component or
   * service manager to a target object.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/29 00:55:46 $
   */
  public class DefaultCompositionService extends DefaultContextualizationService
  {
  
      //==============================================================
      // ContextualizationService
      //==============================================================
  
      /**
       * Runtime contextualization, servicing and or composition of a target object.
       * @param appliance the appliance
       * @param object the object to service
       */
      public void contextualize( 
        ClassLoader loader, Appliance appliance, Object object ) throws Exception
      {
          super.contextualize( loader, appliance, object );
  
          if( object instanceof Serviceable )
          {
              if( getLogger().isDebugEnabled() )
              {
                  final String message = "servicing: " + appliance.toString();
                  getLogger().debug( message );
              }
              AvalonServiceManager manager = new AvalonServiceManager( appliance );
              manager.enableLogging( getLogger().getChildLogger( "manager" ) );
              ((Serviceable) object).service( manager );
  
          } else if( object instanceof Composable )
          {
              if( getLogger().isDebugEnabled() )
              {
                  final String message = "composing: " + appliance.toString();
                  getLogger().debug( message );
              }
              AvalonServiceManager manager = new AvalonServiceManager( appliance );
              manager.enableLogging( getLogger().getChildLogger( "manager" ) );
              ((Composable) object).compose(
                      new WrapperComponentManager( manager ) );
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultContextualizationService.java
  
  Index: DefaultContextualizationService.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 apache@apache.org.
  
   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.assembly.lifecycle.impl;
  
  import java.util.Map;
  
  import org.apache.avalon.assembly.appliance.Appliance;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  /**
   * The context service provides support for the contextualization of a
   * supplied component instance relative to the criteria establihsed under a
   * supplied appliance.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/29 00:55:46 $
   */
  public class DefaultContextualizationService extends AbstractLogEnabled
          implements ContextualizationService
  {
      //==============================================================
      // ContextService
      //==============================================================
  
      /**
       * Contextualization of a supplied object.
       * @param appliance the appliace
       * @param object the object to contextualize
       */
      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" );
          }
  
          Map context = appliance.getContextMap();
  
          if( context != null )
          {
              Appliance provider = appliance.getContextProvider();
  
              //
              // resolve the contextualization strategy - either its a custom
              // interface and handler, or its classic Avalon - try custom first
              //
  
              if( provider != null )
              {
                  if( getLogger().isDebugEnabled() )
                  {
                      final String message =
                              "activating custom context provider: " + provider
                              + " for appliance: " + appliance;
                      getLogger().debug( message );
                  }
  
                  try
                  {
                      Contextualization handler = (Contextualization) provider.resolve( this );
                      handler.contextualize( 
                        loader, appliance.getContextDirective(), object, context );
                      provider.release( handler, this );
                      return;
                  } catch( Throwable e )
                  {
                      final String error =
                              "Contextualization handler failure in appliance: " + appliance;
                      throw new ContextException( error, e );
                  }
              }
  
              if( object instanceof Contextualizable )
              {
                  //
                  // its classic Avalon contextulization
                  //
                  Contextualization contextualizer = new AvalonContextualizer();
                  if( getLogger().isDebugEnabled() )
                  {
                      final String message = appliance.toString() + " (Avalon Policy)";
                      getLogger().debug( message );
                  }
                  try
                  {
                      contextualizer.contextualize(
                        loader, appliance.getContextDirective(), object, context );
                  }
                  catch( ContextException e )
                  {
                      //
                      // this could be improved if the framework ContextException
                      // held the context key that the client is accessing
                      //
  
                      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();
                      throw new ContextException( error, e );
                  } catch( Throwable e )
                  {
                      final String error =
                              "Unexpected exception during contextualization of target: " + appliance;
                      throw new ContextException( error, e );
                  }
              }
              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 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 or Locator Contextualization interface.";
                  throw new ContextException( error );
              }
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultContextualizer.java
  
  Index: DefaultContextualizer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.assembly.lifecycle.impl;
  
  import java.util.Map;
  
  import org.apache.avalon.assembly.locator.Contextualizable;
  import org.apache.avalon.assembly.locator.Locator;
  import org.apache.avalon.assembly.locator.impl.DefaultLocator;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.meta.model.ContextDirective;
  
  /**
   * Definition of an strategy handler that handles the Contextualization
   * process. This implementation is provided as a template for alternative
   * context handlers.  The requirements for introduction of an alternative
   * handler include:
   * <ul>
   * <li>A class implementing the {@link Contextualization} handler interface.</li>
   * <li>Declaration in the classes xinfo of the extension type where the
   *       type attribute value is a version interface reference corresponding
   *       to the interface that the target component must implement.</li>
   * <li>Declaration by the target component in it's xinfo atttributes
   *       of the criteria for a custom context handler under the attribute
   *       key "urn:assembly:lifecycle.context.strategy" and value
   *       corresponding to the strategy type. </li>
   * <li>Implementation of the strategy type interface by the target
   *       component.</li>
   * </ul>
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public class DefaultContextualizer extends AbstractContextualizer
  {
      //=======================================================================
      // Extension
      //=======================================================================
  
      /**
       * Handle the contextualization stage of a component lifecycle.
       *
       * @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
       */
      public void contextualize( 
        ClassLoader loader, ContextDirective directive, Object object, Map map )
        throws ContextException
      {
          if( object instanceof Contextualizable )
          {
              Object context = createContextArgument( loader, directive, DefaultLocator.class, map );
              if( context instanceof Locator )
              {
                  ((Contextualizable) object).contextualize( (Locator) context );
              } 
              else
              {
                  final String error =
                    "Requested context implementation class " + context.getClass().getName()
                    + " does not implement the Locator interface.";
                  throw new ContextException( error );
              }
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultContextualizer.xinfo
  
  Index: DefaultContextualizer.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE type
        PUBLIC "-//AVALON/Component Type DTD Version 1.0//EN"
               "http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
  
  <!--  
  Copyright (C) The Apache Software Foundation. All rights reserved.
  This software is published under the terms of the Apache Software License
  version 1.1, a copy of which has been included with this distribution in
  the LICENSE.txt file.
  
  @author  Avalon Development Team
  @version 1.0 12/03/2001
  -->
  
  <!--
  Definition of the extension type phase support.
  -->
  
  <type>
  
    <info>
      <name>context</name>
    </info>
  
    <!--
    Declaration of the lifecycle support phases that this manager provides. 
    -->
    <extensions>
      <extension type="org.apache.avalon.assembly.locator.Contextualizable" phase="CONTEXT" />
    </extensions>
  
  </type>
  
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/WrapperComponentManager.java
  
  Index: WrapperComponentManager.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 apache@apache.org.
  
   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.assembly.lifecycle.impl;
  
  import org.apache.avalon.assembly.engine.Engine;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceSelector;
  import org.apache.avalon.meta.info.Type;
  
  /**
   * This is a {@link ComponentManager} implementation that can wrap around a
   * {@link ServiceManager} object effectively adapting a {@link ServiceManager}
   * interface to a {@link ComponentManager} interface.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/29 00:55:46 $
   */
  public class WrapperComponentManager
          implements ComponentManager
  {
      /**
       * The service manager we are adapting.
       */
      private final ServiceManager m_manager;
  
      public WrapperComponentManager( final ServiceManager manager )
      {
          if( null == manager )
          {
              throw new NullPointerException( "manager" );
          }
  
          m_manager = manager;
      }
  
      /**
       * Retrieve a component via a key.
       *
       * @param key the key
       * @return the component
       * @throws ComponentException if unable to aquire component
       */
      public Component lookup( final String key )
              throws ComponentException
      {
          try
          {
              final Object object = m_manager.lookup( key );
              if( object instanceof ServiceSelector )
              {
                  return new WrapperComponentSelector( key, (ServiceSelector) object );
              } 
              else
              {
                  if( object instanceof Component )
                  {
                      return (Component) object;
                  } 
                  else
                  {
                      //
                      // use the services defined by the type and use them to
                      // construct a proxy together with the Component interface
                      //
  
                      Class clazz = object.getClass();
                      ClassLoader loader = clazz.getClassLoader();
                      if( !(loader instanceof Engine) )
                      {
                          final String error =
                            "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().getTypeRepository().getType( clazz );
                      return new ComponentInvocationHandler( object, type ).getProxy();
                  }
              }
          } 
          catch( final ServiceException se )
          {
              throw new ComponentException( se.getKey(), se.getMessage(), se.getCause() );
          } 
          catch( final Throwable e )
          {
              final String error =
                      "Unexpected error while handling component lookup request.";
              throw new ComponentException( key, error, e );
          }
      }
  
      /**
       * Check to see if a <code>Component</code> exists for a key.
       *
       * @param key  a string identifying the key to check.
       * @return True if the component exists, False if it does not.
       */
      public boolean hasComponent( final String key )
      {
          return m_manager.hasService( key );
      }
  
      /**
       * Return the <code>Component</code> when you are finished with it.  This
       * allows the <code>ComponentManager</code> to handle the End-Of-Life Lifecycle
       * events associated with the Component.  Please note, that no Exceptions
       * should be thrown at this point.  This is to allow easy use of the
       * ComponentManager system without having to trap Exceptions on a release.
       *
       * @param component The Component we are releasing.
       */
      public void release( final Component component )
      {
          if( component instanceof WrapperComponentSelector )
          {
              m_manager.release( 
                ((WrapperComponentSelector) component).getWrappedSelector() );
          } 
          else
          {
              m_manager.release( component );
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/WrapperComponentSelector.java
  
  Index: WrapperComponentSelector.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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", "Avalon", 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 apache@apache.org.
   *
   * 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 (INCLUDING, 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.assembly.lifecycle.impl;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceSelector;
  
  /**
   * This is a {@link ServiceSelector} implementation that can wrap around a legacy
   * {@link ComponentSelector} object effectively adapting a {@link ComponentSelector}
   * interface to a {@link ServiceSelector} interface.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/04/29 00:55:46 $
   */
  public class WrapperComponentSelector
          implements ComponentSelector
  {
      /**
       * The Selector we are wrapping.
       */
      private final ServiceSelector m_selector;
  
      /**
       * The role that this selector was aquired via.
       */
      private final String m_key;
  
      /**
       * This constructor is a constructor for a WrapperComponentSelector.
       *
       * @param key the key used to aquire this selector
       * @param selector the selector to wrap
       */
      public WrapperComponentSelector( final String key,
              final ServiceSelector selector )
      {
          if( null == key )
          {
              throw new NullPointerException( "key" );
          }
          if( null == selector )
          {
              throw new NullPointerException( "selector" );
          }
  
          m_key = key + "/";
          m_selector = selector;
      }
  
      /**
       * Select a Component based on a policy.
       *
       * @param policy the policy
       * @return the Component
       * @throws ComponentException if unable to select service
       */
      public Component select( final Object policy )
              throws ComponentException
      {
          try
          {
              final Object object = m_selector.select( policy );
              if( object instanceof Component )
              {
                  return (Component) object;
              }
          } catch( final ServiceException se )
          {
              throw new ComponentException( m_key + policy, se.getMessage(), se );
          }
  
          final String message = "Role does not implement the Component " +
                  "interface and thus can not be accessed via ComponentSelector";
          throw new ComponentException( m_key + policy, message );
      }
  
      /**
       * Check to see if a {@link Component} exists relative to the supplied policy.
       *
       * @param policy a {@link Object} containing the selection criteria
       * @return True if the component is available, False if it not.
       */
      public boolean hasComponent( final Object policy )
      {
          return m_selector.isSelectable( policy );
      }
  
      /**
       * Return the {@link Object} when you are finished with it.  This
       * allows the {@link ServiceSelector} to handle the End-Of-Life Lifecycle
       * events associated with the {@link Object}.  Please note, that no
       * Exception should be thrown at this point.  This is to allow easy use of the
       * ServiceSelector system without having to trap Exceptions on a release.
       *
       * @param object The {@link Object} we are releasing.
       */
      public void release( final Component object )
      {
          m_selector.release( object );
      }
  
      /**
       * The {@link WrapperComponentManager} wraps ServiceSelectors in
       *  WrapperServiceSelectors when they are looked up.  This method
       *  makes it possible to release the original component selector.
       *
       * @return The {@link ServiceSelector} being wrapped.
       */
      ServiceSelector getWrappedSelector()
      {
          return m_selector;
      }
  }
  
  
  

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


Mime
View raw message