use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class InitMethod$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final InitMethod initMethod, RuntimeContext context) throws Exception {
if (initMethod == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (InitMethod.class != initMethod.getClass()) {
context.unexpectedSubclass(writer, initMethod, InitMethod.class);
return;
}
context.beforeMarshal(initMethod, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = initMethod.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(initMethod, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: createMethod
final NamedMethod createMethod = initMethod.createMethod;
if (createMethod != null) {
writer.writeStartElement(prefix, "create-method", "http://java.sun.com/xml/ns/javaee");
writeNamedMethod(writer, createMethod, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(initMethod, "createMethod");
}
// ELEMENT: beanMethod
final NamedMethod beanMethod = initMethod.beanMethod;
if (beanMethod != null) {
writer.writeStartElement(prefix, "bean-method", "http://java.sun.com/xml/ns/javaee");
writeNamedMethod(writer, beanMethod, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(initMethod, "beanMethod");
}
context.afterMarshal(initMethod, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class StatefulConcurrentLookupTest method beforeClass.
@BeforeClass
public static synchronized void beforeClass() throws Exception {
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));
final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
assembler.createContainer(statefulContainerInfo);
final EjbJar ejbJar = new EjbJar();
final StatefulBean bean1 = new StatefulBean(MyLocalBeanImpl.class);
final Timeout timeout1 = new Timeout();
timeout1.setTimeout(10);
timeout1.setUnit(TimeUnit.SECONDS);
final ConcurrentMethod method1 = new ConcurrentMethod();
method1.setMethod(new NamedMethod("*"));
method1.setAccessTimeout(timeout1);
bean1.getConcurrentMethod().add(method1);
ejbJar.addEnterpriseBean(bean1);
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class StatefulInterceptorTest method buildTestApp.
public EjbModule buildTestApp() {
final EjbJar ejbJar = new EjbJar();
final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatefulBean(TargetBean.class));
Interceptor interceptor;
interceptor = ejbJar.addInterceptor(new Interceptor(ClassInterceptor.class));
ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptor.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod("echo"));
return new EjbModule(this.getClass().getClassLoader(), this.getClass().getSimpleName(), "test", ejbJar, null);
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class StatefulSessionSynchronizationTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
final Interceptor interceptor = new Interceptor(SimpleInterceptor.class);
ejbJar.addInterceptor(interceptor);
// Test SessionSynchronization interface
final StatefulBean subBeanA = new StatefulBean(SubBeanA.class);
ejbJar.addEnterpriseBean(subBeanA);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptor));
// Test configure session synchronization callback methods in deployment plan
final StatefulBean subBeanB = new StatefulBean(SubBeanB.class);
subBeanB.setAfterBeginMethod(new NamedMethod(SubBeanB.class.getDeclaredMethod("afterBegin")));
subBeanB.setBeforeCompletionMethod(new NamedMethod(SubBeanB.class.getDeclaredMethod("beforeCompletion")));
subBeanB.setAfterCompletionMethod(new NamedMethod(SubBeanB.class.getDeclaredMethod("afterCompletion", boolean.class)));
ejbJar.addEnterpriseBean(subBeanB);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptor));
// Test session synchronization methods via annotations
final StatefulBean subBeanC = new StatefulBean(SubBeanC.class);
ejbJar.addEnterpriseBean(subBeanC);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptor));
// Test override the annotations by deployment plan
final StatefulBean subBeanD = new StatefulBean(SubBeanD.class);
subBeanD.setAfterBeginMethod(new NamedMethod(SubBeanD.class.getDeclaredMethod("afterBeginNew")));
subBeanD.setBeforeCompletionMethod(new NamedMethod(SubBeanD.class.getDeclaredMethod("beforeCompletionNew")));
subBeanD.setAfterCompletionMethod(new NamedMethod(SubBeanD.class.getDeclaredMethod("afterCompletionNew", boolean.class)));
ejbJar.addEnterpriseBean(subBeanD);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanD, interceptor));
// Test only one session synchronization method @AfterBegin
final StatefulBean subBeanE = new StatefulBean(SubBeanE.class);
ejbJar.addEnterpriseBean(subBeanE);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanE, interceptor));
// Test only one session synchronization method @AfterCompletion
final StatefulBean subBeanF = new StatefulBean(SubBeanF.class);
ejbJar.addEnterpriseBean(subBeanF);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanF, interceptor));
// Test only one session synchronization method @BeforeCompletion
final StatefulBean subBeanG = new StatefulBean(SubBeanG.class);
ejbJar.addEnterpriseBean(subBeanG);
assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanG, interceptor));
// Test SessionSynchronization interface but methods are in the parent class
// Interceptor is declared on the bean method
final StatefulBean subBeanH = new StatefulBean(SubBeanH.class);
ejbJar.addEnterpriseBean(subBeanH);
// Test SessionSynchronization interface but methods are in the parent class
// using @LocalBean
final StatefulBean subBeanI = new StatefulBean(SubBeanI.class);
ejbJar.addEnterpriseBean(subBeanI);
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
final InitialContext context = new InitialContext();
final List<Call> expectedResult = Arrays.asList(Call.INTERCEPTOR_AFTER_BEGIN, Call.BEAN_AFTER_BEGIN, Call.INTERCEPTOR_AROUND_INVOKE_BEGIN, Call.BEAN_AROUND_INVOKE_BEGIN, Call.BEAN_METHOD, Call.BEAN_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_BEFORE_COMPLETION, Call.BEAN_BEFORE_COMPLETION, Call.INTERCEPTOR_AFTER_COMPLETION, Call.BEAN_AFTER_COMPLETION);
{
final BeanInterface beanA = (BeanInterface) context.lookup("SubBeanALocal");
beanA.simpleMethod();
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanB = (BeanInterface) context.lookup("SubBeanBLocal");
beanB.simpleMethod();
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanC = (BeanInterface) context.lookup("SubBeanCLocal");
beanC.simpleMethod();
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanD = (BeanInterface) context.lookup("SubBeanDLocal");
beanD.simpleMethod();
assertEquals(expectedResult, result);
result.clear();
}
{
final BeanInterface beanE = (BeanInterface) context.lookup("SubBeanELocal");
beanE.simpleMethod();
assertEquals(Arrays.asList(Call.INTERCEPTOR_AFTER_BEGIN, Call.BEAN_AFTER_BEGIN, Call.INTERCEPTOR_AROUND_INVOKE_BEGIN, Call.BEAN_AROUND_INVOKE_BEGIN, Call.BEAN_METHOD, Call.BEAN_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_BEFORE_COMPLETION, Call.INTERCEPTOR_AFTER_COMPLETION), result);
result.clear();
}
{
final BeanInterface beanF = (BeanInterface) context.lookup("SubBeanFLocal");
beanF.simpleMethod();
assertEquals(Arrays.asList(Call.INTERCEPTOR_AFTER_BEGIN, Call.INTERCEPTOR_AROUND_INVOKE_BEGIN, Call.BEAN_AROUND_INVOKE_BEGIN, Call.BEAN_METHOD, Call.BEAN_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_BEFORE_COMPLETION, Call.INTERCEPTOR_AFTER_COMPLETION, Call.BEAN_AFTER_COMPLETION), result);
result.clear();
}
{
final BeanInterface beanG = (BeanInterface) context.lookup("SubBeanGLocal");
beanG.simpleMethod();
assertEquals(Arrays.asList(Call.INTERCEPTOR_AFTER_BEGIN, Call.INTERCEPTOR_AROUND_INVOKE_BEGIN, Call.BEAN_AROUND_INVOKE_BEGIN, Call.BEAN_METHOD, Call.BEAN_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_BEFORE_COMPLETION, Call.BEAN_BEFORE_COMPLETION, Call.INTERCEPTOR_AFTER_COMPLETION), result);
result.clear();
}
final List<Call> synchAndArroundInvokeResult = Arrays.asList(Call.BEAN_AFTER_BEGIN, Call.INTERCEPTOR_AROUND_INVOKE_BEGIN, Call.BEAN_AROUND_INVOKE_BEGIN, Call.BEAN_METHOD, Call.BEAN_AROUND_INVOKE_AFTER, Call.INTERCEPTOR_AROUND_INVOKE_AFTER, Call.BEAN_BEFORE_COMPLETION, Call.BEAN_AFTER_COMPLETION);
{
final BeanInterface beanH = (BeanInterface) context.lookup("SubBeanHLocal");
beanH.simpleMethod();
assertEquals(synchAndArroundInvokeResult, result);
result.clear();
}
{
final BeanInterface beanI = (BeanInterface) context.lookup("SubBeanILocalBean");
beanI.simpleMethod();
assertEquals(synchAndArroundInvokeResult, result);
result.clear();
}
}
use of org.apache.openejb.jee.NamedMethod$JAXB.readNamedMethod in project tomee by apache.
the class StatelessInterceptorTest method buildTestApp.
public static EjbModule buildTestApp() throws Exception {
final EjbJar ejbJar = new EjbJar();
ejbJar.setId(StatelessInterceptorTest.class.getName());
final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
ejbJar.addEnterpriseBean(new StatelessBean(Target2Bean.class));
final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatelessBean(TargetBean.class));
Interceptor interceptor;
interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
{
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", List.class)));
}
{
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", int.class)));
}
{
interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptorViaDD.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
binding.setMethod(new NamedMethod(TargetBean.class.getMethod("echo", boolean.class)));
}
final EnterpriseBean bean3 = ejbJar.addEnterpriseBean(new StatelessBean(Target3Bean.class));
final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean3));
binding.setExcludeDefaultInterceptors(true);
binding.setExcludeClassInterceptors(true);
return new EjbModule(ejbJar);
}
Aggregations