Author: kylem Date: Wed Jan 19 21:59:35 2005 New Revision: 125720 URL: http://svn.apache.org/viewcvs?view=rev&rev=125720 Log: Add a new SPI (org.apache.beehive.controls.spi.bean.ControlFactory) to the Controls runtime that enables control instantation to be hooked and delegated out to an external JavaBean instantiation/configuration framework, such as Hivemind or Spring.
The SPI provider impl is found using Apache Commons Discovery resouce mechanisms, the most useful probably being to simply include a jar in the application classpath that defines an implementation of the SPI interface using the JDK META-INF/services conventions. THIS DOES INTRODUCE A RUNTIME DEPENDENCY ON THE APACHE COMMONS DISCOVERY JAR. The standard import/build target has been updated so the jar will be automatically included by the webapp build ant target. All control instantations within the Beehive framework, whether done programmatically via Controls.instantiate() API or declaratively from a web service, page flow, or control implementation, are routed through this SPI, so a provider impl can participate in the instantation of all Controls within a Beehive application. A default provider is included (org.apache.beehive.controls.spi.bean.JavaControlFactory) that simply uses Java reflection (the existing mechanism pre-SPI). It will be transparently configured if no other SPI implementation is found. This is an initial step towards having integration between Beehive Controls (which offers a strong programming model and runtime services for JavaBeans) and other bean-oriented frameworks supporting instantation/configuration/wrapper services for JavaBeans. Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/ControlFactory.java incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/JavaControlFactory.java incubator/beehive/trunk/external/commons/ incubator/beehive/trunk/external/commons/commons-codec-1.3.jar (contents, props changed) incubator/beehive/trunk/external/commons/commons-discovery-0.2.jar (contents, props changed) Removed: incubator/beehive/trunk/external/commons-codec/ Modified: incubator/beehive/trunk/beehive-imports.xml incubator/beehive/trunk/controls/build.xml incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java Modified: incubator/beehive/trunk/beehive-imports.xml Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/beehive-imports.xml?view=diff&rev=125720&p1=incubator/beehive/trunk/beehive-imports.xml&r1=125719&p2=incubator/beehive/trunk/beehive-imports.xml&r2=125720 ============================================================================== --- incubator/beehive/trunk/beehive-imports.xml (original) +++ incubator/beehive/trunk/beehive-imports.xml Wed Jan 19 21:59:35 2005 @@ -40,13 +40,22 @@ <!-- ======================================================================== --> <fileset id="controls.fileset" file="${beehive.home}/controls/build/jars/controls.jar"/> + <fileset id="velocity.fileset" dir="${beehive.home}/external/velocity"> <include name="velocity-1.4.jar"/> <include name="velocity-dep-1.4.jar"/> </fileset> - <fileset id="commons-codec.fileset" file="${beehive.home}/external/commons-codec/commons-codec-1.3.jar"/> + + <fileset id="commons-codec.fileset" + file="${beehive.home}/external/commons/commons-codec-1.3.jar"/> + + <fileset id="commons-discovery.fileset" + file="${beehive.home}/external/commons/commons-discovery-0.2.jar"/> + <fileset id="log4j.fileset" file="${beehive.home}/external/log4j/log4j-1.2.8.jar"/> + <fileset id="xbean.fileset" file="${beehive.home}/external/xmlbeans/apache-xbean.jar"/> + <fileset id="jsr173.fileset" file="${beehive.home}/installed/jsr173/jsr173_1.0_api.jar"/> <path id="controls.dependency.path"> @@ -70,6 +79,10 @@ <fileset refid="commons-codec.fileset"/> </path> + <path id="commons-discovery.dependency.path"> + <fileset refid="commons-discovery.fileset"/> + </path> + <path id="log4j.dependency.path"> <fileset refid="log4j.fileset"/> </path> @@ -150,6 +163,7 @@ <copy todir="@{todir}"> <fileset refid="controls.fileset"/> <fileset refid="velocity.fileset"/> + <fileset refid="commons-discovery.fileset"/> </copy> </sequential> </macrodef> Modified: incubator/beehive/trunk/controls/build.xml Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/build.xml?view=diff&rev=125720&p1=incubator/beehive/trunk/controls/build.xml&r1=125719&p2=incubator/beehive/trunk/controls/build.xml&r2=125720 ============================================================================== --- incubator/beehive/trunk/controls/build.xml (original) +++ incubator/beehive/trunk/controls/build.xml Wed Jan 19 21:59:35 2005 @@ -26,12 +26,12 @@ <property name="api.dir" location="src/api"/> <property name="api.classes" location="${classes.dir}/api"/> <property name="spi.dir" location="src/spi"/> - <property name="spi.classes" location="${classes.dir}/spi"/> <property name="runtime.dir" location="src/runtime"/> <property name="runtime.classes" location="${classes.dir}/runtime"/> <property name="controls.jar" location="${jars.dir}/controls.jar"/> <path id="api.classpath"> + <path refid="commons-discovery.dependency.path"/> </path> <path id="spi.classpath"> @@ -44,7 +44,6 @@ <path refid="velocity.dependency.path"/> <path refid="tools.dependency.path"/> <pathelement location="${api.classes}"/> - <pathelement location="${spi.classes}"/> <path id="${api.classpath}"/> </path> <condition property="controls.os" value="windows"> @@ -90,7 +89,6 @@ <!-- ==================================================================== --> <target name="dirs"> <mkdir dir="${api.classes}"/> - <mkdir dir="${spi.classes}"/> <mkdir dir="${runtime.classes}"/> <mkdir dir="${jars.dir}"/> <mkdir dir="${docs.dir}"/> @@ -99,14 +97,14 @@ <!-- Compiles the source code of the project. --> <!-- ==================================================================== --> <target name="classes" depends="dirs"> - <!-- Build the API classes --> + <!-- Build the API and SPI classes --> + <!-- These are built together because there are some cross-depencies --> + <!-- where API classes reference SPI interfaces --> <javac destdir="${api.classes}" classpathref="api.classpath" debug="on"> <src path="${api.dir}"/> - </javac> - <!-- Build the SPI classes --> - <javac destdir="${spi.classes}" classpathref="spi.classpath" debug="on"> <src path="${spi.dir}"/> </javac> + <!-- Build the runtime classes --> <javac destdir="${runtime.classes}" classpathref="runtime.classpath" debug="on"> <src path="${runtime.dir}"/> @@ -129,7 +127,6 @@ <echo message="--------------------------------------------------"/> <jar jarfile="${controls.jar}"> <fileset dir="${api.classes}"/> - <fileset dir="${spi.classes}"/> <fileset dir="${runtime.classes}"/> </jar> <echo message="--------------------------------------------------"/> Modified: incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java?view=diff&rev=125720&p1=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java&r1=125719&p2=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java&r2=125720 ============================================================================== --- incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java (original) +++ incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/Controls.java Wed Jan 19 21:59:35 2005 @@ -18,9 +18,15 @@ */ import org.apache.beehive.controls.api.properties.PropertyMap; +import org.apache.beehive.controls.api.bean.ControlBean; import org.apache.beehive.controls.api.context.ControlBeanContext; import org.apache.beehive.controls.api.ControlException; +import org.apache.beehive.controls.spi.bean.ControlFactory; +import org.apache.beehive.controls.spi.bean.JavaControlFactory; + +import org.apache.commons.discovery.tools.DiscoverClass; + import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; @@ -30,6 +36,8 @@ */ public class Controls { + final private static String DEFAULT_FACTORY_CLASS = JavaControlFactory.class.getName(); + /** * Factory method for instantiating controls. Controls instantiated using this method will be associated with the * current thread-local ControlBeanContext (possibly none), and have an auto-generated ID. @@ -40,9 +48,9 @@ * @return an instance of the specified ControlBean. * @throws ClassNotFoundException */ - public static Object instantiate( ClassLoader cl, - String beanName, - PropertyMap props ) + public static ControlBean instantiate( ClassLoader cl, + String beanName, + PropertyMap props ) throws ClassNotFoundException { return instantiate( cl, beanName, props, null, null ); @@ -60,34 +68,44 @@ * @return an instance of the specified ControlBean. * @throws ClassNotFoundException */ - public static Object instantiate( ClassLoader cl, - String beanName, - PropertyMap props, - ControlBeanContext cbc, - String id ) + public static ControlBean instantiate( ClassLoader cl, + String beanName, + PropertyMap props, + ControlBeanContext cbc, + String id ) throws ClassNotFoundException { - Class beanClass = beanClass = ( cl == null ) ? Class.forName( beanName ) : cl.loadClass( beanName ); + Class beanClass = ( cl == null ) ? Class.forName( beanName ) : cl.loadClass( beanName ); + return instantiate(beanClass, props, cbc, id); + } - Object ret = null; + /** + * Factory method for instantiating controls. + * + * @param beanClass the ControlBean class to instantiate + * @param props an optional PropertyMap containing initial property values for the control. + * may be null. + * @param cbc the ControlBeanContext that will nest the created control. If null, the + * thread-local context (possibly none) will be used. + * @param id a unique ID for the created control. If null, an ID will be auto-generated. + * @return an instance of the specified ControlBean. + */ + public static <T extends ControlBean> T instantiate( Class<T> beanClass, + PropertyMap props, + ControlBeanContext context, + String id ) + { try { - Constructor ctor = beanClass.getConstructor( ControlBeanContext.class, String.class, PropertyMap.class ); - ret = ctor.newInstance( cbc, id, props ); - } - catch ( InvocationTargetException ite ) - { - Throwable t = ite.getCause(); - throw new ControlException( "ControlBean constructor exception: " + t.getClass().getName() + ", " + - t.getMessage() ); + DiscoverClass discoverer = new DiscoverClass(); + Class factoryClass = discoverer.find( ControlFactory.class, DEFAULT_FACTORY_CLASS ); + ControlFactory factory = (ControlFactory)factoryClass.newInstance(); + return factory.instantiate( beanClass, props, context, id ); } catch ( Exception e ) { - throw new ControlException( "Exception creating ControlBean: " + e.getClass().getName() + ", " + - e.getMessage() ); + throw new ControlException( "Exception creating ControlBean", e ); } - - return ret; } /** Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?view=diff&rev=125720&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java&r1=125719&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java&r2=125720 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java Wed Jan 19 21:59:35 2005 @@ -64,8 +64,8 @@ * Creates a new ControlBeanContext instance associated with a specific * control bean. * - * @param bean The control bean that contains/scopes the ControlBeanContext. If null, it means the - * ControlBeanContext is for a top-level container. + * @param bean The control bean that contains/scopes the ControlBeanContext. If null, + it means the ControlBeanContext is for a top-level container. */ protected ControlBeanContext(ControlBean bean) { Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java?view=diff&rev=125720&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java&r1=125719&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java&r2=125720 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java Wed Jan 19 21:59:35 2005 @@ -88,8 +88,11 @@ * Adds a new managed ResourceContext to the ControlContainerContext. This method * is used to register a resource context that has just acquired resources * @param resourceContext the ResourceContext service that has acquired resources + * @param bean the acquiring ControlBean. Unused by the base implementation, but + * available so subclassed containers can have access to the bean. */ - protected synchronized void addResourceContext(ResourceContext resourceContext) + protected synchronized void addResourceContext(ResourceContext resourceContext, + ControlBean bean) { if (!resourceContext.hasResources()) _resourceContexts.push(resourceContext); @@ -99,8 +102,11 @@ * Removes a managed ResourceContext from the ControlContainerContext. This method * is used to unregister a resource context that has already acquired resources * @param resourceContext the ResourceContext service to be removed + * @param bean the acquiring ControlBean. Unused by the base implementation, but + * available so subclassed containers can have access to the bean. */ - protected synchronized void removeResourceContext(ResourceContext resourceContext) + protected synchronized void removeResourceContext(ResourceContext resourceContext, + ControlBean bean) { // // Ignore removal requests received within the context of global cleanup. The Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java?view=diff&rev=125720&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java&r1=125719&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java&r2=125720 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ResourceContextImpl.java Wed Jan 19 21:59:35 2005 @@ -127,7 +127,7 @@ resourceListener.onAcquire(); // Register this ResourceContext with associated container context - _containerContext.addResourceContext(this); + _containerContext.addResourceContext(this, _bean); // Set the flag to indicate resources have been acquired. _hasAcquired = true; @@ -144,7 +144,7 @@ resourceListener.onRelease(); // Unregister this ResourceContext with associated container context - _containerContext.removeResourceContext(this); + _containerContext.removeResourceContext(this, _bean); // Reset the flag to indicate resources have been released. _hasAcquired = false; Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm?view=diff&rev=125720&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm&r1=125719&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm&r2=125720 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ClientInitializer.vm Wed Jan 19 21:59:35 2005 @@ -108,7 +108,7 @@ #macro (initControl $control) $control.controlBean.className $control.localName = ($control.controlBean.className)cbc.getBean("$control.name"); if ($control.localName == null) - $control.localName = (${control.controlBean.className}) Controls.instantiate( null, "${control.controlBean.className}", getAnnotationMap(cbc, ${control.reflectField}), cbc, "$control.name" ); + $control.localName = (${control.controlBean.className}) Controls.instantiate(${control.controlBean.className}.class, getAnnotationMap(cbc, ${control.reflectField}), cbc, "$control.name" ); #initEventAdaptors($control) #if ($init.needsReflection($control)) ${control.reflectField}.set(client, $control.localName); Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/ControlFactory.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/ControlFactory.java?view=auto&rev=125720 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/ControlFactory.java Wed Jan 19 21:59:35 2005 @@ -0,0 +1,50 @@ +package org.apache.beehive.controls.spi.bean; +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Header:$ + */ + +import org.apache.beehive.controls.api.bean.ControlBean; +import org.apache.beehive.controls.api.context.ControlBeanContext; +import org.apache.beehive.controls.api.properties.PropertyMap; + +import java.lang.reflect.Method; + +/** + * The ControlFactory interface defines a service provider interface for integrating + * an external JavaBean instantation/configuration framework with the Controls runtime. + */ +public interface ControlFactory +{ + /** + * Instantiates a new ControlBean of the requested class, using mechanisms provided + * by a provider-specific JavaBeans framework. + * + * @param beanClass the ControlBean class to instantiate + * @param props an initial set of client-specified properties to associate with the + * bean instance. May be null. + * @param context the containing ControlBeanContext for the bean, if nested inside of + * a container or other control. May be null to use the current active + * execution context. + * @param id the bean control ID. Must be unique within the containing context. If + * null, a unique identifier will be auto-generated. + * @returns a new ControlBean instance of the requested class. + */ + public <T extends ControlBean> T instantiate(Class<T> beanClass, + PropertyMap props, + ControlBeanContext context, + String id); +} Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/JavaControlFactory.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/JavaControlFactory.java?view=auto&rev=125720 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/bean/JavaControlFactory.java Wed Jan 19 21:59:35 2005 @@ -0,0 +1,88 @@ +package org.apache.beehive.controls.spi.bean; +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Header:$ + */ + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.beehive.controls.api.properties.PropertyMap; +import org.apache.beehive.controls.api.bean.ControlBean; +import org.apache.beehive.controls.api.context.ControlBeanContext; +import org.apache.beehive.controls.api.ControlException; + +import org.apache.beehive.controls.spi.bean.ControlFactory; + +/** + * The SimpleControlFactory class is a default implementation of the + * <code>org.apache.beehive.controls.api.bean.ControlFactory</code> interface. It + * uses Java reflection to create new control instances. + * + * @see org.apache.beehive.controls.api.Controls#instantiate + * @see org.apache.beehive.controls.spi.ControlFactory + */ +public class JavaControlFactory implements ControlFactory +{ + private static ConcurrentHashMap<Class, Constructor> _constructors = + new ConcurrentHashMap<Class, Constructor>(); + + /** + * Instantiates a new ControlBean of the requested class, using mechanisms provided + * by a provider-specific JavaBeans framework. + * + * @param beanClass the ControlBean class to instantiate + * @param props an initial set of client-specified properties to associate with the + * bean instance. May be null. + * @param context the containing ControlBeanContext for the bean, if nested inside of + * a container or other control. May be null to use the current active + * execution context. + * @param id the bean control ID. Must be unique within the containing context. If + * null, a unique identifier will be auto-generated. + * @returns a new ControlBean instance of the requested class. + */ + public <T extends ControlBean> T instantiate(Class<T> beanClass, + PropertyMap props, + ControlBeanContext context, + String id) + { + T ret = null; + try + { + Constructor<T> ctor = _constructors.get(beanClass); + if (ctor == null) + { + ctor = beanClass.getConstructor(ControlBeanContext.class, String.class, + PropertyMap.class); + _constructors.put(beanClass, ctor); + } + ret = ctor.newInstance(context, id, props); + } + catch (InvocationTargetException ite) + { + Throwable t = ite.getCause(); + throw new ControlException("ControlBean constructor exception", t); + } + catch (Exception e) + { + throw new ControlException("Exception creating ControlBean", e); + } + + return ret; + } +} Added: incubator/beehive/trunk/external/commons/commons-codec-1.3.jar Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/external/commons/commons-codec-1.3.jar?view=auto&rev=125720 ============================================================================== Binary file. No diff available. Added: incubator/beehive/trunk/external/commons/commons-discovery-0.2.jar Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/external/commons/commons-discovery-0.2.jar?view=auto&rev=125720 ============================================================================== Binary file. No diff available. Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java?view=diff&rev=125720&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java&r1=125719&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java&r2=125720 ============================================================================== --- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java (original) +++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/JavaControlUtils.java Wed Jan 19 21:59:35 2005 @@ -18,6 +18,8 @@ package org.apache.beehive.netui.pageflow.internal; import org.apache.beehive.controls.runtime.servlet.ServletBeanContext; +import org.apache.beehive.controls.api.ControlException; +import org.apache.beehive.controls.api.bean.Controls; import org.apache.beehive.controls.api.bean.ControlBean; import org.apache.beehive.controls.api.bean.Control; import org.apache.beehive.controls.api.context.ControlBeanContext; @@ -47,18 +49,11 @@ { private static final Logger _log = Logger.getInstance( JavaControlUtils.class ); private static final String CONTROL_CONTEXT_CLASSNAME = ServletBeanContext.class.getName(); - private static final Class[] CONTROL_BEAN_CONSTRUCTOR_SIGNATURE = - new Class[]{ ControlBeanContext.class, String.class, PropertyMap.class }; /** Map of control-container-class (e.g., PageFlowController) to Map of fields/control-properties. */ private static ConcurrentHashMap< String, Map< Field, PropertyMap > > _controlFieldCache = new ConcurrentHashMap< String, Map< Field, PropertyMap > >(); - /** Cache of control-class-name to Constructor */ - private static ConcurrentHashMap< String, Constructor > _controlConstructors = - new ConcurrentHashMap< String, Constructor >(); - - public static void initializeControlContext( HttpServletRequest request, HttpServletResponse response, ServletContext servletContext ) { @@ -156,33 +151,13 @@ try { - Constructor constructor = _controlConstructors.get( controlClassName ); - - if ( constructor == null ) - { - Class beanClass = Class.forName( controlClassName ); - constructor = beanClass.getConstructor( CONTROL_BEAN_CONSTRUCTOR_SIGNATURE ); - _controlConstructors.put( controlClassName, constructor ); - } - - Object instance = constructor.newInstance( new Object[]{ beanContext, controlID, properties } ); + Object instance = Controls.instantiate( null, controlClassName, properties, beanContext, controlID ); assert instance instanceof ControlBean : instance.getClass().getName(); return ( ControlBean ) instance; } - catch ( ClassNotFoundException e ) - { - _log.error( "Could not find control bean class " + controlClassName ); - throw new ControlInstantiationException( controlClassName, e ); - } - catch ( NoSuchMethodException e ) - { - _log.error( "Missing constructor (ControlBeanContext, String controlID) on control bean class.", e ); - throw new ControlInstantiationException( controlClassName, e ); - } catch ( Exception e ) { - assert e instanceof InstantiationException || e instanceof IllegalAccessException - || e instanceof InvocationTargetException : e.getClass().getName(); + assert e instanceof ControlException : e.getClass().getName(); _log.error( "Error while constructing control bean of type " + controlClassName, e ); throw new ControlInstantiationException( controlClassName, e ); }
