Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.Beans


                } catch (final ClassNotFoundException e) {
                    // no-op
                }
            }

            final Beans beans = ejb.getBeans();
            if (beans != null && ejb.getEjbJar() != null) {
                for (final List<String> managedClasses : beans.getManagedClasses().values()) {
                    for (final String name : managedClasses) {
                        try {
                            finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                        } catch (final ClassNotFoundException e) {
                            // no-op
                        }
                    }
                }
                for (final String name : beans.getInterceptors()) {
                    try {
                        finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                    } catch (final ClassNotFoundException e) {
                        // no-op
                    }
                }
                for (final String name : beans.getAlternativeClasses()) {
                    try {
                        finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                    } catch (final ClassNotFoundException e) {
                        // no-op
                    }
                }
                for (final String name : beans.getDecorators()) {
                    try {
                        finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                    } catch (final ClassNotFoundException e) {
                        // no-op
                    }
View Full Code Here


        return new SingletonBean(OrangeStatefulBean.class);
    }

    @Module
    public Beans getBeans() {
        final Beans beans = new Beans();
        beans.addDecorator(OrangeSecurity.class);
        return beans;
    }
View Full Code Here

        return new StatefulBean(ColorWheel.class);
    }

    @Module
    public Beans getBeans() {
        final Beans beans = new Beans();
//        beans.addManagedClass(ColorWheel.class);
        beans.addManagedClass(Red.class);
        beans.addManagedClass(Orange.class);
        beans.addManagedClass(Yellow.class);
        beans.addManagedClass(Green.class);
        beans.addManagedClass(Blue.class);
        beans.addManagedClass(Violet.class);
        return beans;
    }
View Full Code Here

@RunWith(ApplicationComposer.class)
public class StartupOnCdiBeanTest {
    @Module
    public Beans beans() {
        return new Beans()
                .managedClass(InitMeASAP.class.getName())
                .managedClass(InitMeLater.class.getName());
    }
View Full Code Here

            final IAnnotationFinder finder = ejbModule.getFinder();


            final Map<URL, List<String>> managedClasses;
            {
                final Beans beans = ejbModule.getBeans();

                if (beans != null) {
                    managedClasses = beans.getManagedClasses();
                    managedClasses.putAll(getBeanClasses(finder));

                    // passing jar location to be able to manage maven classes/test-classes which have the same moduleId
                    String id = ejbModule.getModuleId();
                    if (ejbModule.getJarLocation() != null && ejbModule.getJarLocation().contains(ejbModule.getModuleId() + "/target/test-classes".replace("/", File.separator))) {
                        // with maven if both src/main/java and src/test/java are deployed
                        // moduleId.Comp exists twice so it fails
                        // here we simply modify the test comp bean name to avoid it
                        id += "_test";
                    }
                    final String name = BeanContext.Comp.openejbCompName(id);
                    final org.apache.openejb.jee.ManagedBean managedBean = new CompManagedBean(name, BeanContext.Comp.class);
                    managedBean.setTransactionType(TransactionType.BEAN);
                    ejbModule.getEjbJar().addEnterpriseBean(managedBean);

                    if ("true".equals(SystemInstance.get().getProperty("openejb.cdi.support.@Startup", "true"))) {
                        final List<Annotated<Class<?>>> forceStart = finder.findMetaAnnotatedClasses(Startup.class);
                        final List<String> startupBeans = beans.getStartupBeans();
                        for (final Annotated<Class<?>> clazz : forceStart) {
                            startupBeans.add(clazz.get().getName());
                        }
                    }
                } else {
View Full Code Here

        } else if (isEar) { // mainly for CDi TCKs
            final FinderFactory.OpenEJBAnnotationFinder earLibFinder = new FinderFactory.OpenEJBAnnotationFinder(new SimpleWebappAggregatedArchive(earArchive, earMap));
            appModule.setEarLibFinder(earLibFinder);

            final EjbModule earCdiModule = new EjbModule(appModule.getClassLoader(), DeploymentLoader.EAR_SCOPED_CDI_BEANS + appModule.getModuleId(), new EjbJar(), new OpenejbJar());
            earCdiModule.setBeans(new Beans());
            earCdiModule.setFinder(earLibFinder);
            earCdiModule.setEjbJar(new EmptyEjbJar());
            appModule.getEjbModules().add(earCdiModule);

            for (final Map.Entry<ArchivePath, Node> node : archive.getContent(new IncludeRegExpPaths("/.*\\.war")).entrySet()) {
                final Asset asset = node.getValue().getAsset();
                if (ArchiveAsset.class.isInstance(asset)) {
                    final Archive<?> webArchive = ArchiveAsset.class.cast(asset).getArchive();
                    if (WebArchive.class.isInstance(webArchive)) {
                        /* TODO: libs
                        final Map<ArchivePath, Node> libs = archive.getContent(new IncludeRegExpPaths("/WEB-INF/lib/.*\\.jar"));
                        */

                        final Map<String, Object> altDD = new HashMap<String, Object>();
                        final Node beansXml = findBeansXml(webArchive, new ArrayList<AssetSource>(), WEB_INF, altDD);
                        final SWClassLoader webLoader = new SWClassLoader(WEB_INF_CLASSES, parent, webArchive);
                        final FinderFactory.OpenEJBAnnotationFinder finder = new FinderFactory.OpenEJBAnnotationFinder(
                                finderArchive(beansXml, webArchive, webLoader, Collections.<URL>emptyList()));

                        final WebModule webModule = new WebModule(new WebApp(), contextRoot(webArchive.getName()), loader, "", appModule.getModuleId());
                        webModule.setUrls(Collections.<URL>emptyList());
                        webModule.setScannableUrls(Collections.<URL>emptyList());
                        webModule.setFinder(finder);

                        final EjbModule ejbModule = new EjbModule(webLoader, webModule.getModuleId(), null, new EjbJar(), new OpenejbJar());
                        ejbModule.getAltDDs().putAll(altDD);
                        ejbModule.setFinder(finder);
                        ejbModule.setClassLoader(webLoader);
                        ejbModule.setWebapp(true);

                        appModule.getEjbModules().add(ejbModule);
                        appModule.getWebModules().add(webModule);

                        addPersistenceXml(archive, WEB_INF, appModule);
                        addOpenEJbJarXml(archive, WEB_INF, ejbModule);
                        addValidationXml(archive, WEB_INF, new HashMap<String, Object>(), ejbModule);
                        addResourcesXml(archive, WEB_INF, ejbModule);
                        addEnvEntries(archive, WEB_INF, appModule, ejbModule);
                    }
                }
            }
        }

        if (isEar) { // adding the test class as lib class can break test if tested against the web part of the ear
            return appModule;
        }

        // add the test as a managed bean to be able to inject into it easily
        final Map<String, Object> testDD;
        if (javaClass != null) {
            final EjbJar ejbJar = new EjbJar();
            final OpenejbJar openejbJar = new OpenejbJar();
            final String ejbName = appModule.getModuleId() + "_" + javaClass.getName();
            final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(ejbName, javaClass.getName(), true));
            bean.localBean();
            bean.setTransactionType(TransactionType.BEAN);
            final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
            ejbDeployment.setDeploymentId(ejbName);
            final EjbModule e = new EjbModule(ejbJar, openejbJar);
            e.getProperties().setProperty("openejb.cdi.activated", "false");
            e.setBeans(new Beans());
            e.setClassLoader(tempClassLoader);
            appModule.getEjbModules().add(e);
            testDD = e.getAltDDs();
        } else {
            testDD = new HashMap<>(); // ignore
View Full Code Here

        if (jar.getEjbJar().getRelationships() != null) {
            initRelationships(jar, infos);
        }

        final Beans beans = jar.getBeans();
        if (beans != null) {
            ejbJar.beans = new BeansInfo();
            ejbJar.beans.version = beans.getVersion();
            ejbJar.beans.discoveryMode = beans.getBeanDiscoveryMode();
            if (beans.getScan() != null) {
                for (final Beans.Scan.Exclude exclude : beans.getScan().getExclude()) {
                    final ExclusionInfo exclusionInfo = new ExclusionInfo();
                    for (final Object config : exclude.getIfClassAvailableOrIfClassNotAvailableOrIfSystemProperty()) {
                        if (Beans.Scan.Exclude.IfAvailableClassCondition.class.isInstance(config)) {
                            exclusionInfo.availableClasses.add(Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
                        } else if (Beans.Scan.Exclude.IfNotAvailableClassCondition.class.isInstance(config)) {
                            exclusionInfo.notAvailableClasses.add(Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
                        } else if (Beans.Scan.Exclude.IfSystemProperty.class.isInstance(config)) {
                            final Beans.Scan.Exclude.IfSystemProperty systemProperty = Beans.Scan.Exclude.IfSystemProperty.class.cast(config);
                            if (systemProperty.getValue() == null) {
                                exclusionInfo.systemPropertiesPresence.add(systemProperty.getName());
                            } else {
                                exclusionInfo.systemProperties.put(systemProperty.getName(), systemProperty.getValue());
                            }
                        } else {
                            throw new IllegalArgumentException("Not supported: " + config);
                        }
                    }

                    final BeansInfo.ExclusionEntryInfo exclusionEntryInfo = new BeansInfo.ExclusionEntryInfo();
                    exclusionEntryInfo.name = exclude.getName();
                    exclusionEntryInfo.exclusion = exclusionInfo;
                    ejbJar.beans.excludes.add(exclusionEntryInfo);
                }
            }

            ejbJar.beans.interceptors.addAll(beans.getInterceptors());
            ejbJar.beans.decorators.addAll(beans.getDecorators());
            ejbJar.beans.alternativeClasses.addAll(beans.getAlternativeClasses());
            ejbJar.beans.alternativeStereotypes.addAll(beans.getAlternativeStereotypes());

            ejbJar.beans.duplicatedAlternativeClasses.addAll(beans.getDuplicatedAlternatives().getClasses());
            ejbJar.beans.duplicatedAlternativeStereotypes.addAll(beans.getDuplicatedAlternatives().getStereotypes());
            ejbJar.beans.duplicatedInterceptors.addAll(beans.getDuplicatedInterceptors());
            ejbJar.beans.duplicatedDecorators.addAll(beans.getDuplicatedDecorators());

            ejbJar.beans.startupClasses.addAll(beans.getStartupBeans());

            final Map<URL, String> discoveryModeByUrl = new HashMap<>();
            if (CompositeBeans.class.isInstance(beans)) {
                discoveryModeByUrl.putAll(CompositeBeans.class.cast(beans).getDiscoveryByUrl());
            } else {
                discoveryModeByUrl.put(null, beans.getBeanDiscoveryMode());
            }
            for (final Map.Entry<URL, List<String>> next : beans.getManagedClasses().entrySet()) {
                final URL key = next.getKey();

                final BeansInfo.BDAInfo bdaInfo = new BeansInfo.BDAInfo();
                bdaInfo.managedClasses.addAll(next.getValue());
                bdaInfo.discoveryMode = discoveryModeByUrl.get(key);
View Full Code Here

        }
    }

    private static Beans mergeBeansXml(final CompositeBeans current, final URL url) {
        try {
            final Beans beans;
            try {
                beans = ReadDescriptors.readBeans(url.openStream());
            } catch (final IOException e) {
                return current;
            }

            current.getAlternativeClasses().addAll(beans.getAlternativeClasses());
            current.getAlternativeStereotypes().addAll(beans.getAlternativeStereotypes());
            current.getDecorators().addAll(beans.getDecorators());
            current.getInterceptors().addAll(beans.getInterceptors());
            current.getScan().getExclude().addAll(beans.getScan().getExclude());

            // check is done here since later we lost the data of the origin
            ReadDescriptors.checkDuplicatedByBeansXml(beans, current);

            final String beanDiscoveryMode = beans.getBeanDiscoveryMode();
            current.getDiscoveryByUrl().put(url, beanDiscoveryMode == null ? "ALL" : beanDiscoveryMode);
        } catch (final OpenEJBException e) {
            logger.error("Unable to read beans.xml from: " + url.toExternalForm(), e);
        }
        return current;
View Full Code Here

import static org.junit.Assert.assertNull;

public class BeansTest {
    @Test
    public void readEmpty10() throws JAXBException, SAXException, ParserConfigurationException {
        final Beans b = read("<beans xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" +
                "       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
                "       xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd\" />");
        assertNotNull(b);
    }
View Full Code Here

        assertNotNull(b);
    }

    @Test
    public void read10() throws Exception {
        final Beans b = read(
                "<beans\n" +
                "   xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" +
                "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
                "   version=\"1.0\"\n" +
                "   xsi:schemaLocation=\"\n" +
                "      http://java.sun.com/xml/ns/javaee\n" +
                "      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd\">\n" +
                "   <interceptors>\n" +
                "      <class>org.mycompany.myapp.TransactionInterceptor</class>\n" +
                "   </interceptors>\n" +
                "   <alternatives>\n" +
                "         <stereotype>org.mycompany.myapp.Staging</stereotype>\n" +
                "   </alternatives>" +
                "   <decorators>\n" +
                "      <class>org.mycompany.myfwk.TimestampLogger</class>\n" +
                "   </decorators>" +
                "</beans>");
        assertNotNull(b);
        assertEquals(1, b.getInterceptors().size());
        assertEquals("org.mycompany.myapp.TransactionInterceptor", b.getInterceptors().iterator().next());
        assertEquals(0, b.getAlternativeClasses().size());
        assertEquals(1, b.getAlternativeStereotypes().size());
        assertEquals("org.mycompany.myapp.Staging", b.getAlternativeStereotypes().iterator().next());
        assertEquals(1, b.getDecorators().size());
        assertEquals("org.mycompany.myfwk.TimestampLogger", b.getDecorators().iterator().next());
        assertEquals("1.0", b.getVersion());
    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.Beans

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.