ConfigurationFactory implements OpenEjbConfigurationFactory { @Override public OpenEjbConfiguration getOpenEjbConfiguration() throws OpenEJBException { if (sys != null) { return sys; } if (configLocation != null) { openejb = JaxbOpenejb.readConfig(configLocation); } else { openejb = JaxbOpenejb.createOpenejb(); } loadPropertiesDeclaredConfiguration(openejb); sys = new OpenEjbConfiguration(); sys.containerSystem = new ContainerSystemInfo(); sys.facilities = new FacilitiesInfo(); for (final Service service : openejb.getServices()) { final ServiceInfo info = configureService(service, ServiceInfo.class); sys.facilities.services.add(info); } for (final JndiProvider provider : openejb.getJndiProvider()) { final JndiContextInfo info = configureService(provider, JndiContextInfo.class); sys.facilities.remoteJndiContexts.add(info); } sys.facilities.securityService = configureService(openejb.getSecurityService(), SecurityServiceInfo.class); sys.facilities.transactionService = configureService(openejb.getTransactionManager(), TransactionServiceInfo.class); final List<ResourceInfo> resources = new ArrayList<ResourceInfo>(); for (final Resource resource : openejb.getResource()) { final ResourceInfo resourceInfo = configureService(resource, ResourceInfo.class); resources.add(resourceInfo); } Collections.sort(resources, new ResourceInfoComparator(resources)); sys.facilities.resources.addAll(resources); if (openejb.getProxyFactory() != null) { sys.facilities.intraVmServer = configureService(openejb.getProxyFactory(), ProxyFactoryInfo.class); } for (final Container declaration : openejb.getContainer()) { final ContainerInfo info = createContainerInfo(declaration); sys.containerSystem.containers.add(info); } final List<File> declaredApps = getDeclaredApps(); for (final File jarFile : declaredApps) { try { final AppInfo appInfo = configureApplication(jarFile); sys.containerSystem.applications.add(appInfo); } catch (OpenEJBException alreadyHandled) { final DeploymentExceptionManager exceptionManager = SystemInstance.get().getComponent(DeploymentExceptionManager.class); exceptionManager.pushDelpoymentException(alreadyHandled); } } final boolean embedded = SystemInstance.get().hasProperty(EJBContainer.class.getName()); final Options options = SystemInstance.get().getOptions(); if (options.get("openejb.system.apps", false)) { try { final AppInfo appInfo = configureApplication(new AppModule(SystemApps.getSystemModule())); sys.containerSystem.applications.add(appInfo); } catch (OpenEJBException e) { logger.error("Unable to load the system applications.", e); } } else if (options.get(DEPLOYMENTS_CLASSPATH_PROPERTY, !embedded)) { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final ArrayList<File> jarFiles = getModulesFromClassPath(declaredApps, classLoader); final String appId = "classpath.ear"; final boolean classpathAsEar = options.get(CLASSPATH_AS_EAR, true); try { if (classpathAsEar && !jarFiles.isEmpty()) { final AppInfo appInfo = configureApplication(classLoader, appId, jarFiles); sys.containerSystem.applications.add(appInfo); } else for (final File jarFile : jarFiles) { final AppInfo appInfo = configureApplication(jarFile); sys.containerSystem.applications.add(appInfo); } if (jarFiles.size() == 0) { logger.warning("config.noModulesFoundToDeploy"); } } catch (OpenEJBException alreadyHandled) { logger.debug("config.alreadyHandled"); } } for (final Deployments deployments : openejb.getDeployments()) { if (deployments.isAutoDeploy()) { if (deployments.getDir() != null) { sys.containerSystem.autoDeploy.add(deployments.getDir()); } } } final OpenEjbConfiguration finished = sys; sys = null; openejb = null; return finished; } ConfigurationFactory();  ConfigurationFactory(final boolean offline);  ConfigurationFactory(final boolean offline, final DynamicDeployer preAutoConfigDeployer);  ConfigurationFactory(final boolean offline, final OpenEjbConfiguration configuration);  ConfigurationFactory(final boolean offline,
                                final DynamicDeployer preAutoConfigDeployer,
                                final OpenEjbConfiguration configuration);  ConfigurationFactory(final boolean offline, final Chain deployerChain, final OpenEjbConfiguration configuration); static List<HandlerChainInfo> toHandlerChainInfo(final HandlerChains chains); @Override void init(final Properties props); @Override OpenEjbConfiguration getOpenEjbConfiguration(); ArrayList<File> getModulesFromClassPath(final List<File> declaredApps, final ClassLoader classLoader); ContainerInfo createContainerInfo(final Container container); Object toConfigDeclaration(final String id, final URI uri); AppInfo configureApplication(final File jarFile); AppInfo configureApplication(final ClassLoader classLoader, final String id, final List<File> jarFiles); @SuppressWarnings("unchecked") AppModule loadApplication(final ClassLoader classLoader, String id, final List<File> jarFiles); EjbJarInfo configureApplication(final EjbJar ejbJar); EjbJarInfo configureApplication(final EjbModule ejbModule); ClientInfo configureApplication(final ClientModule clientModule); ConnectorInfo configureApplication(final ConnectorModule connectorModule); WebAppInfo configureApplication(final WebModule webModule); AppInfo configureApplication(final AppModule appModule); T configureService(final Class<? extends T> type); T configureService(org.apache.openejb.config.Service service, final Class<? extends T> infoType); T configureService(final String id, final Class<? extends T> type); T configureService(final Class<? extends T> type, final String serviceId, final Properties declaredProperties, final String providerId, final String serviceType); static boolean isResourceType(final String service, final List<String> types, final String type); static final String OPENEJB_JDBC_DATASOURCE_CREATOR; static final String ADDITIONAL_DEPLOYMENTS; }
@Test public void testGetOpenEjbConfiguration() throws OpenEJBException { SystemInstance.get().setProperty(ConfigurationFactory.VALIDATION_SKIP_PROPERTY, "false"); SystemInstance.get().setProperty(DeploymentsResolver.SEARCH_CLASSPATH_FOR_DEPLOYMENTS_PROPERTY, "false"); final boolean offline = false; ConfigurationFactory factory = new ConfigurationFactory(offline); OpenEjbConfiguration openEjbConfig = factory.getOpenEjbConfiguration(); assertEquals(0, openEjbConfig.containerSystem.applications.size()); }
@Test public void testConfigurationFactoryBooleanOpenEjbConfiguration() throws OpenEJBException { final boolean offline = false; final OpenEjbConfiguration openEjbConfiguration = new OpenEjbConfiguration(); ConfigurationFactory factory = new ConfigurationFactory(offline, openEjbConfiguration); assertEquals(openEjbConfiguration, factory.getOpenEjbConfiguration()); }
@Test public void testConfigurationFactoryBooleanDynamicDeployerOpenEjbConfiguration() throws OpenEJBException { final boolean offline = false; final DynamicDeployer dynamicDeployer = null; final OpenEjbConfiguration openEjbConfiguration = new OpenEjbConfiguration(); ConfigurationFactory factory = new ConfigurationFactory(offline, dynamicDeployer, openEjbConfiguration); assertEquals(openEjbConfiguration, factory.getOpenEjbConfiguration()); }