List of usage examples for org.apache.commons.discovery.tools DiscoverClass find
public Class find(Class spiClass, String defaultImpl) throws DiscoveryException
From source file:org.apache.beehive.controls.api.bean.Controls.java
/** * 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.//from ww w. ja va2 s .c om * @param context 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 { 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); } }
From source file:org.apache.beehive.controls.runtime.bean.ControlBean.java
/** * Internal method used to lookup a ControlBeanContextFactory. This factory is used to create the * ControlBeanContext object for this ControlBean. The factory is discoverable from either the containing * ControlBeanContext object or from the environment. If the containing CBC object exposes a * contextual service of type {@link ControlBeanContextFactory}, the factory returned from this will * be used to create a ControlBeanContext object. * * @param context//from www .j a v a2 s. c o m * @return the ControlBeanContextFactory discovered in the environment or a default one if no factory is configured */ private ControlBeanContextFactory lookupControlBeanContextFactory( org.apache.beehive.controls.api.context.ControlBeanContext context) { // first, try to find the CBCFactory from the container if (context != null) { ControlBeanContextFactory cbcFactory = context.getService(ControlBeanContextFactory.class, null); if (cbcFactory != null) { return cbcFactory; } } // Create the context that acts as the BeanContextProxy for this bean (the context that this bean _defines_). try { DiscoverClass discoverer = new DiscoverClass(); Class factoryClass = discoverer.find(ControlBeanContextFactory.class, DefaultControlBeanContextFactory.class.getName()); return (ControlBeanContextFactory) factoryClass.newInstance(); } catch (Exception e) { throw new ControlException("Exception creating ControlBeanContext", e); } }