avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl DefaultComponentModel.java
Date Thu, 11 Mar 2004 12:28:07 GMT
mcconnell    2004/03/11 04:28:07

  Modified:    merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
                        DefaultComponentModel.java
  Log:
  Update the isContextDependent test to include assessment of context via constructor injection.
  
  Revision  Changes    Path
  1.14      +39 -2     avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java
  
  Index: DefaultComponentModel.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultComponentModel.java	11 Mar 2004 01:30:38 -0000	1.13
  +++ DefaultComponentModel.java	11 Mar 2004 12:28:07 -0000	1.14
  @@ -21,6 +21,7 @@
   import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.Properties;
  +import java.lang.reflect.Constructor;
   import java.security.AccessControlContext;
   
   import org.apache.avalon.composition.data.DeploymentProfile;
  @@ -884,7 +885,6 @@
               Class contextualizable = 
                 getComponentClass( classLoader, strategy );
   
  -
               if( contextualizable == null )
               {
                   final String error = 
  @@ -911,6 +911,23 @@
           }
           else
           {
  +            //
  +            // its either classic avalon 4.1 or its 4.2 constructor 
  +            // based - first off check the constructor for a type 
  +            // corresponding to the base class
  +            //
  +            
  +            String contextClassname = 
  +              m_context.getType().getContext().getContextInterfaceClassname();
  +            Class contextClass = 
  +              getComponentClass( classLoader, contextClassname );
  +            boolean isConstructorBased = isaConstructorArg( contextClass );
  +            if( isConstructorBased ) return true;
  +            
  +            //
  +            // otherwise check for classic avalon Contextualizable
  +            //
  +
               Class contextualizable = 
                 getComponentClass( classLoader, CONTEXTUALIZABLE );
               if( contextualizable != null )
  @@ -920,6 +937,26 @@
                       return true;
                   }
               }
  +        }
  +        return false;
  +    }
  +
  +   /**
  +    * Test to determin if the first constructor supports the context
  +    * base class as a parameter type.
  +    * @return TRUE or FALSE
  +    */
  +    private boolean isaConstructorArg( Class base )
  +    {
  +        if( null == base ) return false;
  +        Class clazz = getDeploymentClass();
  +        Constructor[] constructors = clazz.getConstructors();
  +        if( constructors.length == 0 ) return false;
  +        Constructor constructor = constructors[0];
  +        Class[] types = constructor.getParameterTypes();
  +        for( int i=0; i<types.length; i++ )
  +        {
  +            if( base.isAssignableFrom( types[i] ) ) return true;
           }
           return false;
       }
  
  
  

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


Mime
View raw message