Search in sources :

Example 1 with ContainerType

use of org.apache.openejb.ContainerType in project aries by apache.

the class RunningApplication method registerEJBs.

private void registerEJBs() {
    Collection<String> names = new HashSet<String>();
    Dictionary<String, String> d = bundle.getHeaders();
    String valueOfExportEJBHeader = d.get("Export-EJB");
    if ((valueOfExportEJBHeader == null)) {
        return;
    }
    if (names.contains(NONE)) {
        return;
    }
    List<NameValuePair> contentsOfExportEJBHeader = ManifestHeaderProcessor.parseExportString(valueOfExportEJBHeader);
    for (NameValuePair nvp : contentsOfExportEJBHeader) {
        names.add(nvp.getName());
    }
    if (valueOfExportEJBHeader.trim().equals("")) {
        names = new AllCollection<String>();
    }
    //Register our session beans
    for (BeanContext beanContext : ctx.getDeployments()) {
        String ejbName = beanContext.getEjbName();
        //Skip if not a Singleton or stateless bean
        ContainerType type = beanContext.getContainer().getContainerType();
        boolean register = type == ContainerType.SINGLETON || type == ContainerType.STATELESS;
        //Skip if not allowed name
        register &= names.contains(ejbName);
        if (!register) {
            continue;
        }
        if (beanContext.isLocalbean()) {
            BeanContext.BusinessLocalBeanHome home = beanContext.getBusinessLocalBeanHome();
            Dictionary<String, Object> props = new Hashtable<String, Object>();
            props.put("ejb.name", ejbName);
            props.put("ejb.type", getCasedType(type));
            regs.add(bundle.getBundleContext().registerService(beanContext.getBeanClass().getName(), new EJBServiceFactory(home), props));
        }
        for (Class<?> interfce : beanContext.getBusinessLocalInterfaces()) {
            BeanContext.BusinessLocalHome home = beanContext.getBusinessLocalHome(interfce);
            Dictionary<String, Object> props = new Hashtable<String, Object>();
            props.put("ejb.name", ejbName);
            props.put("ejb.type", getCasedType(type));
            regs.add(bundle.getBundleContext().registerService(interfce.getName(), new EJBServiceFactory(home), props));
        }
        for (Class<?> interfce : beanContext.getBusinessRemoteInterfaces()) {
            List<Class> interfaces = ProxyInterfaceResolver.getInterfaces(beanContext.getBeanClass(), interfce, beanContext.getBusinessRemoteInterfaces());
            BeanContext.BusinessRemoteHome home = beanContext.getBusinessRemoteHome(interfaces, interfce);
            Dictionary<String, Object> props = new Hashtable<String, Object>();
            props.put("sevice.exported.interfaces", interfce.getName());
            props.put("ejb.name", ejbName);
            props.put("ejb.type", getCasedType(type));
            regs.add(bundle.getBundleContext().registerService(interfce.getName(), new EJBServiceFactory(home), props));
        }
    }
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) Hashtable(java.util.Hashtable) ContainerType(org.apache.openejb.ContainerType) BeanContext(org.apache.openejb.BeanContext) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 NameValuePair (org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair)1 BeanContext (org.apache.openejb.BeanContext)1 ContainerType (org.apache.openejb.ContainerType)1