Example usage for java.lang Class isInterface

List of usage examples for java.lang Class isInterface

Introduction

In this page you can find the example usage for java.lang Class isInterface.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isInterface();

Source Link

Document

Determines if the specified Class object represents an interface type.

Usage

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Create a new Instance of an 'Indexed' Property
 * @param name The name of the property//from w  w w  .j a  v a  2  s. co  m
 * @param type The class of the property
 * @return The new value
 */
protected Object createIndexedProperty(String name, Class type) {

    // Create the indexed object
    Object indexedProperty = null;

    if (type == null) {

        indexedProperty = defaultIndexedProperty(name);

    } else if (type.isArray()) {

        indexedProperty = Array.newInstance(type.getComponentType(), 0);

    } else if (List.class.isAssignableFrom(type)) {
        if (type.isInterface()) {
            indexedProperty = defaultIndexedProperty(name);
        } else {
            try {
                indexedProperty = type.newInstance();
            } catch (Exception ex) {
                throw new IllegalArgumentException("Error instantiating indexed property of type '"
                        + type.getName() + "' for '" + name + "' " + ex);
            }
        }
    } else {

        throw new IllegalArgumentException(
                "Non-indexed property of type '" + type.getName() + "' for '" + name + "'");
    }

    return indexedProperty;

}

From source file:org.apache.camel.impl.CamelPostProcessorHelper.java

/**
 * Creates the object to be injected for an {@link org.apache.camel.EndpointInject} or {@link org.apache.camel.Produce} injection point
 *//*w w w  . j  av  a  2 s  .  com*/
@SuppressWarnings("unchecked")
public Object getInjectionValue(Class<?> type, String endpointUri, String endpointRef,
        String injectionPointName, Object bean, String beanName) {
    if (type.isAssignableFrom(ProducerTemplate.class)) {
        return createInjectionProducerTemplate(endpointUri, endpointRef, injectionPointName);
    } else if (type.isAssignableFrom(ConsumerTemplate.class)) {
        return createInjectionConsumerTemplate(endpointUri, endpointRef, injectionPointName);
    } else {
        Endpoint endpoint = getEndpointInjection(endpointUri, endpointRef, injectionPointName, true);
        if (endpoint != null) {
            if (type.isInstance(endpoint)) {
                return endpoint;
            } else if (type.isAssignableFrom(Producer.class)) {
                return createInjectionProducer(endpoint, bean, beanName);
            } else if (type.isAssignableFrom(PollingConsumer.class)) {
                return createInjectionPollingConsumer(endpoint, bean, beanName);
            } else if (type.isInterface()) {
                // lets create a proxy
                try {
                    return ProxyHelper.createProxy(endpoint, type);
                } catch (Exception e) {
                    throw createProxyInstantiationRuntimeException(type, endpoint, e);
                }
            } else {
                throw new IllegalArgumentException("Invalid type: " + type.getName()
                        + " which cannot be injected via @EndpointInject/@Produce for: " + endpoint);
            }
        }
        return null;
    }
}

From source file:org.firebrandocm.dao.AbstractPersistenceFactory.java

/**
 * @param entityClass the class type for this instance
 * @param <T>         the type of class to be returned
 * @return an instance of this type after transformation of its accessors to notify the persistence context that there are ongoing changes
 *//*  ww w  .j a  v  a2s.co  m*/
@SuppressWarnings("unchecked")
public <T> T getInstance(Class<T> entityClass) {
    final ClassMetadata<T> metadata = getClassMetadata(entityClass);
    T instance;
    try {
        if (metadata != null) { //create a proxy that can support lazy loading and interception of certain methods
            instance = metadata.createProxy();
        } else { //an embedded entity with no metadata
            if (entityClass.isInterface()) {
                Class implClass = defaultInterfaceContainersImpl.get(entityClass);
                if (implClass == null) {
                    throw new IllegalStateException(String.format("no default impl found for %s", entityClass));
                }
                instance = (T) implClass.newInstance();
            } else {
                instance = entityClass.newInstance();
            }
        }
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    return instance;
}

From source file:org.apache.axis.description.JavaServiceDesc.java

private Method[] getMethods(Class implClass) {
    if (implClass.isInterface()) {
        // only return methods that are not part of start classes
        List methodsList = new ArrayList();
        Method[] methods = implClass.getMethods();
        if (methods != null) {
            for (int i = 0; i < methods.length; i++) {
                String declaringClass = methods[i].getDeclaringClass().getName();
                if (!declaringClass.startsWith("java.") && !declaringClass.startsWith("javax.")) {
                    methodsList.add(methods[i]);
                }//from  w  w  w. j av  a2  s.c  om
            }
        }
        return (Method[]) methodsList.toArray(new Method[] {});
    } else {
        return implClass.getDeclaredMethods();
    }
}

From source file:com.clarkparsia.empire.annotation.RdfGenerator.java

@SuppressWarnings("unchecked")
private static <T> T getProxyOrDbObject(Object theAccessor, Class<T> theClass, Object theKey,
        DataSource theSource) throws Exception {
    long start = System.currentTimeMillis();
    if (BeanReflectUtil.isFetchTypeLazy(theAccessor)) {
        // ========= start PATCH
        try {//from   w w w  .  j a  v a  2  s  . c  om
            // try to determine proper class from rdf:type
            T rdfObj = Empire.get().instance(theClass);
            asSupportsRdfId(rdfObj).setRdfId(asPrimaryKey(theKey));
            theClass = determineClass(theClass, rdfObj, theSource, false);
        } catch (Exception ignore) {
        }
        // ========= end PATCH

        Proxy<T> aProxy = new Proxy<T>(theClass, asPrimaryKey(theKey), theSource);

        ProxyFactory aFactory = new ProxyFactory();
        aFactory.setInterfaces(ObjectArrays.concat(theClass.getInterfaces(), EmpireGenerated.class));
        if (!theClass.isInterface()) {
            aFactory.setSuperclass(theClass);
        }

        aFactory.setFilter(METHOD_FILTER);
        final ProxyHandler<T> aHandler = new ProxyHandler<T>(aProxy);

        Object aObj = aFactory.createClass(METHOD_FILTER).newInstance();

        ((ProxyObject) aObj).setHandler(aHandler);
        return (T) aObj;
    } else {
        return fromRdf(theClass, asPrimaryKey(theKey), theSource);
    }
}

From source file:com.comtop.cap.bm.metadata.common.dwr.CapMapConverter.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object convertInbound(Class<?> paramType, InboundVariable data) throws ConversionException {
    if (data.isNull()) {
        return null;
    }/*from  w  w  w  . ja v  a2 s.c  om*/

    String value = data.getValue();

    // If the text is null then the whole bean is null
    if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) {
        return null;
    }

    if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START)
            || !value.endsWith(ProtocolConstants.INBOUND_MAP_END)) {
        log.warn("Expected object while converting data for " + paramType.getName() + " in "
                + data.getContext().getCurrentProperty() + ". Passed: " + value);
        throw new ConversionException(paramType, "Data conversion error. See logs for more details.");
    }

    value = value.substring(1, value.length() - 1);

    try {
        // Maybe we ought to check that the paramType isn't expecting a more
        // distinct type of Map and attempt to create that?
        Map<Object, Object> map;

        // If paramType is concrete then just use whatever we've got.
        if (!paramType.isInterface() && !Modifier.isAbstract(paramType.getModifiers())) {
            // If there is a problem creating the type then we have no way
            // of completing this - they asked for a specific type and we
            // can't create that type. I don't know of a way of finding
            // subclasses that might be instaniable so we accept failure.
            map = (Map<Object, Object>) paramType.newInstance();
        } else {
            map = new HashMap<Object, Object>();
        }

        // Get the extra type info
        Property parent = data.getContext().getCurrentProperty();

        Property keyProp = parent.createChild(0);
        keyProp = converterManager.checkOverride(keyProp);

        Property valProp = parent.createChild(1);
        valProp = converterManager.checkOverride(valProp);

        // We should put the new object into the working map in case it
        // is referenced later nested down in the conversion process.
        data.getContext().addConverted(data, paramType, map);
        InboundContext incx = data.getContext();

        // Loop through the property declarations
        StringTokenizer st = new StringTokenizer(value, ",");
        int size = st.countTokens();
        for (int i = 0; i < size; i++) {
            String token = st.nextToken();
            if (token.trim().length() == 0) {
                continue;
            }

            int colonpos = token.indexOf(ProtocolConstants.INBOUND_MAP_ENTRY);
            if (colonpos == -1) {
                throw new ConversionException(paramType, "Missing " + ProtocolConstants.INBOUND_MAP_ENTRY
                        + " in object description: {1}" + token);
            }

            String valStr = token.substring(colonpos + 1).trim();
            String[] splitIv = ConvertUtil.splitInbound(valStr);
            String splitIvValue = splitIv[ConvertUtil.INBOUND_INDEX_VALUE];
            String splitIvType = splitIv[ConvertUtil.INBOUND_INDEX_TYPE];
            InboundVariable valIv = new InboundVariable(incx, null, splitIvType, splitIvValue);
            valIv.dereference();

            Class valTyClass = String.class;

            if ("boolean".equals(valIv.getType())) {
                valTyClass = Boolean.class;
            } else if ("array".equals(valIv.getType())) {
                valTyClass = ArrayList.class;
            } else if ("number".equals(valIv.getType())) {
                String strValue = valIv.getValue();
                if (strValue.indexOf(".") != -1) {
                    valTyClass = Double.class;
                } else {
                    valTyClass = Integer.class;
                }
            } else if ("date".equals(valIv.getType())) {
                valTyClass = Date.class;
            }

            Object val = converterManager.convertInbound(valTyClass, valIv, valProp);
            String keyStr = token.substring(0, colonpos).trim();
            map.put(keyStr, val);
        }

        return map;
    } catch (ConversionException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new ConversionException(paramType, ex);
    }
}

From source file:com.web.server.EJBDeployer.java

@Override
public void fileChanged(FileChangeEvent arg0) throws Exception {
    try {/*from   w ww. j a  va2 s.co m*/
        FileObject baseFile = arg0.getFile();
        EJBContext ejbContext;
        if (baseFile.getName().getURI().endsWith(".jar")) {
            fileDeleted(arg0);
            URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(baseFile.getName().getURI()) },
                    Thread.currentThread().getContextClassLoader());
            ConfigurationBuilder config = new ConfigurationBuilder();
            config.addUrls(ClasspathHelper.forClassLoader(classLoader));
            config.addClassLoader(classLoader);
            org.reflections.Reflections reflections = new org.reflections.Reflections(config);
            EJBContainer container = EJBContainer.getInstance(baseFile.getName().getURI(), config);
            container.inject();
            Set<Class<?>> cls = reflections.getTypesAnnotatedWith(Stateless.class);
            Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class);
            Object obj;
            System.gc();
            if (cls.size() > 0) {
                ejbContext = new EJBContext();
                ejbContext.setJarPath(baseFile.getName().getURI());
                ejbContext.setJarDeployed(baseFile.getName().getBaseName());
                for (Class<?> ejbInterface : cls) {
                    //BeanPool.getInstance().create(ejbInterface);
                    obj = BeanPool.getInstance().get(ejbInterface);
                    System.out.println(obj);
                    ProxyFactory factory = new ProxyFactory();
                    obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj),
                            servicesRegistryPort);
                    String remoteBinding = container.getRemoteBinding(ejbInterface);
                    System.out.println(remoteBinding + " for EJB" + obj);
                    if (remoteBinding != null) {
                        //registry.unbind(remoteBinding);
                        registry.rebind(remoteBinding, (Remote) obj);
                        ejbContext.put(remoteBinding, obj.getClass());
                    }
                    //registry.rebind("name", (Remote) obj);
                }
                jarEJBMap.put(baseFile.getName().getURI(), ejbContext);
            }
            System.out.println("Class Message Driven" + clsMessageDriven);
            System.out.println("Class Message Driven" + clsMessageDriven);
            if (clsMessageDriven.size() > 0) {
                System.out.println("Class Message Driven");
                MDBContext mdbContext;
                ConcurrentHashMap<String, MDBContext> mdbContexts;
                if (jarMDBMap.get(baseFile.getName().getURI()) != null) {
                    mdbContexts = jarMDBMap.get(baseFile.getName().getURI());
                } else {
                    mdbContexts = new ConcurrentHashMap<String, MDBContext>();
                }
                jarMDBMap.put(baseFile.getName().getURI(), mdbContexts);
                MDBContext mdbContextOld;
                for (Class<?> mdbBean : clsMessageDriven) {
                    String classwithpackage = mdbBean.getName();
                    System.out.println("class package" + classwithpackage);
                    classwithpackage = classwithpackage.replace("/", ".");
                    System.out.println("classList:" + classwithpackage.replace("/", "."));
                    try {
                        if (!classwithpackage.contains("$")) {
                            //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
                            //System.out.println();
                            if (!mdbBean.isInterface()) {
                                Annotation[] classServicesAnnot = mdbBean.getDeclaredAnnotations();
                                if (classServicesAnnot != null) {
                                    for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                        if (classServicesAnnot[annotcount] instanceof MessageDriven) {
                                            MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount];
                                            ActivationConfigProperty[] activationConfigProperties = messageDrivenAnnot
                                                    .activationConfig();
                                            mdbContext = new MDBContext();
                                            mdbContext.setMdbName(messageDrivenAnnot.name());
                                            for (ActivationConfigProperty activationConfigProperty : activationConfigProperties) {
                                                if (activationConfigProperty.propertyName()
                                                        .equals(MDBContext.DESTINATIONTYPE)) {
                                                    mdbContext.setDestinationType(
                                                            activationConfigProperty.propertyValue());
                                                } else if (activationConfigProperty.propertyName()
                                                        .equals(MDBContext.DESTINATION)) {
                                                    mdbContext.setDestination(
                                                            activationConfigProperty.propertyValue());
                                                } else if (activationConfigProperty.propertyName()
                                                        .equals(MDBContext.ACKNOWLEDGEMODE)) {
                                                    mdbContext.setAcknowledgeMode(
                                                            activationConfigProperty.propertyValue());
                                                }
                                            }
                                            if (mdbContext.getDestinationType().equals(Queue.class.getName())) {
                                                mdbContextOld = null;
                                                if (mdbContexts.get(mdbContext.getMdbName()) != null) {
                                                    mdbContextOld = mdbContexts.get(mdbContext.getMdbName());
                                                    if (mdbContextOld != null && mdbContext.getDestination()
                                                            .equals(mdbContextOld.getDestination())) {
                                                        throw new Exception(
                                                                "Only one MDB can listen to destination:"
                                                                        + mdbContextOld.getDestination());
                                                    }
                                                }
                                                mdbContexts.put(mdbContext.getMdbName(), mdbContext);
                                                Queue queue = (Queue) jms.lookup(mdbContext.getDestination());
                                                Connection connection = connectionFactory
                                                        .createConnection("guest", "guest");
                                                connection.start();
                                                Session session;
                                                if (mdbContext.getAcknowledgeMode() != null && mdbContext
                                                        .getAcknowledgeMode().equals("Auto-Acknowledge")) {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                } else {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                }
                                                MessageConsumer consumer = session.createConsumer(queue);
                                                consumer.setMessageListener(
                                                        (MessageListener) mdbBean.newInstance());
                                                mdbContext.setConnection(connection);
                                                mdbContext.setSession(session);
                                                mdbContext.setConsumer(consumer);
                                                System.out.println("Queue=" + queue);
                                            } else if (mdbContext.getDestinationType()
                                                    .equals(Topic.class.getName())) {
                                                if (mdbContexts.get(mdbContext.getMdbName()) != null) {
                                                    mdbContextOld = mdbContexts.get(mdbContext.getMdbName());
                                                    if (mdbContextOld.getConsumer() != null)
                                                        mdbContextOld.getConsumer().setMessageListener(null);
                                                    if (mdbContextOld.getSession() != null)
                                                        mdbContextOld.getSession().close();
                                                    if (mdbContextOld.getConnection() != null)
                                                        mdbContextOld.getConnection().close();
                                                }
                                                mdbContexts.put(mdbContext.getMdbName(), mdbContext);
                                                Topic topic = (Topic) jms.lookup(mdbContext.getDestination());
                                                Connection connection = connectionFactory
                                                        .createConnection("guest", "guest");
                                                connection.start();
                                                Session session;
                                                if (mdbContext.getAcknowledgeMode() != null && mdbContext
                                                        .getAcknowledgeMode().equals("Auto-Acknowledge")) {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                } else {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                }
                                                MessageConsumer consumer = session.createConsumer(topic);
                                                consumer.setMessageListener(
                                                        (MessageListener) mdbBean.newInstance());
                                                mdbContext.setConnection(connection);
                                                mdbContext.setSession(session);
                                                mdbContext.setConsumer(consumer);
                                                System.out.println("Topic=" + topic);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            classLoader.close();
            System.out.println(baseFile.getName().getURI() + " Deployed");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:com.web.server.EJBDeployer.java

@Override
public void fileCreated(FileChangeEvent arg0) throws Exception {
    try {//ww w  .j a va 2  s .com
        FileObject baseFile = arg0.getFile();
        EJBContext ejbContext;
        if (baseFile.getName().getURI().endsWith(".jar")) {
            System.out.println(baseFile.getName().getURI());
            URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(baseFile.getName().getURI()) },
                    Thread.currentThread().getContextClassLoader());
            ConfigurationBuilder config = new ConfigurationBuilder();
            config.addUrls(ClasspathHelper.forClassLoader(classLoader));
            config.addClassLoader(classLoader);
            org.reflections.Reflections reflections = new org.reflections.Reflections(config);
            EJBContainer container = EJBContainer.getInstance(baseFile.getName().getURI(), config);
            container.inject();
            Set<Class<?>> clsStateless = reflections.getTypesAnnotatedWith(Stateless.class);
            Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class);
            Object obj;
            System.gc();
            if (clsStateless.size() > 0) {
                ejbContext = new EJBContext();
                ejbContext.setJarPath(baseFile.getName().getURI());
                ejbContext.setJarDeployed(baseFile.getName().getBaseName());
                for (Class<?> ejbInterface : clsStateless) {
                    //BeanPool.getInstance().create(ejbInterface);
                    obj = BeanPool.getInstance().get(ejbInterface);
                    System.out.println(obj);
                    ProxyFactory factory = new ProxyFactory();
                    obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj),
                            servicesRegistryPort);
                    String remoteBinding = container.getRemoteBinding(ejbInterface);
                    System.out.println(remoteBinding + " for EJB" + obj);
                    if (remoteBinding != null) {
                        //registry.unbind(remoteBinding);
                        registry.rebind(remoteBinding, (Remote) obj);
                        ejbContext.put(remoteBinding, obj.getClass());
                    }
                    //registry.rebind("name", (Remote) obj);
                }
                jarEJBMap.put(baseFile.getName().getURI(), ejbContext);
            }
            System.out.println("Class Message Driven" + clsMessageDriven);
            System.out.println("Class Message Driven" + clsMessageDriven);
            if (clsMessageDriven.size() > 0) {
                System.out.println("Class Message Driven");
                MDBContext mdbContext;
                ConcurrentHashMap<String, MDBContext> mdbContexts;
                if (jarMDBMap.get(baseFile.getName().getURI()) != null) {
                    mdbContexts = jarMDBMap.get(baseFile.getName().getURI());
                } else {
                    mdbContexts = new ConcurrentHashMap<String, MDBContext>();
                }
                jarMDBMap.put(baseFile.getName().getURI(), mdbContexts);
                MDBContext mdbContextOld;
                for (Class<?> mdbBean : clsMessageDriven) {
                    String classwithpackage = mdbBean.getName();
                    System.out.println("class package" + classwithpackage);
                    classwithpackage = classwithpackage.replace("/", ".");
                    System.out.println("classList:" + classwithpackage.replace("/", "."));
                    try {
                        if (!classwithpackage.contains("$")) {
                            //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
                            //System.out.println();
                            if (!mdbBean.isInterface()) {
                                Annotation[] classServicesAnnot = mdbBean.getDeclaredAnnotations();
                                if (classServicesAnnot != null) {
                                    for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                        if (classServicesAnnot[annotcount] instanceof MessageDriven) {
                                            MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount];
                                            ActivationConfigProperty[] activationConfigProperties = messageDrivenAnnot
                                                    .activationConfig();
                                            mdbContext = new MDBContext();
                                            mdbContext.setMdbName(messageDrivenAnnot.name());
                                            for (ActivationConfigProperty activationConfigProperty : activationConfigProperties) {
                                                if (activationConfigProperty.propertyName()
                                                        .equals(MDBContext.DESTINATIONTYPE)) {
                                                    mdbContext.setDestinationType(
                                                            activationConfigProperty.propertyValue());
                                                } else if (activationConfigProperty.propertyName()
                                                        .equals(MDBContext.DESTINATION)) {
                                                    mdbContext.setDestination(
                                                            activationConfigProperty.propertyValue());
                                                } else if (activationConfigProperty.propertyName()
                                                        .equals(MDBContext.ACKNOWLEDGEMODE)) {
                                                    mdbContext.setAcknowledgeMode(
                                                            activationConfigProperty.propertyValue());
                                                }
                                            }
                                            if (mdbContext.getDestinationType().equals(Queue.class.getName())) {
                                                mdbContextOld = null;
                                                if (mdbContexts.get(mdbContext.getMdbName()) != null) {
                                                    mdbContextOld = mdbContexts.get(mdbContext.getMdbName());
                                                    if (mdbContextOld != null && mdbContext.getDestination()
                                                            .equals(mdbContextOld.getDestination())) {
                                                        throw new Exception(
                                                                "Only one MDB can listen to destination:"
                                                                        + mdbContextOld.getDestination());
                                                    }
                                                }
                                                mdbContexts.put(mdbContext.getMdbName(), mdbContext);
                                                Queue queue = (Queue) jms.lookup(mdbContext.getDestination());
                                                Connection connection = connectionFactory
                                                        .createConnection("guest", "guest");
                                                connection.start();
                                                Session session;
                                                if (mdbContext.getAcknowledgeMode() != null && mdbContext
                                                        .getAcknowledgeMode().equals("Auto-Acknowledge")) {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                } else {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                }
                                                MessageConsumer consumer = session.createConsumer(queue);
                                                consumer.setMessageListener(
                                                        (MessageListener) mdbBean.newInstance());
                                                mdbContext.setConnection(connection);
                                                mdbContext.setSession(session);
                                                mdbContext.setConsumer(consumer);
                                                System.out.println("Queue=" + queue);
                                            } else if (mdbContext.getDestinationType()
                                                    .equals(Topic.class.getName())) {
                                                if (mdbContexts.get(mdbContext.getMdbName()) != null) {
                                                    mdbContextOld = mdbContexts.get(mdbContext.getMdbName());
                                                    if (mdbContextOld.getConsumer() != null)
                                                        mdbContextOld.getConsumer().setMessageListener(null);
                                                    if (mdbContextOld.getSession() != null)
                                                        mdbContextOld.getSession().close();
                                                    if (mdbContextOld.getConnection() != null)
                                                        mdbContextOld.getConnection().close();
                                                }
                                                mdbContexts.put(mdbContext.getMdbName(), mdbContext);
                                                Topic topic = (Topic) jms.lookup(mdbContext.getDestination());
                                                Connection connection = connectionFactory
                                                        .createConnection("guest", "guest");
                                                connection.start();
                                                Session session;
                                                if (mdbContext.getAcknowledgeMode() != null && mdbContext
                                                        .getAcknowledgeMode().equals("Auto-Acknowledge")) {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                } else {
                                                    session = connection.createSession(false,
                                                            Session.AUTO_ACKNOWLEDGE);
                                                }
                                                MessageConsumer consumer = session.createConsumer(topic);
                                                consumer.setMessageListener(
                                                        (MessageListener) mdbBean.newInstance());
                                                mdbContext.setConnection(connection);
                                                mdbContext.setSession(session);
                                                mdbContext.setConsumer(consumer);
                                                System.out.println("Topic=" + topic);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            classLoader.close();
        }
        System.out.println(baseFile.getName().getURI() + " Deployed");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadAnnotatedClass(String subpackage, Class<?> objectClass, Class<?> annotationClass,
        AnnotatedClassHandler handler) throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + "." + subpackage;

    for (Class<?> cls : MiscUtilities.findSubclasses(objectClass, ipack, getClassLoader())) {

        /*/*from w  ww  .j av a  2s  . c om*/
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        /*
         * find class with annotation and send back to plugin to process it
         */
        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation.annotationType().equals(annotationClass)) {
                handler.process(annotation, cls, this);
            }
        }
    }
}

From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java

protected void loadRESTHandlers() throws ThinklabException {

    String ipack = this.getClass().getPackage().getName() + ".rest";

    for (Class<?> cls : MiscUtilities.findSubclasses(IRESTHandler.class, ipack, getClassLoader())) {

        /*/*w ww.  java  2s .  c o  m*/
         * lookup annotation, ensure we can use the class
         */
        if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
            continue;

        for (Annotation annotation : cls.getAnnotations()) {
            if (annotation instanceof RESTResourceHandler) {

                String path = ((RESTResourceHandler) annotation).path();
                String description = ((RESTResourceHandler) annotation).description();
                RESTManager.get().registerService(path, (Class<?>) cls);

                break;
            }
        }
    }

}