Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.AssemblyDescriptor$JAXB


     */
    private void resolveDestinationLinks(final AppModule appModule) throws OpenEJBException {
        // build up a link resolver
        final LinkResolver<MessageDestination> destinationResolver = new LinkResolver<MessageDestination>();
        for (final EjbModule ejbModule : appModule.getEjbModules()) {
            final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
            if (assembly != null) {
                for (final MessageDestination destination : assembly.getMessageDestination()) {
                    destinationResolver.add(ejbModule.getModuleUri(), destination.getMessageDestinationName(), destination);
                }
            }
        }
        for (final ClientModule clientModule : appModule.getClientModules()) {
            for (final MessageDestination destination : clientModule.getApplicationClient().getMessageDestination()) {
                destinationResolver.add(appModule.getModuleUri(), destination.getMessageDestinationName(), destination);
            }
        }
        for (final WebModule webModule : appModule.getWebModules()) {
            for (final MessageDestination destination : webModule.getWebApp().getMessageDestination()) {
                destinationResolver.add(appModule.getModuleUri(), destination.getMessageDestinationName(), destination);
            }
        }

        // remember the type of each destination so we can use it to fillin MDBs that don't declare destination type
        final Map<MessageDestination, String> destinationTypes = new HashMap<MessageDestination, String>();

        // resolve all MDBs with destination links
        // if MessageDestination does not have a mapped name assigned, give it the destination from the MDB
        for (final EjbModule ejbModule : appModule.getEjbModules()) {
            final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
            if (assembly == null) {
                continue;
            }

            final URI moduleUri = ejbModule.getModuleUri();
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();

            for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
                // MDB destination is deploymentId if none set
                if (bean instanceof MessageDrivenBean) {
                    final MessageDrivenBean mdb = (MessageDrivenBean) bean;

                    final EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
                    if (ejbDeployment == null) {
                        throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
                    }

                    // skip destination refs without a destination link
                    final String link = mdb.getMessageDestinationLink();
                    if (link == null || link.length() == 0) {
                        continue;
                    }

                    // resolve the destination... if we don't find one it is a configuration bug
                    final MessageDestination destination = destinationResolver.resolveLink(link, moduleUri);
                    if (destination == null) {
                        throw new OpenEJBException("Message destination " + link + " for message driven bean " + mdb.getEjbName() + " not found");
                    }

                    // get the destinationId is the mapped name
                    String destinationId = destination.getMappedName();
                    if (destinationId == null) {
                        // if we don't have a mapped name use the destination of the mdb
                        final Properties properties = mdb.getActivationConfig().toProperties();
                        destinationId = properties.getProperty("destination");
                        destination.setMappedName(destinationId);
                    }

                    if (mdb.getMessageDestinationType() != null && !destinationTypes.containsKey(destination)) {
                        destinationTypes.put(destination, mdb.getMessageDestinationType());
                    }

                    // destination identifier
                    ResourceLink resourceLink = ejbDeployment.getResourceLink("openejb/destination");
                    if (resourceLink == null) {
                        resourceLink = new ResourceLink();
                        resourceLink.setResRefName("openejb/destination");
                        ejbDeployment.addResourceLink(resourceLink);
                    }
                    resourceLink.setResId(destinationId);
                }
            }
        }

        // resolve all message destination refs with links and assign a ref id to the reference
        for (final EjbModule ejbModule : appModule.getEjbModules()) {
            final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
            if (assembly == null) {
                continue;
            }

            final URI moduleUri = ejbModule.getModuleUri();
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();

            for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
                final EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
                if (ejbDeployment == null) {
                    throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
                }

                for (final MessageDestinationRef ref : bean.getMessageDestinationRef()) {
                    // skip destination refs with a resource link already assigned
                    if (ref.getMappedName() == null && ejbDeployment.getResourceLink(ref.getName()) == null) {
                        final String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
                        if (destinationId != null) {
                            // build the link and add it
                            final ResourceLink resourceLink = new ResourceLink();
                            resourceLink.setResId(destinationId);
                            resourceLink.setResRefName(ref.getName());
                            ejbDeployment.addResourceLink(resourceLink);
                        }

                    }
                }
            }
        }

        for (final ClientModule clientModule : appModule.getClientModules()) {
            final URI moduleUri = clientModule.getModuleUri();
            for (final MessageDestinationRef ref : clientModule.getApplicationClient().getMessageDestinationRef()) {
                final String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
                if (destinationId != null) {
                    // for client modules we put the destinationId in the mapped name
                    ref.setMappedName(destinationId);
                }
            }
        }

        for (final WebModule webModule : appModule.getWebModules()) {
            final URI moduleUri = URLs.uri(webModule.getModuleId());
            for (final MessageDestinationRef ref : webModule.getWebApp().getMessageDestinationRef()) {
                final String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
                if (destinationId != null) {
                    // for web modules we put the destinationId in the mapped name
                    ref.setMappedName(destinationId);
                }
            }
        }

        // Process MDBs one more time...
        // this time fill in the destination type (if not alreday specified) with
        // the info from the destination (which got filled in from the references)
        for (final EjbModule ejbModule : appModule.getEjbModules()) {
            final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
            if (assembly == null) {
                continue;
            }

            final URI moduleUri = URLs.uri(ejbModule.getModuleId());
View Full Code Here


public class CheckAssemblyBindings extends ValidationBase {
    public void validate(final EjbModule ejbModule) {
        checkUnusedInterceptors(ejbModule);
        final Map<String, EnterpriseBean> ejbsByName = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();

        final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();

        if (assembly == null) {
            return;
        }

        for (final InterceptorBinding binding : assembly.getInterceptorBinding()) {
            final List<String> interceptorClasses = binding.getInterceptorClass();
            if (binding.getInterceptorOrder() != null) {
                interceptorClasses.addAll(binding.getInterceptorOrder().getInterceptorClass());
            }

            if (binding.getEjbName() != null && !binding.getEjbName().equals("*") && !ejbsByName.containsKey(binding.getEjbName())) {
                fail("InterceptorBinding", "interceptorBinding.noSuchEjbName", binding.getEjbName(), join(",", interceptorClasses));
            }

            if (binding.getMethod() != null) {
                if (binding.getEjbName() == null) {
                    fail("InterceptorBinding", "interceptorBinding.ejbNameRequiredWithMethod", binding.getMethod().getMethodName(), join(",", interceptorClasses));
                }
            }
        }

        for (final MethodPermission permission : assembly.getMethodPermission()) {
            for (final Method method : permission.getMethod()) {
                if (method.getEjbName() == null) {
                    fail("MethodPermission", "methodPermission.ejbNameRequired", method.getMethodName(), join(",", permission.getRoleName()));
                } else if (method.getEjbName().equals("*")) { //NOPMD
                    // no-op. Just continue the loop.
                } else if (!ejbsByName.containsKey(method.getEjbName())) {
                    fail("MethodPermission", "methodPermission.noSuchEjbName", method.getEjbName(), method.getMethodName(), join(",", permission.getRoleName()));
                }
            }
        }

        for (final ContainerTransaction transaction : assembly.getContainerTransaction()) {
            for (final Method method : transaction.getMethod()) {
                if (method.getEjbName() == null) {
                    fail("ContainerTransaction", "containerTransaction.ejbNameRequired", method.getMethodName(), transaction.getTransAttribute());
                } else if (method.getEjbName().equals("*")) { //NOPMD
                    // no-op. Just continue the loop.
View Full Code Here

            }
        }
    }

    private void checkUnusedInterceptors(final EjbModule ejbModule) {
        final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
        final Interceptor[] interceptorsArray = ejbModule.getEjbJar().getInterceptors();
        final List<Interceptor> interceptors = Arrays.asList(interceptorsArray);
        final Set<String> interceptorClassNames = new HashSet<String>(interceptors.size());
        for (final Interceptor interceptor : interceptors) {
            interceptorClassNames.add(interceptor.getInterceptorClass());
        }
        final Set<String> interceptorClassNamesUsedInBindings = new HashSet<String>();
        for (final InterceptorBinding binding : assembly.getInterceptorBinding()) {
            final List<String> interceptorClass = binding.getInterceptorClass();
            interceptorClassNamesUsedInBindings.addAll(interceptorClass);
        }
        final Set<String> unusedInterceptors = new HashSet<String>();
        for (final String clazz : interceptorClassNames) {
View Full Code Here

        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();

        //Configure AroundTimeout by deployment plan
        final Interceptor interceptorA = new Interceptor(SimpleInterceptorA.class);
        interceptorA.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(SimpleInterceptorA.class.getName(), "interceptorTimeoutAround"));
        ejbJar.addInterceptor(interceptorA);

        //Configure AroundTimeout by annotation
        final Interceptor interceptorB = new Interceptor(SimpleInterceptorB.class);
        ejbJar.addInterceptor(interceptorB);

        //Override AroundTimeout annotation by deployment plan
        final Interceptor interceptorC = new Interceptor(SimpleInterceptorC.class);
        interceptorC.getAroundTimeout().add(new org.apache.openejb.jee.AroundTimeout(SimpleInterceptorC.class.getName(), "interceptorTimeoutAround"));
        ejbJar.addInterceptor(interceptorC);

        //Configure aroundTimeout by deployment plan
        final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
        subBeanA.addAroundTimeout("beanTimeoutAround");
        ejbJar.addEnterpriseBean(subBeanA);
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorA));
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorB));
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanA, interceptorC));

        //Configure aroundTimeout by annotation
        final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
        ejbJar.addEnterpriseBean(subBeanB);
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorA));
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorB));
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanB, interceptorC));

        //Override aroundTimeout annotation by deployment plan
        final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
        subBeanC.addAroundTimeout("beanTimeoutAround");
        ejbJar.addEnterpriseBean(subBeanC);
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorA));
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorB));
        assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(subBeanC, interceptorC));

        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
        assembler.createApplication(ejbJarInfo);
        final InitialContext context = new InitialContext();
View Full Code Here

    public EjbJar module() {
        final EjbJar ejbJar = new EjbJar();

        final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(ThirdSLSBean.class));

        final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();

        assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
        assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));

        return ejbJar;
    }
View Full Code Here

    public EjbJar module() {
        final EjbJar ejbJar = new EjbJar();

        final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SecondStatelessInterceptedBean.class));

        final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();

        assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
        assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
        assembly.addInterceptorBinding(new InterceptorBinding(bean)).setExcludeDefaultInterceptors(true);

        return ejbJar;
    }
View Full Code Here

    public void applicationExceptionInheritanceTest() throws Exception {
        EjbModule ejbModule = testModule();
        final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans();
        ejbModule = discvrAnnBeans.deploy(ejbModule);

        final AssemblyDescriptor assemblyDescriptor = ejbModule.getEjbJar().getAssemblyDescriptor();
        org.apache.openejb.jee.ApplicationException appEx =
            assemblyDescriptor.getApplicationException(BusinessException.class);
        assertThat(appEx, notNullValue());
        assertThat(appEx.getExceptionClass(), is(BusinessException.class.getName()));
        assertThat(appEx.isRollback(), is(true));

        //inheritance is now handled at runtime, only explicitly mentioned exceptions are in the assembly descriptor
        appEx = assemblyDescriptor.getApplicationException(ValueRequiredException.class);
        assertThat(appEx, nullValue());
    }
View Full Code Here

        addStatefulBean(ejbJar, TransactionContextBean.class, "TransactionToExtended", "Extendedx5");

        addStatelessBean(ejbJar, TransactionContextBean.class, "StatelessTransactionToExtended", "Extendedx5");
        ejbJar.addEnterpriseBean(new StatefulBean("Transactionx6", EndNodeBean.class));

        ejbJar.setAssemblyDescriptor(new AssemblyDescriptor());
        ejbJar.getAssemblyDescriptor().addApplicationException(IllegalArgumentException.class, false, true);
        ejbJar.getAssemblyDescriptor().addApplicationException(ArgumentException.class, false, true);

//        List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
View Full Code Here

    public EjbJar module() {
        final EjbJar ejbJar = new EjbJar();

        final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(FullyInterceptedBean.class));

        final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();

        assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
        assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));

        final InterceptorBinding b = assembly.addInterceptorBinding(new InterceptorBinding(bean));
        b.setExcludeDefaultInterceptors(true);
        b.setMethod(new NamedMethod("methodWithDefaultInterceptorsExcluded"));

        return ejbJar;
    }
View Full Code Here

        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);
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.AssemblyDescriptor$JAXB

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.