avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craft...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules Fortress.java ECM.java AbstractModule.java
Date Fri, 04 Oct 2002 14:46:36 GMT
crafterm    2002/10/04 07:46:35

  Modified:    xfc/src/java/org/apache/excalibur/xfc/modules Fortress.java
                        ECM.java AbstractModule.java
  Log:
  General updates to use new Model class.
  Added support for ComponentSelector style role definitions.
  General javadoc cleanups.
  
  Revision  Changes    Path
  1.2       +57 -34    jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/Fortress.java
  
  Index: Fortress.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/Fortress.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Fortress.java	2 Oct 2002 17:32:28 -0000	1.1
  +++ Fortress.java	4 Oct 2002 14:46:35 -0000	1.2
  @@ -105,31 +105,45 @@
       // </role-list>
   
       /**
  -     * Method for extracting a role's default implementing class, 
  -     * Fortress style.
  +     * Method to construct a {@link RoleRef} object from
  +     * a Role definition.
        *
  -     * @param role role <code>Configuration</code> information
  -     * @return the role's default implementing class name
  +     * @param role role information
  +     * @return a {@link RoleRef} instance
        * @exception Exception if an error occurs
        */
  -    protected String getDefaultClass( final Configuration role )
  +    protected RoleRef buildRoleRef( final Configuration role )
           throws Exception
       {
  -        return role.getChild( "component" ).getAttribute( "class" );
  +        Configuration[] hints = role.getChildren( "component" );
  +        Definition[] definitions = new Definition[ hints.length ];
  +
  +        for ( int i = 0; i < hints.length; ++i )
  +        {
  +            definitions[i] =
  +                new Definition(
  +                    getRole( role ),
  +                    getHintClass( hints[i] ),
  +                    getShorthand( hints[i] ),
  +                    getHandler( getHintClass( hints[i] ) )
  +                );
  +        }
  +
  +        return new RoleRef( getRole( role ), definitions );
       }
   
       /**
  -     * Method for extracting a role's shorthand name, Fortress
  -     * style.
  +     * Method for extracting a role's default implementing class, 
  +     * Fortress style.
        *
        * @param role role <code>Configuration</code> information
  -     * @return the role's shorthand name
  +     * @return the role's default implementing class name
        * @exception Exception if an error occurs
        */
  -    protected String getShorthand( final Configuration role )
  +    protected String getDefaultClass( final Configuration role )
           throws Exception
       {
  -        return super.getShorthand( role.getChild( "component" ) );
  +        return role.getAttribute( "class" );
       }
   
       /**
  @@ -142,9 +156,7 @@
       protected String getHandler( final Configuration role )
           throws Exception
       {
  -        return getLifestyleType(
  -            role.getChild( "component" ).getAttribute( "handler" ), TRANSIENT
  -        );
  +        return getLifestyleType( role.getAttribute( "handler" ), TRANSIENT );
       }
   
       /**
  @@ -178,35 +190,46 @@
       }
   
       /**
  -     * Method for building a Fortress style Role definition
  -     * based on a {@link RoleRef} object.
  +     * Builds a single component Role definition from a {@link RoleRef}
  +     * definition.
        *
  -     * @param roleref a <code>RoleRef</code> instance
  -     * @return role definition as a <code>Configuration</code> value
  +     * @param ref a {@link RoleRef} instance
  +     * @return a <code>Configuration</code> instance
        * @exception Exception if an error occurs
        */
  -    protected Configuration buildRole( final RoleRef roleref )
  +    protected Configuration buildSingleComponentRole( final RoleRef ref )
  +        throws Exception
  +    {
  +        return buildMultipleComponentRole( ref );
  +    }
  +
  +    /**
  +     * Builds a multiple component Role definition (ie ComponentSelector based)
  +     * from a {@link RoleRef} definition.
  +     *
  +     * @param ref a {@link RoleRef} instance
  +     * @return a <code>Configuration</code> instance
  +     * @exception Exception if an error occurs
  +     */
  +    protected Configuration buildMultipleComponentRole( final RoleRef ref )
           throws Exception
       {
           DefaultConfiguration role = new DefaultConfiguration( "role", "" );
  -        Definition[] defs = roleref.getProviders();
  +        Definition[] defs = ref.getProviders();
   
  -        if ( defs.length > 1 )
  -        {
  -            // REVISIT(MC): generate component selector
  -        }
  -        else
  +        for ( int i = 0; i < defs.length; ++i )
           {
  -            role.setAttribute( "name", roleref.getRole() );
  -
  -            DefaultConfiguration component = new DefaultConfiguration( "component", "");
  -            component.setAttribute( "shorthand", defs[0].getShorthand() );
  -            component.setAttribute( "class", defs[0].getDefaultClass() );
  -            component.setAttribute(
  -                "handler", getLifestyleType( defs[0].getHandler(), FACTORY )
  +            DefaultConfiguration hint = new DefaultConfiguration( "component", "" );
  +            hint.setAttribute( "shorthand", defs[i].getShorthand() );
  +            hint.setAttribute( "class", defs[i].getDefaultClass() );
  +            hint.setAttribute(
  +                "handler", getLifestyleType( defs[i].getHandler(), TRANSIENT )
               );
  -            role.addChild( component );
  +
  +            role.addChild( hint );
           }
  +
  +        role.setAttribute( "name", ref.getRole() );
   
           return role;
       }
  
  
  
  1.2       +143 -32   jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ECM.java
  
  Index: ECM.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ECM.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ECM.java	2 Oct 2002 17:32:28 -0000	1.1
  +++ ECM.java	4 Oct 2002 14:46:35 -0000	1.2
  @@ -94,6 +94,10 @@
       private static final String RECYCLABLE =
           "org.apache.avalon.excalibur.mpool.Recyclable";
   
  +    // ExcaliburComponentSelector name
  +    private static final String ECS =
  +        "org.apache.avalon.excalibur.component.ExcaliburComponentSelector";
  +
       private static Map m_handlers = new HashMap();
   
       /**
  @@ -107,7 +111,7 @@
        * </p>
        *
        * @param context a <code>String</code> context value
  -     * @return a <code>Model</code> instance
  +     * @return a {@link Model} instance
        * @exception Exception if an error occurs
        */
       public Model generate( final String context )
  @@ -124,7 +128,7 @@
           // for each role create a type object
           for ( int i = 0; i < roles.length; ++i )
           {
  -            model.addDefinition( buildDefinition( roles[i] ) );
  +            model.addRoleRef( buildRoleRef( roles[i] ) );
           }
   
           if ( getLogger().isDebugEnabled() )
  @@ -175,22 +179,73 @@
       }
   
       /**
  -     * Method to construct a {@link Definition} object from
  +     * Method to construct a {@link RoleRef} object from
        * a Role definition.
        *
        * @param role role information
  -     * @return a <code>Definition</code> instance
  +     * @return a {@link RoleRef} instance
  +     * @exception Exception if an error occurs
  +     */
  +    protected RoleRef buildRoleRef( final Configuration role )
  +        throws Exception
  +    {
  +        if ( role.getChildren( "hint" ).length > 0 )   // component selector definition
  +        {
  +            return buildMultipleComponentRoleRef( role );
  +        }
  +
  +        // single component definition
  +        return buildSingleComponentRoleRef( role );
  +    }
  +
  +    /**
  +     * Method for constructing a {@link RoleRef} object from a single
  +     * component role definition.
  +     *
  +     * @param role a <code>Configuration</code> value
  +     * @return a {@link RoleRef} value
  +     * @exception Exception if an error occurs
  +     */
  +    protected RoleRef buildSingleComponentRoleRef( final Configuration role )
  +        throws Exception
  +    {
  +        Definition def =
  +            new Definition(
  +                getRole( role ),
  +                getDefaultClass( role ),
  +                getShorthand( role ),
  +                getHandler( getDefaultClass( role ) )
  +            );
  +
  +        return new RoleRef( getRole( role ), def );
  +    }
  +
  +    /**
  +     * Method for constructing a {@link RoleRef} object from a multiple
  +     * component role definition (ie. component selector).
  +     *
  +     * @param role a <code>Configuration</code> value
  +     * @return a {@link RoleRef} value
        * @exception Exception if an error occurs
        */
  -    protected Definition buildDefinition( final Configuration role )
  +    protected RoleRef buildMultipleComponentRoleRef( final Configuration role )
           throws Exception
       {
  -        return new Definition(
  -            getRole( role ),
  -            getDefaultClass( role ),
  -            getShorthand( role ),
  -            getHandler( role )
  -        );
  +        Configuration[] hints = role.getChildren( "hint" );
  +        Definition[] definitions = new Definition[ hints.length ];
  +
  +        for ( int i = 0; i < hints.length; ++i )
  +        {
  +            definitions[i] =
  +                new Definition(
  +                    getRole( role ),
  +                    getHintClass( hints[i] ),
  +                    getShorthand( hints[i] ),
  +                    getHandler( getHintClass( hints[i] ) )
  +                );
  +        }
  +
  +        return new RoleRef( getRole( role ), definitions );
       }
   
       /**
  @@ -208,7 +263,7 @@
   
       /**
        * Method to extract a role's implementing class, ECM
  -     * style
  +     * style.
        *
        * @param role role <code>Configuration</code> information
        * @return the implementing class name
  @@ -221,8 +276,22 @@
       }
   
       /**
  +     * Method to extract a hint's implementing class, ECM
  +     * style.
  +     *
  +     * @param role role <code>Configuration</code> information
  +     * @return the implementing class name
  +     * @exception Exception if an error occurs
  +     */
  +    protected String getHintClass( final Configuration role )
  +        throws Exception
  +    {
  +        return role.getAttribute( "class" );
  +    }
  +
  +    /**
        * Method for extracting a role's shorthand name, ECM
  -     * style
  +     * style.
        *
        * @param role role <code>Configuration</code> information
        * @return the shorthand name
  @@ -241,16 +310,16 @@
        * try to ascertain which handler has been chosed by the 
        * implementor.
        *
  -     * @param role role <code>Configuration</code> information
  +     * @param classname class name as a <code>String</code> value
        * @return normalized handler name
        * @exception Exception if an error occurs
        */
  -    protected String getHandler( final Configuration role )
  +    protected String getHandler( final String classname )
           throws Exception
       {
           try
           {
  -            Class clazz = Class.forName( getDefaultClass( role ) );
  +            Class clazz = Class.forName( classname );
               Class[] interfaces = clazz.getInterfaces();
   
               for ( int i = 0; i < interfaces.length; ++i )
  @@ -276,7 +345,7 @@
               if ( getLogger().isWarnEnabled() )
               {
                   getLogger().warn(
  -                    "Could not load Class " + role.getAttribute( "default-class" ) +
  +                    "Could not load Class " + classname +
                       " for Component Handler analysis, defaulting to 'transient'"
                   );
               }
  @@ -296,7 +365,7 @@
        * Serializes a {@link Model} definition, ECM style, to an
        * output context.
        *
  -     * @param model a <code>Model</code> instance
  +     * @param model a {@link Model} instance
        * @param context ECM output Context
        * @exception Exception if an error occurs
        */
  @@ -304,7 +373,7 @@
           throws Exception
       {
           RoleRef[] rolerefs = model.getDefinitions();
  -        DefaultConfiguration roles = new DefaultConfiguration("role-list", "");
  +        DefaultConfiguration roles = new DefaultConfiguration( "role-list", "" );
   
           // for each type object generate a roles file entry
           for ( int i = 0; i < rolerefs.length; ++i )
  @@ -319,37 +388,79 @@
        * Method to build a Role definition from a {@link RoleRef}
        * object.
        *
  -     * @param roleref a <code>RoleRef</code> instance
  +     * @param roleref a {@link RoleRef} instance
        * @return role definition as a <code>Configuration</code> instance
        * @exception Exception if an error occurs
        */
       protected Configuration buildRole( final RoleRef roleref )
           throws Exception
       {
  -        DefaultConfiguration role = new DefaultConfiguration("role", "");
  -
           Definition[] defs = roleref.getProviders();
   
  -        if ( defs.length > 1 )
  +        if ( getLogger().isDebugEnabled() )
           {
  -            // REVISIT: generate component selector
  +            getLogger().debug( "Building role for model: " + roleref.getRole() );
           }
  -        else
  +
  +        if ( roleref.getProviders().length > 1 )
           {
  -            role.setAttribute( "name", roleref.getRole() );
  -            role.setAttribute( "shorthand", defs[0].getShorthand() );
  -            role.setAttribute( "default-class", defs[0].getDefaultClass() );
  +            return buildMultipleComponentRole( roleref );
           }
   
  -        if ( getLogger().isDebugEnabled() )
  +        return buildSingleComponentRole( roleref );
  +    }
  +
  +    /**
  +     * Builds a multiple component Role definition (ie ComponentSelector based)
  +     * from a {@link RoleRef} definition.
  +     *
  +     * @param ref a {@link RoleRef} instance
  +     * @return a <code>Configuration</code> instance
  +     * @exception Exception if an error occurs
  +     */
  +    protected Configuration buildMultipleComponentRole( final RoleRef ref )
  +        throws Exception
  +    {
  +        DefaultConfiguration role = new DefaultConfiguration( "role", "" );
  +        Definition[] defs = ref.getProviders();
  +
  +        for ( int i = 0; i < defs.length; ++i )
           {
  -            getLogger().debug( "Building role for model: " + roleref.getRole() );
  +            DefaultConfiguration hint = new DefaultConfiguration( "hint", "" );
  +            hint.setAttribute( "shorthand", defs[i].getShorthand() );
  +            hint.setAttribute( "class", defs[i].getDefaultClass() );
           }
   
  +        role.setAttribute( "name", ref.getRole() );
  +        role.setAttribute( "shorthand", "REVISIT" ); // REVISIT(MC) ?
  +        role.setAttribute( "default-class", ECS );
  +
  +        return role;
  +    }
  +
  +    /**
  +     * Builds a single component Role definition from a {@link RoleRef}
  +     * definition.
  +     *
  +     * @param ref a {@link RoleRef} instance
  +     * @return a <code>Configuration</code> instance
  +     * @exception Exception if an error occurs
  +     */
  +    protected Configuration buildSingleComponentRole( final RoleRef ref )
  +        throws Exception
  +    {
  +        DefaultConfiguration role = new DefaultConfiguration( "role", "" );
  +        Definition[] defs = ref.getProviders();
  +
  +        // there is only 1 provider, use index 0 directly
  +        role.setAttribute( "name", ref.getRole() );
  +        role.setAttribute( "shorthand", defs[0].getShorthand() );
  +        role.setAttribute( "default-class", defs[0].getDefaultClass() );
  +
           return role;
       }
   
  -    // Default mappings for ECM and Type lifestyles
  +    // Normalized mappings for ECM lifestyles
       static
       {
           // ECM -> Type
  
  
  
  1.2       +4 -4      jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/AbstractModule.java
  
  Index: AbstractModule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/AbstractModule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractModule.java	2 Oct 2002 17:32:28 -0000	1.1
  +++ AbstractModule.java	4 Oct 2002 14:46:35 -0000	1.2
  @@ -84,7 +84,7 @@
       protected final DefaultConfigurationBuilder m_builder;
   
       /**
  -     * Creates a new <code>AbstractModule</code> instance.
  +     * Creates a new {@link AbstractModule} instance.
        */
       public AbstractModule()
       {
  @@ -100,7 +100,7 @@
        * input context
        *
        * @param context a <code>String</code> value
  -     * @return a <code>Model</code> value
  +     * @return a {@link Model} value
        * @exception Exception if an error occurs
        */
       public abstract Model generate( final String context )
  @@ -110,7 +110,7 @@
        * Abstract method for serializing a given {@link Model} to
        * an output context.
        *
  -     * @param model a <code>Model</code> value
  +     * @param model a {@link Model} value
        * @param context a <code>String</code> value
        * @exception Exception if an error occurs
        */
  
  
  

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


Mime
View raw message