Search in sources :

Example 1 with EjbDescriptor

use of org.jboss.weld.ejb.spi.EjbDescriptor in project core by weld.

the class SubclassedComponentDescriptorTest method prepareContainer.

@BeforeClass
public void prepareContainer() {
    final EjbDescriptor<Foo> fooDescriptor = new EjbDescriptorImpl<Foo>(Foo.class, Foo.class, EnhancedFoo.class, SessionBeanType.STATEFUL);
    final EjbDescriptor<Bar> barDescriptor = new EjbDescriptorImpl<Bar>(Bar.class, BarLocal.class, EnhancedBar.class, SessionBeanType.STATEFUL);
    final EjbDescriptor<Baz> bazDescriptor = new EjbDescriptorImpl<Baz>(Baz.class, Baz.class, EnhancedBaz.class, null);
    final BeanDeploymentArchive bda = new BeanDeploymentArchiveImpl("1", Foo.class, Bar.class, BarLocal.class, BarDecorator.class, BarInterceptor.class, BarInterceptorBinding.class, Baz.class) {

        @Override
        public Collection<EjbDescriptor<?>> getEjbs() {
            return ImmutableSet.<EjbDescriptor<?>>of(fooDescriptor, barDescriptor, bazDescriptor);
        }
    };
    final Deployment deployment = new FlatDeployment(bda) {

        @Override
        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            return bda;
        }

        @Override
        protected void configureServices(Environment environment) {
            super.configureServices(environment);
            getServices().add(EjbServices.class, new MockEjbServices());
        }
    };
    container = new TestContainer(deployment).startContainer();
    manager = (BeanManagerImpl) container.getBeanManager(bda);
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) EjbDescriptor(org.jboss.weld.ejb.spi.EjbDescriptor) MockEjbServices(org.jboss.weld.mock.MockEjbServices) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) Environment(org.jboss.weld.bootstrap.api.Environment) AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with EjbDescriptor

use of org.jboss.weld.ejb.spi.EjbDescriptor in project Payara by payara.

the class EjbServicesImpl method registerInterceptors.

@Override
public void registerInterceptors(EjbDescriptor<?> ejbDesc, InterceptorBindings interceptorBindings) {
    com.sun.enterprise.deployment.EjbDescriptor glassfishEjbDesc = (com.sun.enterprise.deployment.EjbDescriptor) ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor();
    // First create master list of EjbInterceptor descriptors
    for (Interceptor<?> next : interceptorBindings.getAllInterceptors()) {
        if (logger.isLoggable(FINE)) {
            logger.log(FINE, TRYING_TO_REGISTER_INTERCEPTOR, new Object[] { next });
        }
        // Add interceptor to list all interceptors in ejb descriptor
        if (!(glassfishEjbDesc.hasInterceptorClass(next.getBeanClass().getName()))) {
            if (logger.isLoggable(FINE)) {
                logger.log(FINE, ADDING_INTERCEPTOR_FOR_EJB, new Object[] { next.getBeanClass().getName(), glassfishEjbDesc.getEjbClassName() });
            }
            EjbInterceptor ejbInt = makeEjbInterceptor(next, glassfishEjbDesc.getEjbBundleDescriptor());
            ejbInt.setInterceptorClass(next.getBeanClass());
            glassfishEjbDesc.addInterceptorClass(ejbInt);
        }
    }
    // Create ordered list of EjbInterceptor for each lifecycle interception type and append to
    // EjbDescriptor.
    // JSR 299 (CDI) interceptors are always added after any interceptors defined via
    // EJB-defined metadata, so the ordering will be correct since all the ejb interceptors
    // have already been processed.
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(AROUND_CONSTRUCT, interceptorBindings.getLifecycleInterceptors(AROUND_CONSTRUCT), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(POST_CONSTRUCT, interceptorBindings.getLifecycleInterceptors(POST_CONSTRUCT), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(PRE_DESTROY, interceptorBindings.getLifecycleInterceptors(PRE_DESTROY), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(PRE_PASSIVATE, interceptorBindings.getLifecycleInterceptors(PRE_PASSIVATE), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(POST_ACTIVATE, interceptorBindings.getLifecycleInterceptors(POST_ACTIVATE), glassfishEjbDesc));
    // JSR 299-provided list is organized as per-method.  Append each method chain to EjbDescriptor.
    Class<?> ejbBeanClass = null;
    try {
        ClassLoader cl = glassfishEjbDesc.getEjbBundleDescriptor().getClassLoader();
        ejbBeanClass = cl.loadClass(glassfishEjbDesc.getEjbClassName());
    } catch (ClassNotFoundException cnfe) {
        throw new IllegalStateException("Cannot load bean class " + glassfishEjbDesc.getEjbClassName(), cnfe);
    }
    Class<?> ejbBeanSuperClass = ejbBeanClass;
    while (!ejbBeanSuperClass.equals(java.lang.Object.class)) {
        for (Method m : ejbBeanSuperClass.getDeclaredMethods()) {
            if (!methodOverridden(ejbBeanClass, m)) {
                List<EjbInterceptor> aroundInvokeChain = makeInterceptorChain(InterceptionType.AROUND_INVOKE, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, m), glassfishEjbDesc);
                glassfishEjbDesc.addMethodLevelChain(aroundInvokeChain, m, true);
                List<EjbInterceptor> aroundTimeoutChain = makeInterceptorChain(InterceptionType.AROUND_TIMEOUT, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, m), glassfishEjbDesc);
                glassfishEjbDesc.addMethodLevelChain(aroundTimeoutChain, m, false);
            }
        }
        ejbBeanSuperClass = ejbBeanSuperClass.getSuperclass();
    }
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) Method(java.lang.reflect.Method) EjbDescriptor(org.jboss.weld.ejb.spi.EjbDescriptor)

Aggregations

EjbDescriptor (org.jboss.weld.ejb.spi.EjbDescriptor)2 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)1 Method (java.lang.reflect.Method)1 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)1 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)1 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)1 Environment (org.jboss.weld.bootstrap.api.Environment)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 Deployment (org.jboss.weld.bootstrap.spi.Deployment)1 MockEjbServices (org.jboss.weld.mock.MockEjbServices)1 AfterClass (org.testng.annotations.AfterClass)1 BeforeClass (org.testng.annotations.BeforeClass)1