Example usage for org.apache.commons.discovery.tools DiscoverClass DiscoverClass

List of usage examples for org.apache.commons.discovery.tools DiscoverClass DiscoverClass

Introduction

In this page you can find the example usage for org.apache.commons.discovery.tools DiscoverClass DiscoverClass.

Prototype

public DiscoverClass() 

Source Link

Document

Create a class instance with dynamic environment (thread context class loader is determined on each call).

Usage

From source file:info.magnolia.cms.util.FactoryUtil.java

public static Object getInstance(Class interf) {
    try {/*w ww . ja  v a2s  . c om*/
        return new DiscoverClass().newInstance(interf, props);
    } catch (Exception e) {
        log.error("can't instantiate an implementation of this class [" + interf.getName() + "]");
    }
    return null;
}

From source file:at.gv.egovernment.moa.spss.api.Configurator.java

public static synchronized Configurator getInstance() {
    if (instance == null) {
        try {//from  w  w w . java2  s. co  m
            DiscoverClass discover = new DiscoverClass();
            instance = (Configurator) discover.newInstance(Configurator.class, DEFAULT_IMPLEMENTATION);
        } catch (Exception e) {
            // this can not happen since we provide a valid default 
            // implementation
        }
    }
    return instance;
}

From source file:at.gv.egovernment.moa.spss.api.SignatureCreationService.java

/**
 * Get an instance of the <code>SignatureCreationService</code>.
 * /*from  ww  w. j  a  va 2  s .c  o  m*/
 * @return A concrete instance of the <code>SignatureCreationService</code>.
 */
public static synchronized SignatureCreationService getInstance() {
    if (instance == null) {
        try {
            DiscoverClass discover = new DiscoverClass();
            instance = (SignatureCreationService) discover.newInstance(SignatureCreationService.class,
                    DEFAULT_IMPLEMENTATION);
        } catch (Exception e) {
            // this can not happen since we provide a valid default 
            // implementation
        }
    }
    return instance;
}

From source file:at.gv.egovernment.moa.spss.api.SignatureVerificationService.java

/**
 * Get an instance of the <code>SignatureVerificationService</code>.
 * /*www.j a v a 2s .c o m*/
 * @return A concrete instance of the 
 * <code>SignatureVerificationService</code>.
 */
public static synchronized SignatureVerificationService getInstance() {
    if (instance == null) {
        try {
            DiscoverClass discover = new DiscoverClass();
            instance = (SignatureVerificationService) discover.newInstance(SignatureVerificationService.class,
                    DEFAULT_IMPLEMENTATION);
        } catch (Exception e) {
            // this can not happen since we provide a valid default 
            // implementation
        }
    }
    return instance;
}

From source file:at.gv.egovernment.moa.spss.api.SPSSFactory.java

/**
 * Returns the single instance of this class.
 * /*from w ww. j a v  a2  s  .  co  m*/
 * @return The single instance of this class.
 */
public static synchronized SPSSFactory getInstance() {
    if (instance == null) {
        try {
            DiscoverClass discover = new DiscoverClass();
            instance = (SPSSFactory) discover.newInstance(SPSSFactory.class, DEFAULT_IMPLEMENTATION);
        } catch (Exception e) {
            // this can not happen since we provide a valid default 
            // implementation
        }
    }
    return instance;
}

From source file:com.netspective.commons.acl.AccessControlListTest.java

public void testAuthenticatedUser() throws DataModelException, InvocationTargetException,
        InstantiationException, NoSuchMethodException, IllegalAccessException, IOException {
    AccessControlListsComponent aclc = (AccessControlListsComponent) XdmComponentFactory.get(
            AccessControlListsComponent.class, new Resource(AccessControlListTest.class, RESOURCE_NAME_THREE),
            XdmComponentFactory.XDMCOMPFLAGS_DEFAULT);

    // Verify _something_ was loaded...
    assertNotNull(aclc);/*from  w  w  w .  j a  va  2 s . c  o  m*/

    // ValueContext Created User...
    ValueContext vcOne = ValueSources.getInstance().createDefaultValueContext();
    assertNotNull(vcOne);

    Class authUserClass = new DiscoverClass().find(AuthenticatedUser.class,
            BasicAuthenticatedUser.class.getName());
    MutableAuthenticatedUser userOne = (MutableAuthenticatedUser) authUserClass.newInstance();
    assertNotNull(userOne);

    userOne.setUserId("admin");
    assertEquals("admin", userOne.getUserId());
    assertEquals("admin", userOne.getName());

    userOne.setUserName("Administrator");
    assertEquals("Administrator", userOne.getUserName());

    // Independently created User...
    ValueContext vcTwo = ValueSources.getInstance().createDefaultValueContext();
    MutableAuthenticatedUser userTwo = new BasicAuthenticatedUser();
    userTwo.setUserId("admin");
    userTwo.setUserName("Administrator");

    assertEquals("admin", userTwo.getUserId());
    assertEquals("Administrator", userTwo.getUserName());

    //TODO: Implement setAuthenticatedUser (and getAuthenticatedUser) and _then_ enable these lines
    /*
           vcTwo.setAuthenticatedUser(userTwo);
           assertEquals(userTwo, vcTwo.getAuthenticatedUser());
    */

    // Alternate constructor
    ValueContext vcThree = ValueSources.getInstance().createDefaultValueContext();
    MutableAuthenticatedUser userThree = new BasicAuthenticatedUser();
    userThree.setUserId("admin");
    userThree.setUserName("Administrator");

    assertEquals("admin", userThree.getUserId());
    assertEquals("Administrator", userThree.getUserName());

    //TODO: Implement setAuthenticatedUser (and getAuthenticatedUser) and _then_ enable these lines
    /*
           vcThree.setAuthenticatedUser(userThree);
           assertEquals(userThree, vcThree.getAuthenticatedUser());
    */
}

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 .  j  a  va2 s.  com
 * @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   w  w  w  .  ja  va  2 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);
    }
}