Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.ManagedBean


            // Add the test case as an @ManagedBean
            {
                final EjbJar ejbJar = new EjbJar();
                final OpenejbJar openejbJar = new OpenejbJar();
                final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(javaClass.getSimpleName(), javaClass.getName(), true));
                bean.setTransactionType(TransactionType.BEAN);
                final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
                ejbDeployment.setDeploymentId(javaClass.getName());

                appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
            }

            // For the moment we just take the first @Configuration method
            // maybe later we can add something fancy to allow multiple configurations using a qualifier
            // as a sort of altDD/altConfig concept.  Say for example the altDD prefix might be "foo",
            // we can then imagine something like this:
            // @Foo @Configuration public Properties alternateConfig(){...}
            // @Foo @Module  public Properties alternateModule(){...}
            // anyway, one thing at a time ....

            final Properties configuration = new Properties();
            configuration.put(DEPLOYMENTS_CLASSPATH_PROPERTY, "false");

            final EnableServices annotation = testClass.getJavaClass().getAnnotation(EnableServices.class);
            if (annotation != null && annotation.httpDebug()) {
                configuration.setProperty("httpejbd.print", "true");
                configuration.setProperty("httpejbd.indent.xml", "true");
                configuration.setProperty("logging.level.OpenEJB.server.http", "FINE");
            }

            final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Configuration.class);
            for (FrameworkMethod method : methods) {
                final Object o = method.invokeExplosively(testInstance);
                if (o instanceof Properties) {
                    Properties properties = (Properties) o;
                    configuration.putAll(properties);
                }
                break;
            }

            if (SystemInstance.isInitialized()) SystemInstance.reset();

            SystemInstance.init(configuration);

            // save the test under test to be able to retrieve it from extensions
            // /!\ has to be done before all other init
            SystemInstance.get().setComponent(TestInstance.class, new TestInstance(testClass.getJavaClass(), testInstance));

            // call the mock injector before module method to be able to use mocked classes
            // it will often use the TestInstance so
            final List<FrameworkMethod> mockInjectors = testClass.getAnnotatedMethods(MockInjector.class);
            for (FrameworkMethod method : mockInjectors) { // max == 1 so no need to break
                Object o = method.invokeExplosively(testInstance);
                if (o instanceof Class<?>) {
                    o = ((Class<?>) o).newInstance();
                }
                if (o instanceof FallbackPropertyInjector) {
                    SystemInstance.get().setComponent(FallbackPropertyInjector.class, (FallbackPropertyInjector) o);
                }
            }

            for (FrameworkMethod method : testClass.getAnnotatedMethods(Component.class)) {
                Object value = method.invokeExplosively(testInstance);
                if (value instanceof Class<?>) {
                    value = ((Class<?>) value).newInstance();
                }

                Class<?> key = method.getMethod().getReturnType();

                if (!key.isInstance(value)) { // we can't do it in validate to avoid to instantiate the value twice
                    throw new OpenEJBRuntimeException(value + " is not an instance of " + key.getName());
                }

                SystemInstance.get().setComponent((Class<Object>) key, value);
            }

            final Map<String, URL> additionalDescriptors = descriptorsToMap(testClass.getJavaClass().getAnnotation(Descriptors.class));

            Application application = null;

            int webModulesNb = 0;

            // Invoke the @Module producer methods to build out the AppModule
            for (FrameworkMethod method : testClass.getAnnotatedMethods(Module.class)) {

                final Object obj = method.invokeExplosively(testInstance);
                final Classes classesAnnotation = method.getAnnotation(Classes.class);

                if (obj instanceof WebApp) { // will add the ejbmodule too
                    webModulesNb++;

                    final WebApp webapp = (WebApp) obj;
                    String root = webapp.getContextRoot();
                    if (root == null) {
                        root = "/openejb";
                    }

                    final WebModule webModule = new WebModule(webapp, root, Thread.currentThread().getContextClassLoader(), "", root);

                    webModule.getAltDDs().putAll(additionalDescriptors);
                    webModule.getAltDDs().putAll(descriptorsToMap(method.getAnnotation(Descriptors.class)));

                    if (classesAnnotation != null) {
                        webModule.setFinder(finderFromClasses(classesAnnotation.value()));
                    }
                    DeploymentLoader.addWebModule(webModule, appModule);
                } else if (obj instanceof WebModule) { // will add the ejbmodule too
                    webModulesNb++;

                    final WebModule webModule = (WebModule) obj;

                    webModule.getAltDDs().putAll(additionalDescriptors);
                    webModule.getAltDDs().putAll(descriptorsToMap(method.getAnnotation(Descriptors.class)));

                    if (classesAnnotation != null) {
                        webModule.setFinder(finderFromClasses(classesAnnotation.value()));
                    }
                    DeploymentLoader.addWebModule(webModule, appModule);
                } else if (obj instanceof EjbModule) {
                    final EjbModule ejbModule = (EjbModule) obj;

                    ejbModule.getAltDDs().putAll(additionalDescriptors);
                    ejbModule.getAltDDs().putAll(descriptorsToMap(method.getAnnotation(Descriptors.class)));

                    if (classesAnnotation != null) {
                        ejbModule.setFinder(finderFromClasses(classesAnnotation.value()));
                    }
                    ejbModule.initAppModule(appModule);
                    appModule.getEjbModules().add(ejbModule);
                } else if (obj instanceof EjbJar) {

                    final EjbJar ejbJar = (EjbJar) obj;
                    setId(ejbJar, method);

                    final EjbModule ejbModule = new EjbModule(ejbJar);

                    ejbModule.getAltDDs().putAll(additionalDescriptors);
                    ejbModule.getAltDDs().putAll(descriptorsToMap(method.getAnnotation(Descriptors.class)));

                    appModule.getEjbModules().add(ejbModule);
                    if (classesAnnotation != null) {
                        ejbModule.setFinder(finderFromClasses(classesAnnotation.value()));
                    }
                } else if (obj instanceof EnterpriseBean) {

                    final EnterpriseBean bean = (EnterpriseBean) obj;
                    final EjbJar ejbJar = new EjbJar(method.getName());
                    ejbJar.addEnterpriseBean(bean);
                    EjbModule ejbModule = new EjbModule(ejbJar);
                    Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(bean.getEjbClass());
                    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(clazz)).link());
                    appModule.getEjbModules().add(ejbModule);

                } else if (obj instanceof Application) {
View Full Code Here


        // add the test as a managed bean to be able to inject into it easily
        {
            final EjbJar ejbJar = new EjbJar();
            final OpenejbJar openejbJar = new OpenejbJar();
            final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(javaClass.getSimpleName(), javaClass.getName(), true));
            bean.setTransactionType(TransactionType.BEAN);
            final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
            ejbDeployment.setDeploymentId(javaClass.getName());
            appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
        }
View Full Code Here

TOP

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

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.