Package org.apache.openejb.config

Examples of org.apache.openejb.config.AppModule


        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

        EjbJar ejbJar = new EjbJar();
        EjbModule ejbModule = new EjbModule(ejbJar);

        appModule = new AppModule(ejbModule.getClassLoader(), "mbeans");
        appModule.getEjbModules().add(ejbModule);
        assembler.createApplication(config.configureApplication(appModule));
    }
View Full Code Here


        }
        if (properties == null) {
            properties = new Properties();
        }

        AppModule appModule = null;
        try {
            File file = new File(location);
            appModule = deploymentLoader.load(file);

            // Add any alternate deployment descriptors to the modules
            Map<String, DeploymentModule> modules = new TreeMap<String, DeploymentModule>();
            for (DeploymentModule module : appModule.getEjbModules()) {
                modules.put(module.getModuleId(), module);
            }
            for (DeploymentModule module : appModule.getClientModules()) {
                modules.put(module.getModuleId(), module);
            }
            for (DeploymentModule module : appModule.getWebModules()) {
                modules.put(module.getModuleId(), module);
            }
            for (DeploymentModule module : appModule.getConnectorModules()) {
                modules.put(module.getModuleId(), module);
            }

            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                String name = (String) entry.getKey();
                if (name.startsWith(ALT_DD + "/")) {
                    name = name.substring(ALT_DD.length() + 1);

                    DeploymentModule module;
                    int slash = name.indexOf('/');
                    if (slash > 0) {
                        String moduleId = name.substring(0, slash);
                        name = name.substring(slash + 1);
                        module = modules.get(moduleId);
                    } else {
                        module = appModule;
                    }

                    if (module != null) {
                        String value = (String) entry.getValue();
                        File dd = new File(value);
                        if (dd.canRead()) {
                            module.getAltDDs().put(name, dd.toURI().toURL());
                        } else {
                            module.getAltDDs().put(name, value);
                        }
                    }
                }
            }

            AppInfo appInfo = configurationFactory.configureApplication(appModule);
            if (properties != null && properties.containsKey(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP)) {
                appInfo.appId = properties.getProperty(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP);
            }
            assembler.createApplication(appInfo);

            return appInfo;
        } catch (Throwable e) {
            // destroy the class loader for the failed application
            if (appModule != null) {
                ClassLoaderUtil.destroyClassLoader(appModule.getJarLocation());
            }

            e.printStackTrace();

            if (e instanceof javax.validation.ValidationException) {
View Full Code Here

        @Override
        public void evaluate() throws Throwable {
            final Class<?> javaClass = testClass.getJavaClass();
            final ClassLoader loader = javaClass.getClassLoader();
            AppModule appModule = new AppModule(loader, javaClass.getSimpleName());

            // 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));
            }

            Application application = null;

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

                final Object obj = method.invokeExplosively(testInstance);

                if (obj instanceof EjbJar) {

                    final EjbJar ejbJar = (EjbJar) obj;
                    setId(ejbJar, method);
                    appModule.getEjbModules().add(new EjbModule(ejbJar));

                } 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) {

                    application = (Application) obj;
                    setId(application, method);

                } else if (obj instanceof Connector) {

                    final Connector connector = (Connector) obj;
                    setId(connector, method);
                    appModule.getConnectorModules().add(new ConnectorModule(connector));

                } else if (obj instanceof Persistence) {

                    final Persistence persistence = (Persistence) obj;
                    appModule.getPersistenceModules().add(new PersistenceModule("", persistence));

                } else if (obj instanceof PersistenceUnit) {

                    final PersistenceUnit unit = (PersistenceUnit) obj;
                    appModule.getPersistenceModules().add(new PersistenceModule("", new Persistence(unit)));

                } else if (obj instanceof Beans) {

                    final Beans beans = (Beans) obj;
                    final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
                    ejbModule.setBeans(beans);
                    appModule.getEjbModules().add(ejbModule);

                } else if (obj instanceof Class[]) {

                    final Class[] beans = (Class[]) obj;
                    final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
                    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(beans)).link());
                    ejbModule.setBeans(new Beans());
                    appModule.getEjbModules().add(ejbModule);
                } else if (obj instanceof Class) {

                    final Class bean = (Class) obj;
                    final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
                    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(bean)).link());
                    ejbModule.setBeans(new Beans());
                    appModule.getEjbModules().add(ejbModule);
                }
            }

            // Application is final in AppModule, which is fine, so we'll create a new one and move everything
            if (application != null) {
                final AppModule newModule = new AppModule(appModule.getClassLoader(), appModule.getModuleId(), application, false);
                newModule.getClientModules().addAll(appModule.getClientModules());
                newModule.getPersistenceModules().addAll(appModule.getPersistenceModules());
                newModule.getEjbModules().addAll(appModule.getEjbModules());
                newModule.getConnectorModules().addAll(appModule.getConnectorModules());
                appModule = newModule;
            }

            // For the moment we just take the first @Configuration method
            // maybe later we can add something fancy to allow multiple configurations using a qualifier
View Full Code Here

        EjbJar ejbJar = ejbjar(beans);
        ear(ejbJar);
    }

    private void ear(EjbJar... ejbJars) throws OpenEJBException, NamingException, IOException {
        AppModule app = new AppModule(this.getClass().getClassLoader(), "classpath-"+ejbJars.hashCode());
        for (EjbJar ejbJar : ejbJars) {
            app.getEjbModules().add(new EjbModule(ejbJar));
        }
        assembler.createApplication(config.configureApplication(app));
    }
View Full Code Here

                        LOGGER.warn("can't find bundle {}", bundle.getBundleId());
                        return;
                    }

                    LOGGER.info("looking bundle {} in {}", bundle.getBundleId(), bundleDump);
                    final AppModule appModule = new OSGiDeploymentLoader(bundle).load(bundleDump);
                    LOGGER.info("deploying bundle #" + bundle.getBundleId() + " as an EJBModule");

                    final ConfigurationFactory configurationFactory = new ConfigurationFactory();
                    final AppInfo appInfo = configurationFactory.configureApplication(appModule);
                    appInfo.appId = "bundle_" + bundle.getBundleId();
View Full Code Here

        if (targetPath == null) throw new NullPointerException("targetPath is null");
        if (targetPath.endsWith("/")) throw new IllegalArgumentException("targetPath must not end with a '/'");

        // Load the module file
        DeploymentLoader loader = new DeploymentLoader();
        AppModule appModule = null;
        try {
            appModule = loader.load(new File(moduleFile.getName()));
        } catch (UnknownModuleTypeException e){
            return null;
        } catch (UnsupportedModuleTypeException e){
            return null;
        } catch (OpenEJBException e) {
            Throwable t = e.getCause();
            if (t instanceof UnknownModuleTypeException || t instanceof UnsupportedModuleTypeException) {
                return null;
            }
            throw new DeploymentException(e);
        }

        // did we find a ejb jar?
        if (appModule.getEjbModules().size() == 0) {
            return null;
        }

        // get the module
        org.apache.openejb.config.EjbModule ejbModule = appModule.getEjbModules().get(0);

        // add the ejb-jar.xml altDD plan
        if (specDDUrl != null) {
            ejbModule.getAltDDs().put("ejb-jar.xml", specDDUrl);
        }
View Full Code Here

            // temporary classloader is used for processing ejb annotations and byte code manipulation during ejb load
            TemporaryClassLoader temporaryClassLoader = new TemporaryClassLoader(new URL[0], classLoader);

            // create an openejb app module for the ear containing all ejb modules
            AppModule appModule = new AppModule(classLoader, ejbModule.getEjbModule().getModuleId());
            for (EjbModule module : earData.getEjbModuels()) {
                module.setClassLoader(temporaryClassLoader);
                appModule.getEjbModules().add(module.getEjbModule());
            }

            // build the config info tree
            // this method fills in the ejbJar jaxb tree based on the annotations
            // (metadata complete) and it run the openejb verifier
            AppInfo appInfo;
            try {
                appInfo = openEjbSystem.configureApplication(appModule);
            } catch (ValidationFailedException set) {
                StringBuilder sb = new StringBuilder();
                sb.append("Jar failed validation: "+appModule.getModuleId());

                for (ValidationError e : set.getErrors()) {
                    sb.append(e.getPrefix() + " ... " + e.getComponentName() + ":\t" + e.getMessage(2));
                }
View Full Code Here

*/
public class JavaEEModuleHelper {

    public AppModule getMetadataCompleteModules(String jarFilePath) throws ContributionReadException {
        DeploymentLoader loader = new DeploymentLoader();
        AppModule appModule = null;
        try {
            appModule = loader.load(new File(jarFilePath));
        } catch (OpenEJBException e) {
            throw new ContributionReadException(e);
        }
View Full Code Here

        } catch (IOException e) {
            throw new ContributionReadException(e);
        }

        JavaEEModuleHelper jmh = new JavaEEModuleHelper();
        AppModule appModule = jmh.getMetadataCompleteModules(tempFile.getAbsolutePath());
        if(!tempFile.delete()) {
            tempFile.deleteOnExit();
        }
        return createJavaEEApplicationInfo(appModule);
    }
View Full Code Here

      //We build our own because we can't trust anyone to get the classpath right otherwise!
      module.setFinder(new IDirectoryFinder(AnnotationDeployer.class.getClassLoader(),
          getClassPathLocations(manifest, bundle)));
     
      //Scan our app for annotated EJBs
      AppModule app = new AppModule(module);
      new AnnotationDeployer().deploy(app);
     
      //Register our session beans
      for(EnterpriseBean eb : ejbJar.getEnterpriseBeans()) {
       
View Full Code Here

TOP

Related Classes of org.apache.openejb.config.AppModule

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.