Search in sources :

Example 1 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class ActivationConfig$JAXB method _read.

public static final ActivationConfig _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final ActivationConfig activationConfig = new ActivationConfig();
    context.beforeUnmarshal(activationConfig, LifecycleCallback.NONE);
    ArrayList<Text> descriptions = null;
    List<ActivationConfigProperty> activationConfigProperty = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("activation-configType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, ActivationConfig.class);
        }
    }
    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
        if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
            // ATTRIBUTE: id
            final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
            context.addXmlId(reader, id, activationConfig);
            activationConfig.id = id;
        } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
            context.unexpectedAttribute(attribute, new QName("", "id"));
        }
    }
    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
        if (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: descriptions
            final Text descriptionsItem = readText(elementReader, context);
            if (descriptions == null) {
                descriptions = new ArrayList<Text>();
            }
            descriptions.add(descriptionsItem);
        } else if (("activation-config-property" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: activationConfigProperty
            final ActivationConfigProperty activationConfigPropertyItem = readActivationConfigProperty(elementReader, context);
            if (activationConfigProperty == null) {
                activationConfigProperty = activationConfig.activationConfigProperty;
                if (activationConfigProperty != null) {
                    activationConfigProperty.clear();
                } else {
                    activationConfigProperty = new ArrayList<ActivationConfigProperty>();
                }
            }
            activationConfigProperty.add(activationConfigPropertyItem);
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "activation-config-property"));
        }
    }
    if (descriptions != null) {
        try {
            activationConfig.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
        } catch (final Exception e) {
            context.setterError(reader, ActivationConfig.class, "setDescriptions", Text[].class, e);
        }
    }
    if (activationConfigProperty != null) {
        activationConfig.activationConfigProperty = activationConfigProperty;
    }
    context.afterUnmarshal(activationConfig, LifecycleCallback.NONE);
    return activationConfig;
}
Also used : ActivationConfigProperty$JAXB.readActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty) ActivationConfigProperty$JAXB.writeActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Text$JAXB.readText(org.apache.openejb.jee.Text$JAXB.readText) Text$JAXB.writeText(org.apache.openejb.jee.Text$JAXB.writeText) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 2 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class EjbJarInfoBuilder method initMessageBean.

private EnterpriseBeanInfo initMessageBean(final MessageDrivenBean mdb, final Map m) throws OpenEJBException {
    final MessageDrivenBeanInfo bean = new MessageDrivenBeanInfo();
    bean.timeoutMethod = toInfo(mdb.getTimeoutMethod());
    copyCallbacks(mdb.getAroundTimeout(), bean.aroundTimeout);
    copyCallbacks(mdb.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(mdb.getPostConstruct(), bean.postConstruct);
    copyCallbacks(mdb.getPreDestroy(), bean.preDestroy);
    copySchedules(mdb.getTimer(), bean.methodScheduleInfos);
    final EjbDeployment d = (EjbDeployment) m.get(mdb.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + mdb.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = mdb.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = mdb.getDescription();
    bean.displayName = mdb.getDisplayName();
    bean.ejbClass = mdb.getEjbClass();
    bean.ejbName = mdb.getEjbName();
    final TransactionType txType = mdb.getTransactionType();
    bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.properties.putAll(d.getProperties());
    if (mdb.getMessagingType() != null) {
        bean.mdbInterface = mdb.getMessagingType();
    } else {
        bean.mdbInterface = "javax.jms.MessageListener";
    }
    final ResourceLink resourceLink = d.getResourceLink("openejb/destination");
    if (resourceLink != null) {
        bean.destinationId = resourceLink.getResId();
    }
    if (mdb.getMessageDestinationType() != null) {
        bean.activationProperties.put("destinationType", mdb.getMessageDestinationType());
    }
    final ActivationConfig activationConfig = mdb.getActivationConfig();
    if (activationConfig != null) {
        for (final ActivationConfigProperty property : activationConfig.getActivationConfigProperty()) {
            final String name = property.getActivationConfigPropertyName();
            final String value = property.getActivationConfigPropertyValue();
            bean.activationProperties.put(name, value);
        }
    }
    return bean;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) TransactionType(org.apache.openejb.jee.TransactionType) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Icon(org.apache.openejb.jee.Icon) ActivationConfig(org.apache.openejb.jee.ActivationConfig)

Example 3 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class MdbConfigTest method createJaxbMdb.

private MessageDrivenBean createJaxbMdb(final String ejbName, final String mdbClass, final String messageListenerInterface) {
    final MessageDrivenBean bean = new MessageDrivenBean(ejbName);
    bean.setEjbClass(mdbClass);
    bean.setMessagingType(messageListenerInterface);
    final ActivationConfig activationConfig = new ActivationConfig();
    activationConfig.getActivationConfigProperty().add(new ActivationConfigProperty("destination", ejbName));
    activationConfig.getActivationConfigProperty().add(new ActivationConfigProperty("destinationType", "javax.jms.Queue"));
    bean.setActivationConfig(activationConfig);
    return bean;
}
Also used : ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ActivationConfig(org.apache.openejb.jee.ActivationConfig)

Example 4 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class AutoConfig method processActivationConfig.

/**
     * Set destination, destinationType, clientId and subscriptionName in the MDB activation config.
     */
private void processActivationConfig(final EjbModule ejbModule) throws OpenEJBException {
    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
        openejbJar = ejbModule.getOpenejbJar();
    } else {
        openejbJar = new OpenejbJar();
        ejbModule.setOpenejbJar(openejbJar);
    }
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        if (bean instanceof MessageDrivenBean) {
            final MessageDrivenBean mdb = (MessageDrivenBean) bean;
            if (mdb.getActivationConfig() == null) {
                mdb.setActivationConfig(new ActivationConfig());
            }
            if (!isJms(mdb)) {
                continue;
            }
            final EjbDeployment ejbDeployment = deployments.get(bean.getEjbName());
            if (ejbDeployment == null) {
                throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
            }
            final Properties properties = mdb.getActivationConfig().toProperties();
            String destination = properties.getProperty("destinationName", properties.getProperty("destinationLookup"));
            if (destination != null) {
                if (destination.startsWith("openejb:Resource/")) {
                    destination = destination.substring("openejb:Resource/".length());
                }
                if (destination.startsWith("java:openejb/Resource/")) {
                    destination = destination.substring("java:openejb/Resource/".length());
                }
                mdb.getActivationConfig().addProperty("destination", destination);
                // Remove destinationName as it is not in the standard ActivationSpec 
                final List<ActivationConfigProperty> list = mdb.getActivationConfig().getActivationConfigProperty();
                final Iterator<ActivationConfigProperty> iterator = list.iterator();
                while (iterator.hasNext()) {
                    final ActivationConfigProperty configProperty = iterator.next();
                    final String activationConfigPropertyName = configProperty.getActivationConfigPropertyName();
                    if (activationConfigPropertyName.equals("destinationName") || activationConfigPropertyName.equals("destinationLookup")) {
                        iterator.remove();
                        // we suppose we have only one of both we should be the case
                        break;
                    }
                }
            } else {
                destination = properties.getProperty("destination");
            }
            if (destination == null) {
                // EE 7/EJB 3.2
                destination = properties.getProperty("destinationLookup");
            }
            //                String destination = properties.getProperty("destination", properties.getProperty("destinationName"));
            if (destination == null) {
                destination = ejbDeployment.getDeploymentId();
                mdb.getActivationConfig().addProperty("destination", destination);
            }
            // destination identifier
            ResourceLink link = ejbDeployment.getResourceLink("openejb/destination");
            if (link == null && mdb.getMessageDestinationLink() == null) {
                link = new ResourceLink();
                link.setResId(destination);
                link.setResRefName("openejb/destination");
                ejbDeployment.addResourceLink(link);
            }
            // destination type
            String destinationType = properties.getProperty("destinationType");
            if (destinationType == null && mdb.getMessageDestinationType() != null) {
                destinationType = mdb.getMessageDestinationType();
                mdb.getActivationConfig().addProperty("destinationType", destinationType);
            }
            if (mdb.getMessageDestinationType() == null) {
                mdb.setMessageDestinationType(destinationType);
            }
            // topics need a clientId and subscriptionName
            if ("javax.jms.Topic".equals(destinationType)) {
                if (Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.activemq.deploymentId-as-clientId", ejbModule.getProperties().getProperty("openejb.activemq.deploymentId-as-clientId", "true"))) && !properties.containsKey("clientId")) {
                    mdb.getActivationConfig().addProperty("clientId", ejbDeployment.getDeploymentId());
                }
                if (!properties.containsKey("subscriptionName")) {
                    mdb.getActivationConfig().addProperty("subscriptionName", ejbDeployment.getDeploymentId() + "_subscription");
                }
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) ActivationConfig(org.apache.openejb.jee.ActivationConfig) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ResourceLink(org.apache.openejb.jee.oejb3.ResourceLink) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Example 5 with ActivationConfigProperty$JAXB.writeActivationConfigProperty

use of org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty in project tomee by apache.

the class OpenEjb2Conversion method convertMdbConfigs.

public final void convertMdbConfigs(final EjbJar ejbJar, final OpenejbJarType openejbJarType) {
    final Map<String, MessageDrivenBean> mdbs = new TreeMap<String, MessageDrivenBean>();
    for (final EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
        if (!(enterpriseBean instanceof MessageDrivenBean)) {
            continue;
        }
        mdbs.put(enterpriseBean.getEjbName(), (MessageDrivenBean) enterpriseBean);
    }
    for (final org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
        if (!(enterpriseBean instanceof MessageDrivenBeanType)) {
            continue;
        }
        final MessageDrivenBeanType bean = (MessageDrivenBeanType) enterpriseBean;
        final MessageDrivenBean mdb = mdbs.get(bean.getEjbName());
        if (mdb == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        final ActivationConfigType activationConfigType = bean.getActivationConfig();
        if (activationConfigType != null) {
            ActivationConfig activationConfig = mdb.getActivationConfig();
            if (activationConfig == null) {
                activationConfig = new ActivationConfig();
                mdb.setActivationConfig(activationConfig);
            }
            for (final ActivationConfigPropertyType propertyType : activationConfigType.getActivationConfigProperty()) {
                final ActivationConfigProperty property = new ActivationConfigProperty(propertyType.getActivationConfigPropertyName(), propertyType.getActivationConfigPropertyValue());
                activationConfig.getActivationConfigProperty().add(property);
            }
        }
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) MessageDrivenBeanType(org.apache.openejb.jee.oejb2.MessageDrivenBeanType) TreeMap(java.util.TreeMap) ActivationConfig(org.apache.openejb.jee.ActivationConfig) ActivationConfigProperty(org.apache.openejb.jee.ActivationConfigProperty) ActivationConfigPropertyType(org.apache.openejb.jee.oejb2.ActivationConfigPropertyType) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ActivationConfigType(org.apache.openejb.jee.oejb2.ActivationConfigType)

Aggregations

ActivationConfig (org.apache.openejb.jee.ActivationConfig)5 ActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty)5 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)4 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)3 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 Properties (java.util.Properties)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ActivationConfigProperty$JAXB.readActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty$JAXB.readActivationConfigProperty)2 ActivationConfigProperty$JAXB.writeActivationConfigProperty (org.apache.openejb.jee.ActivationConfigProperty$JAXB.writeActivationConfigProperty)2 Text$JAXB.readText (org.apache.openejb.jee.Text$JAXB.readText)2 Text$JAXB.writeText (org.apache.openejb.jee.Text$JAXB.writeText)2 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)2 ResourceLink (org.apache.openejb.jee.oejb3.ResourceLink)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)1 QName (javax.xml.namespace.QName)1 MessageDrivenBeanInfo (org.apache.openejb.assembler.classic.MessageDrivenBeanInfo)1