leosimons 2003/02/08 06:49:16 Modified: component/src/java/org/apache/avalon/excalibur/component ComponentHandler.java DefaultComponentFactory.java Log: Adding back in the methods removed in version 1.6 when proxying was implemented, which broke backwards compatibility. This restores compatibility for ComponentHandler and should allow cocoon to build against ECM cvs again. We should carefully check all changes made with the comment "update component to use proxies" as things might have broken in more areas, for example - protected PoolableComponentHandler( final Class componentClass, + protected PoolableComponentHandler( final String role, + final Class componentClass, final Configuration config, final ComponentManager manager, final Context context, could lead to problems in packages that extend ECM or some of its classes. Revision Changes Path 1.10 +134 -3 avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentHandler.java Index: ComponentHandler.java =================================================================== RCS file: /home/cvs/avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/ComponentHandler.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ComponentHandler.java 7 Nov 2002 06:37:53 -0000 1.9 +++ ComponentHandler.java 8 Feb 2003 14:49:16 -0000 1.10 @@ -7,6 +7,9 @@ */ package org.apache.avalon.excalibur.component; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + import org.apache.avalon.excalibur.pool.Poolable; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; @@ -51,8 +54,135 @@ *-------------------------------------------------------------*/ /** * Looks up and returns a component handler for a given component class. + * The componentClass must either implement Component or have a public + * static field named ROLE containing the Fully Qualified Classname as a + * String of the interface or class defining the component's role. + * + * @param componentClass Class of the component for which the handle is + * being requested. + * @param configuration The configuration for this component. + * @param componentManager The ComponentLocator which will be managing + * the Component. + * @param context The current context object. + * @param roleManager The current RoleManager. + * @param loggerManager The current LogKitLoggerManager. + * + * @throws Exception If there were any problems obtaining a ComponentHandler + * + * @deprecated This method has been deprecated in favor of the version below which + * handles instrumentation. + */ + public static ComponentHandler getComponentHandler( final Class componentClass, + final Configuration configuration, + final ComponentManager componentManager, + final Context context, + final RoleManager roleManager, + final LogkitLoggerManager loggerManager ) + throws Exception + { + return ComponentHandler.getComponentHandler( componentClass, + configuration, + componentManager, + context, + roleManager, + loggerManager, + null, + "N/A" ); + } + + /** + * Looks up and returns a component handler for a given component class. + * The componentClass must either implement Component or have a public + * static field named ROLE containing the Fully Qualified Classname as a + * String of the interface or class defining the component's role. + * + * @param componentClass Class of the component for which the handle is + * being requested. + * @param configuration The configuration for this component. + * @param componentManager The ComponentLocator which will be managing + * the Component. + * @param context The current context object. + * @param roleManager The current RoleManager. + * @param loggerManager The current LogKitLoggerManager. + * @param instrumentManager The current InstrumentManager (May be null). + * @param instrumentableName The instrumentable name to assign to + * components created by the handler. + * + * @throws Exception If there were any problems obtaining a ComponentHandler + */ + public static ComponentHandler getComponentHandler( final Class componentClass, + final Configuration configuration, + final ComponentManager componentManager, + final Context context, + final RoleManager roleManager, + final LogkitLoggerManager loggerManager, + final InstrumentManager instrumentManager, + final String instrumentableName ) + throws Exception + { + // If componentClass extends Component, everything + // is fly, as no proxy needs to be generated, and we can pass + // in null for the role. If not, we check for a public ROLE + // member and use that. If that fails, we complain loudly... + String role = null; + final boolean isComponent = Component.class.isAssignableFrom( componentClass ); + + if( role == null && !isComponent ) + { + try + { + final Field field = componentClass.getField( "ROLE" ); + final boolean isStatic = Modifier.isStatic(field.getModifiers()); + if( !isStatic ) + throw new IllegalArgumentException( "the componentClass you provided" + + "does not implement Component, and you also did not" + + "specify a role." ); + + final Object fieldContents = field.get(null); + if( fieldContents instanceof String ) + role = (String)field.get(null); // found the role + } + catch( NoSuchFieldException nsfe ) + { + throw new IllegalArgumentException( "the componentClass you provided" + + "does not implement Component, and you also did not" + + "specify a role." ); + } + catch( SecurityException se ) + { + throw new IllegalArgumentException( "the componentClass you provided" + + "does not implement Component, and you also did not" + + "specify a role." ); + } + catch( IllegalArgumentException iae ) + { + // won't happen + throw iae; + } + catch( IllegalAccessException iae ) + { + // won't happen + throw new IllegalArgumentException( "the componentClass you provided" + + "does not implement Component, and you also did not" + + "specify a role." ); + } + } + return ComponentHandler.getComponentHandler( role, + componentClass, + configuration, + componentManager, + context, + roleManager, + loggerManager, + instrumentManager, + instrumentableName ); + } + + /** + * Looks up and returns a component handler for a given component class. * - * @param role The role name of the component. + * @param role The role name of the component. This must be + * a fully-qualified classname. * @param componentClass Class of the component for which the handle is * being requested. * @param configuration The configuration for this component. @@ -90,7 +220,8 @@ /** * Looks up and returns a component handler for a given component class. * - * @param role The role name of the component. + * @param role The role name of the component. This must be + * a fully-qualified classname * @param componentClass Class of the component for which the handle is * being requested. * @param configuration The configuration for this component. 1.18 +4 -1 avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/DefaultComponentFactory.java Index: DefaultComponentFactory.java =================================================================== RCS file: /home/cvs/avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/DefaultComponentFactory.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- DefaultComponentFactory.java 5 Feb 2003 02:28:35 -0000 1.17 +++ DefaultComponentFactory.java 8 Feb 2003 14:49:16 -0000 1.18 @@ -295,6 +295,9 @@ // This makes it possible to use components which are not real Components // with the ECM. We need to remember to unwrap this when the component is // decommissioned. + // + // note that ComponentHandler depends on this specific + // component instanceof Component check to be made Component returnableComponent; if( !( component instanceof Component ) ) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]