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;
}
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;
}
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;
}
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");
}
}
}
}
}
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);
}
}
}
}
Aggregations