Search in sources :

Example 1 with EjbLocalRefType

use of org.apache.openejb.jee.oejb2.EjbLocalRefType in project tomee by apache.

the class OpenEjb2Conversion method convertEjbRefs.

public final void convertEjbRefs(final EjbJar ejbJar, final OpenejbJar openejbJar, final OpenejbJarType openejbJarType) {
    openejbJar.getProperties().putAll(openejbJarType.getProperties());
    final Map<String, EnterpriseBean> ejbs = ejbJar.getEnterpriseBeansByEjbName();
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
        final EnterpriseBean ejb = ejbs.get(enterpriseBean.getEjbName());
        if (ejb == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        final Map<String, EjbRef> ejbRefs = ejb.getEjbRefMap();
        final EjbDeployment deployment = deployments.get(enterpriseBean.getEjbName());
        if (deployment == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        // Add WS Security
        if (enterpriseBean instanceof SessionBeanType) {
            final SessionBeanType sessionBean = (SessionBeanType) enterpriseBean;
            final WebServiceSecurityType webServiceSecurityType = sessionBean.getWebServiceSecurity();
            if (webServiceSecurityType != null) {
                if (webServiceSecurityType.getRealmName() != null) {
                    deployment.addProperty("webservice.security.realm", webServiceSecurityType.getRealmName());
                }
                if (webServiceSecurityType.getSecurityRealmName() != null) {
                    deployment.addProperty("webservice.security.securityRealm", webServiceSecurityType.getSecurityRealmName());
                }
                if (webServiceSecurityType.getTransportGuarantee() != null) {
                    deployment.addProperty("webservice.security.transportGarantee", webServiceSecurityType.getTransportGuarantee().value());
                } else {
                    deployment.addProperty("webservice.security.transportGarantee", "NONE");
                }
                if (webServiceSecurityType.getAuthMethod() != null) {
                    deployment.addProperty("webservice.security.authMethod", webServiceSecurityType.getAuthMethod().value());
                } else {
                    deployment.addProperty("webservice.security.authMethod", "NONE");
                }
                deployment.getProperties().putAll(webServiceSecurityType.getProperties());
            }
            if (sessionBean.getWebServiceAddress() != null) {
                deployment.getProperties().put("openejb.webservice.deployment.address", sessionBean.getWebServiceAddress());
            }
        }
        deployment.getProperties().putAll(enterpriseBean.getProperties());
        for (final String name : enterpriseBean.getLocalJndiName()) {
            deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "LocalHome"));
        }
        for (final String name : enterpriseBean.getJndiName()) {
            deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "RemoteHome"));
        }
        for (final Jndi jndi : enterpriseBean.getJndi()) {
            deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(jndi.getName(), jndi.getInterface()));
        }
        final Set<String> ejbLinks = new TreeSet<String>();
        for (final EjbLink ejbLink : deployment.getEjbLink()) {
            ejbLinks.add(ejbLink.getEjbRefName());
        }
        for (final EjbRefType refType : enterpriseBean.getEjbRef()) {
            final String refName = refType.getRefName();
            if (ejbLinks.contains(refName)) {
                // don't overwrite refs that have been already set
                continue;
            }
            final String nsCorbaloc = refType.getNsCorbaloc();
            if (nsCorbaloc != null) {
                final EjbRef ref = ejbRefs.get(refName);
                if (ref != null) {
                    ref.setMappedName("jndi:" + nsCorbaloc);
                }
            } else if (refType.getEjbLink() != null) {
                final EjbRef ref = ejbRefs.get(refName);
                if (ref != null) {
                    ref.setEjbLink(refType.getEjbLink());
                }
            } else {
                final PatternType pattern = refType.getPattern();
                addEjbLink(deployment, refName, pattern);
            }
        }
        for (final EjbLocalRefType refType : enterpriseBean.getEjbLocalRef()) {
            final String refName = refType.getRefName();
            if (ejbLinks.contains(refName)) {
                // don't overwrite refs that have been already set
                continue;
            }
            if (refType.getEjbLink() != null) {
                final EjbRef ref = ejbRefs.get(refName);
                if (ref != null) {
                    ref.setEjbLink(refType.getEjbLink());
                }
            } else {
                final PatternType pattern = refType.getPattern();
                addEjbLink(deployment, refName, pattern);
            }
        }
    }
}
Also used : PatternType(org.apache.openejb.jee.oejb2.PatternType) WebServiceSecurityType(org.apache.openejb.jee.oejb2.WebServiceSecurityType) EjbRefType(org.apache.openejb.jee.oejb2.EjbRefType) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbLocalRefType(org.apache.openejb.jee.oejb2.EjbLocalRefType) Jndi(org.apache.openejb.jee.oejb2.Jndi) EjbLink(org.apache.openejb.jee.oejb3.EjbLink) TreeSet(java.util.TreeSet) EjbRef(org.apache.openejb.jee.EjbRef) SessionBeanType(org.apache.openejb.jee.oejb2.SessionBeanType) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Aggregations

TreeSet (java.util.TreeSet)1 EjbRef (org.apache.openejb.jee.EjbRef)1 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)1 EjbLocalRefType (org.apache.openejb.jee.oejb2.EjbLocalRefType)1 EjbRefType (org.apache.openejb.jee.oejb2.EjbRefType)1 Jndi (org.apache.openejb.jee.oejb2.Jndi)1 PatternType (org.apache.openejb.jee.oejb2.PatternType)1 SessionBeanType (org.apache.openejb.jee.oejb2.SessionBeanType)1 WebServiceSecurityType (org.apache.openejb.jee.oejb2.WebServiceSecurityType)1 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)1 EjbLink (org.apache.openejb.jee.oejb3.EjbLink)1