Example usage for org.apache.commons.lang ClassUtils toClass

List of usage examples for org.apache.commons.lang ClassUtils toClass

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils toClass.

Prototype

public static Class<?>[] toClass(Object[] array) 

Source Link

Document

Converts an array of Object in to an array of Class objects.

This method returns null for a null input array.

Usage

From source file:gda.factory.corba.util.ImplFactory.java

protected void makeObjectsAvailable() throws FactoryException {
    POA poa = netService.getPOA();

    //TODO All errors should lead to throwing a FactoryException - check error then lead to system exit
    org.omg.PortableServer.Servant servant;

    Runtime.getRuntime().addShutdownHook(uk.ac.gda.util.ThreadManager.getThread(new Runnable() {
        @Override// w  w w  .ja  v a2  s .  co m
        public void run() {
            shutdown();
        }
    }, getNamespace() + " ImplFactory shutdown"));

    List<Findable> findables = getFindablesToMakeAvailable();
    for (Findable findable : findables) {
        String name = findable.getName();
        if (findable instanceof Localizable && !((Localizable) findable).isLocal()) {

            if (excludedObjects != null && excludedObjects.contains(name)) {
                logger.info(String.format("Not exporting %s - it has been excluded", name));
                continue;
            }

            Class<?> type = findable.getClass();
            if (RbacUtils.objectIsCglibProxy(findable)) {
                // Object has been proxied. Get its original type
                type = type.getSuperclass();
            }

            String implName = CorbaUtils.getImplementationClassName(type);
            String adapterClassName = CorbaUtils.getAdapterClassName(type);

            org.omg.CORBA.Object obj = null;
            try {
                Class<?> classDef = Class.forName(implName);
                Constructor<?>[] ctors = classDef.getDeclaredConstructors();
                Constructor<?> ctor = ctors[0];

                final Object[] args = new Object[] { findable, poa };
                if (!ClassUtils.isAssignable(ClassUtils.toClass(args), ctor.getParameterTypes())) {
                    logger.warn("Class " + implName + " is unsuitable for " + name
                            + ", so it will be a local object");
                }

                else {
                    servant = (org.omg.PortableServer.Servant) ctor.newInstance(args);
                    obj = poa.servant_to_reference(servant);
                }
            } catch (ClassNotFoundException ex) {
                logger.warn("Cannot find class " + implName + ": " + name + " will be a local object");
            } catch (Exception e) {
                logger.error(
                        "Could not instantiate class " + implName + ": " + name + " will be a local object", e);
            }

            String fullName = getNamespace() + NetService.OBJECT_DELIMITER + name;
            if (obj != null) {
                // bind throws a factory exception which is not caught
                // but passed back to the caller.
                store.put(fullName, new CorbaBoundObject(fullName, adapterClassName, obj));
                netService.bind(fullName, adapterClassName, obj);
                logger.debug("ImplFactory created Corba object for " + fullName);
            } else {
                logger.warn("No CORBA object created for " + fullName);
            }
        }

        else {
            logger.debug(
                    String.format("Not exporting %s - it is local (or does not implement Localizable)", name));
        }
    }
}

From source file:org.nebularis.defproxy.configuration.ProxyConfigurationBuilder.java

private boolean areParameterTypesCompatible(final MethodSignature interfaceMethod,
        final MethodSignature delegateMethod) {
    if (targetSiteWrappers.containsKey(delegateMethod)) {
        final AdditionalArguments slot = targetSiteWrappers.get(delegateMethod);
        if (slot.insertion.equals(Insertion.Prefix)) {
            if (slot.params.length < delegateMethod.getParameterTypes().length) {
                final Class[] inputTypes = new Class[slot.params.length];
                final List<Class> inputClassList = asList(delegateMethod.getParameterTypes());
                inputClassList.subList(0, inputTypes.length).toArray(inputTypes);
                return isAssignable(inputTypes, ClassUtils.toClass(slot.params));
            }/*w  w w . j  a  va2 s .co  m*/
            return isAssignable(delegateMethod.getParameterTypes(), ClassUtils.toClass(slot.params));
        } else {
            assert (slot.insertion.equals(Insertion.Suffix));
            final Class[] inputTypes = new Class[delegateMethod.getParameterTypes().length];
            final List<Class> inputClassList = asList(delegateMethod.getParameterTypes());
            inputClassList.toArray(inputTypes);
            CollectionUtils.reverseArray(inputTypes);

            final Class[] slotTypes = new Class[slot.params.length];
            final List<Class> slotClassList = asList(ClassUtils.toClass(slot.params));
            slotClassList.toArray(slotTypes);
            CollectionUtils.reverseArray(slotTypes);
            return isAssignable(inputTypes, slotTypes);
        }
    }
    return isAssignable(interfaceMethod.getParameterTypes(), delegateMethod.getParameterTypes());
}