use of org.apache.openejb.jee.ResourceEnvRef$JAXB.writeResourceEnvRef in project tomee by apache.
the class LegacyProcessor method process.
public static void process(final Class<?> clazz, final EnterpriseBean bean) {
if (bean instanceof SessionBean) {
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getSessionType() == STATEFUL && SessionSynchronization.class.isAssignableFrom(clazz)) {
try {
sessionBean.getAfterBegin().add(new LifecycleCallback(clazz.getMethod("afterBegin")));
sessionBean.getBeforeCompletion().add(new LifecycleCallback(clazz.getMethod("beforeCompletion")));
sessionBean.getAfterCompletion().add(new LifecycleCallback(clazz.getMethod("afterCompletion", boolean.class)));
} catch (final NoSuchMethodException e) {
//Ignore, should never happen
}
}
if (javax.ejb.SessionBean.class.isAssignableFrom(clazz)) {
final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.SessionBean/sessionContext", SessionContext.class);
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(clazz);
target.setInjectionTargetName("sessionContext");
ref.getInjectionTarget().add(target);
sessionBean.getResourceEnvRef().add(ref);
}
}
if (bean instanceof MessageDrivenBean) {
final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
if (javax.ejb.MessageDrivenBean.class.isAssignableFrom(clazz)) {
final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.MessageDrivenBean/messageDrivenContext", MessageDrivenContext.class);
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(clazz);
target.setInjectionTargetName("messageDrivenContext");
ref.getInjectionTarget().add(target);
messageDrivenBean.getResourceEnvRef().add(ref);
}
}
}
use of org.apache.openejb.jee.ResourceEnvRef$JAXB.writeResourceEnvRef in project tomee by apache.
the class BuiltInEnvironmentEntries method add.
private void add(final JndiConsumer jndi, final DeploymentModule module, final DeploymentModule app, final boolean defaults) {
// Standard names
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:module/ModuleName").value(module.getModuleId()).type(String.class));
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:app/AppName").value(app.getModuleId()).type(String.class));
// Standard References to built-in objects
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/BeanManager").type(BeanManager.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/Validator").type(Validator.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/ValidatorFactory").type(ValidatorFactory.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionManager").type(TransactionManager.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionSynchronizationRegistry").type(TransactionSynchronizationRegistry.class));
if (defaults) {
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedExecutorService").type(ManagedExecutorService.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedScheduledExecutorService").type(ManagedScheduledExecutorService.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedThreadFactory").type(ManagedThreadFactory.class));
try {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
contextClassLoader.loadClass("org.apache.activemq.ActiveMQSslConnectionFactory");
final ResourceEnvRef ref = new ResourceEnvRef().name("java:comp/DefaultJMSConnectionFactory").type(contextClassLoader.loadClass("javax.jms.ConnectionFactory"));
add(jndi.getResourceEnvRefMap(), ref);
} catch (final ClassNotFoundException | NoClassDefFoundError notThere) {
// no-op
}
}
// OpenEJB specific feature
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:comp/ComponentName").value(jndi.getJndiConsumerName()).type(String.class));
}
use of org.apache.openejb.jee.ResourceEnvRef$JAXB.writeResourceEnvRef in project tomee by apache.
the class ApplyOpenejbJar method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final Map<String, EjbDeployment> ejbDeployments = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
// Get the OpenEJB deployment from openejb-jar.xml
final EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
enterpriseBean.setId(ejbDeployment.getDeploymentId());
for (final ResourceRef ref : enterpriseBean.getResourceRef()) {
final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
{
ref.setMappedName(resourceLink.getResId());
}
}
for (final ResourceEnvRef ref : enterpriseBean.getResourceEnvRef()) {
final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
{
ref.setMappedName(resourceLink.getResId());
}
}
for (final MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
final ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
if (resourceLink != null && resourceLink.getResId() != null) /* don't overwrite with null */
{
ref.setMappedName(resourceLink.getResId());
}
}
for (final EjbRef ref : enterpriseBean.getEjbRef()) {
final EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
if (ejbLink != null && ejbLink.getDeployentId() != null) /* don't overwrite with null */
{
ref.setMappedName(ejbLink.getDeployentId());
}
}
for (final EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
final EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
if (ejbLink != null && ejbLink.getDeployentId() != null) /* don't overwrite with null */
{
ref.setMappedName(ejbLink.getDeployentId());
}
}
}
}
return appModule;
}
use of org.apache.openejb.jee.ResourceEnvRef$JAXB.writeResourceEnvRef in project tomee by apache.
the class InjectionTest method setUp.
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
statelessContainerInfo.properties.setProperty("TimeOut", "10");
statelessContainerInfo.properties.setProperty("MaxSize", "0");
statelessContainerInfo.properties.setProperty("StrictPooling", "false");
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
final StatelessBean bean = new StatelessBean(WidgetBean.class);
bean.addBusinessLocal(Widget.class.getName());
bean.addBusinessRemote(RemoteWidget.class.getName());
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(bean);
bean.getEnvEntry().add(new EnvEntry(name("myString"), "java.lang.String", "2"));
bean.getEnvEntry().add(new EnvEntry(name("myDouble"), "java.lang.Double", "3.0"));
bean.getEnvEntry().add(new EnvEntry(name("myLong"), "java.lang.Long", "4"));
bean.getEnvEntry().add(new EnvEntry(name("myFloat"), "java.lang.Float", "5"));
bean.getEnvEntry().add(new EnvEntry(name("myInteger"), "java.lang.Integer", "6"));
bean.getEnvEntry().add(new EnvEntry(name("myShort"), "java.lang.Short", "7"));
bean.getEnvEntry().add(new EnvEntry(name("myBoolean"), "java.lang.Boolean", "false"));
bean.getEnvEntry().add(new EnvEntry(name("myByte"), "java.lang.Byte", "8"));
bean.getEnvEntry().add(new EnvEntry(name("myCharacter"), "java.lang.Character", "9"));
bean.getEnvEntry().add(new EnvEntry(name("myClass"), "java.lang.Class", Widget.class.getName()));
bean.getEnvEntry().add(new EnvEntry(name("myTimeUnit"), TimeUnit.class.getName(), "HOURS"));
final EnvEntry entry = new EnvEntry("injectedBoolean", (String) null, "true");
entry.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "injectedBoolean")));
bean.getEnvEntry().add(entry);
final ResourceEnvRef resourceEnvRef = new ResourceEnvRef("injectedContext", (String) null);
resourceEnvRef.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "injectedContext")));
bean.getResourceEnvRef().add(resourceEnvRef);
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.jee.ResourceEnvRef$JAXB.writeResourceEnvRef in project tomee by apache.
the class Interceptor$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final Interceptor interceptor, RuntimeContext context) throws Exception {
if (interceptor == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (Interceptor.class != interceptor.getClass()) {
context.unexpectedSubclass(writer, interceptor, Interceptor.class);
return;
}
context.beforeMarshal(interceptor, org.metatype.sxc.jaxb.LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = interceptor.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(interceptor, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: descriptions
Text[] descriptions = null;
try {
descriptions = interceptor.getDescriptions();
} catch (final Exception e) {
context.getterError(interceptor, "descriptions", Interceptor.class, "getDescriptions", e);
}
if (descriptions != null) {
for (final Text descriptionsItem : descriptions) {
if (descriptionsItem != null) {
writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
writeText(writer, descriptionsItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "descriptions");
}
}
}
// ELEMENT: interceptorClass
final String interceptorClassRaw = interceptor.interceptorClass;
String interceptorClass = null;
try {
interceptorClass = Adapters.collapsedStringAdapterAdapter.marshal(interceptorClassRaw);
} catch (final Exception e) {
context.xmlAdapterError(interceptor, "interceptorClass", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (interceptorClass != null) {
writer.writeStartElement(prefix, "interceptor-class", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(interceptorClass);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "interceptorClass");
}
// ELEMENT: aroundInvoke
final List<AroundInvoke> aroundInvoke = interceptor.aroundInvoke;
if (aroundInvoke != null) {
for (final AroundInvoke aroundInvokeItem : aroundInvoke) {
if (aroundInvokeItem != null) {
writer.writeStartElement(prefix, "around-invoke", "http://java.sun.com/xml/ns/javaee");
writeAroundInvoke(writer, aroundInvokeItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "aroundInvoke");
}
}
}
// ELEMENT: aroundTimeout
final List<AroundTimeout> aroundTimeout = interceptor.aroundTimeout;
if (aroundTimeout != null) {
for (final AroundTimeout aroundTimeoutItem : aroundTimeout) {
if (aroundTimeoutItem != null) {
writer.writeStartElement(prefix, "around-timeout", "http://java.sun.com/xml/ns/javaee");
writeAroundTimeout(writer, aroundTimeoutItem, context);
writer.writeEndElement();
}
}
}
// ELEMENT: envEntry
final KeyedCollection<String, EnvEntry> envEntry = interceptor.envEntry;
if (envEntry != null) {
for (final EnvEntry envEntryItem : envEntry) {
if (envEntryItem != null) {
writer.writeStartElement(prefix, "env-entry", "http://java.sun.com/xml/ns/javaee");
writeEnvEntry(writer, envEntryItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "envEntry");
}
}
}
// ELEMENT: ejbRef
final KeyedCollection<String, EjbRef> ejbRef = interceptor.ejbRef;
if (ejbRef != null) {
for (final EjbRef ejbRefItem : ejbRef) {
if (ejbRefItem != null) {
writer.writeStartElement(prefix, "ejb-ref", "http://java.sun.com/xml/ns/javaee");
writeEjbRef(writer, ejbRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "ejbRef");
}
}
}
// ELEMENT: ejbLocalRef
final KeyedCollection<String, EjbLocalRef> ejbLocalRef = interceptor.ejbLocalRef;
if (ejbLocalRef != null) {
for (final EjbLocalRef ejbLocalRefItem : ejbLocalRef) {
if (ejbLocalRefItem != null) {
writer.writeStartElement(prefix, "ejb-local-ref", "http://java.sun.com/xml/ns/javaee");
writeEjbLocalRef(writer, ejbLocalRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "ejbLocalRef");
}
}
}
// ELEMENT: serviceRef
final KeyedCollection<String, ServiceRef> serviceRef = interceptor.serviceRef;
if (serviceRef != null) {
for (final ServiceRef serviceRefItem : serviceRef) {
if (serviceRefItem != null) {
writer.writeStartElement(prefix, "service-ref", "http://java.sun.com/xml/ns/javaee");
writeServiceRef(writer, serviceRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "serviceRef");
}
}
}
// ELEMENT: resourceRef
final KeyedCollection<String, ResourceRef> resourceRef = interceptor.resourceRef;
if (resourceRef != null) {
for (final ResourceRef resourceRefItem : resourceRef) {
if (resourceRefItem != null) {
writer.writeStartElement(prefix, "resource-ref", "http://java.sun.com/xml/ns/javaee");
writeResourceRef(writer, resourceRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "resourceRef");
}
}
}
// ELEMENT: resourceEnvRef
final KeyedCollection<String, ResourceEnvRef> resourceEnvRef = interceptor.resourceEnvRef;
if (resourceEnvRef != null) {
for (final ResourceEnvRef resourceEnvRefItem : resourceEnvRef) {
if (resourceEnvRefItem != null) {
writer.writeStartElement(prefix, "resource-env-ref", "http://java.sun.com/xml/ns/javaee");
writeResourceEnvRef(writer, resourceEnvRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "resourceEnvRef");
}
}
}
// ELEMENT: messageDestinationRef
final KeyedCollection<String, MessageDestinationRef> messageDestinationRef = interceptor.messageDestinationRef;
if (messageDestinationRef != null) {
for (final MessageDestinationRef messageDestinationRefItem : messageDestinationRef) {
if (messageDestinationRefItem != null) {
writer.writeStartElement(prefix, "message-destination-ref", "http://java.sun.com/xml/ns/javaee");
writeMessageDestinationRef(writer, messageDestinationRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "messageDestinationRef");
}
}
}
// ELEMENT: persistenceContextRef
final KeyedCollection<String, PersistenceContextRef> persistenceContextRef = interceptor.persistenceContextRef;
if (persistenceContextRef != null) {
for (final PersistenceContextRef persistenceContextRefItem : persistenceContextRef) {
if (persistenceContextRefItem != null) {
writer.writeStartElement(prefix, "persistence-context-ref", "http://java.sun.com/xml/ns/javaee");
writePersistenceContextRef(writer, persistenceContextRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "persistenceContextRef");
}
}
}
// ELEMENT: persistenceUnitRef
final KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef = interceptor.persistenceUnitRef;
if (persistenceUnitRef != null) {
for (final PersistenceUnitRef persistenceUnitRefItem : persistenceUnitRef) {
if (persistenceUnitRefItem != null) {
writer.writeStartElement(prefix, "persistence-unit-ref", "http://java.sun.com/xml/ns/javaee");
writePersistenceUnitRef(writer, persistenceUnitRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "persistenceUnitRef");
}
}
}
// ELEMENT: postConstruct
final List<org.apache.openejb.jee.LifecycleCallback> postConstruct = interceptor.postConstruct;
if (postConstruct != null) {
for (final org.apache.openejb.jee.LifecycleCallback postConstructItem : postConstruct) {
if (postConstructItem != null) {
writer.writeStartElement(prefix, "post-construct", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, postConstructItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "postConstruct");
}
}
}
// ELEMENT: preDestroy
final List<org.apache.openejb.jee.LifecycleCallback> preDestroy = interceptor.preDestroy;
if (preDestroy != null) {
for (final org.apache.openejb.jee.LifecycleCallback preDestroyItem : preDestroy) {
if (preDestroyItem != null) {
writer.writeStartElement(prefix, "pre-destroy", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, preDestroyItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "preDestroy");
}
}
}
// ELEMENT: dataSource
final KeyedCollection<String, DataSource> dataSource = interceptor.dataSource;
if (dataSource != null) {
for (final DataSource dataSourceItem : dataSource) {
if (dataSourceItem != null) {
writer.writeStartElement(prefix, "data-source", "http://java.sun.com/xml/ns/javaee");
writeDataSource(writer, dataSourceItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "dataSource");
}
}
}
// ELEMENT: postActivate
final List<org.apache.openejb.jee.LifecycleCallback> postActivate = interceptor.postActivate;
if (postActivate != null) {
for (final org.apache.openejb.jee.LifecycleCallback postActivateItem : postActivate) {
if (postActivateItem != null) {
writer.writeStartElement(prefix, "post-activate", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, postActivateItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "postActivate");
}
}
}
// ELEMENT: prePassivate
final List<org.apache.openejb.jee.LifecycleCallback> prePassivate = interceptor.prePassivate;
if (prePassivate != null) {
for (final org.apache.openejb.jee.LifecycleCallback prePassivateItem : prePassivate) {
if (prePassivateItem != null) {
writer.writeStartElement(prefix, "pre-passivate", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, prePassivateItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "prePassivate");
}
}
}
// ELEMENT: afterBegin
final List<org.apache.openejb.jee.LifecycleCallback> afterBegin = interceptor.afterBegin;
if (afterBegin != null) {
for (final org.apache.openejb.jee.LifecycleCallback afterBeginItem : afterBegin) {
if (afterBeginItem != null) {
writer.writeStartElement(prefix, "after-begin", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, afterBeginItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "afterBegin");
}
}
}
// ELEMENT: beforeCompletion
final List<org.apache.openejb.jee.LifecycleCallback> beforeCompletion = interceptor.beforeCompletion;
if (beforeCompletion != null) {
for (final org.apache.openejb.jee.LifecycleCallback beforeCompletionItem : beforeCompletion) {
if (beforeCompletionItem != null) {
writer.writeStartElement(prefix, "before-completion", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, beforeCompletionItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "beforeCompletion");
}
}
}
// ELEMENT: afterCompletion
final List<org.apache.openejb.jee.LifecycleCallback> afterCompletion = interceptor.afterCompletion;
if (afterCompletion != null) {
for (final org.apache.openejb.jee.LifecycleCallback afterCompletionItem : afterCompletion) {
if (afterCompletionItem != null) {
writer.writeStartElement(prefix, "after-completion", "http://java.sun.com/xml/ns/javaee");
writeLifecycleCallback(writer, afterCompletionItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(interceptor, "afterCompletion");
}
}
}
context.afterMarshal(interceptor, org.metatype.sxc.jaxb.LifecycleCallback.NONE);
}
Aggregations