You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/01/16 12:48:42 UTC

svn commit: r496663 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config: AutoDeployer.java ConfigurationFactory.java ProviderDefaults.java

Author: dblevins
Date: Tue Jan 16 03:48:40 2007
New Revision: 496663

URL: http://svn.apache.org/viewvc?view=rev&rev=496663
Log:
Inlined and cleaned ConfigurationFactory

Removed:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ProviderDefaults.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AutoDeployer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AutoDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AutoDeployer.java?view=diff&rev=496663&r1=496662&r2=496663
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AutoDeployer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AutoDeployer.java Tue Jan 16 03:48:40 2007
@@ -29,16 +29,11 @@
 import org.apache.openejb.util.SafeToolkit;
 
 public class AutoDeployer implements DynamicDeployer {
-
-    private List<ContainerInfo> containers;
-    private List<String> resources;
+    private final ConfigurationFactory config;
 
     public AutoDeployer(ConfigurationFactory config) {
         /* Load container list */
-        this.containers = config.getContainerInfos();
-
-        /* Load resource list */
-        this.resources = config.getConnectorIds();
+        this.config = config;
     }
 
     public void init() throws OpenEJBException {
@@ -153,7 +148,7 @@
     }
 
     private String getUsableContainer(Class<? extends ContainerInfo> containerInfoType) {
-        for (ContainerInfo containerInfo : containers) {
+        for (ContainerInfo containerInfo : config.getContainerInfos()) {
             if (containerInfo.getClass().equals(containerInfoType)){
                 return containerInfo.id;
             }
@@ -162,6 +157,8 @@
         return null;
     }
     private ResourceLink autoAssingResourceRef(ResourceRef ref) throws OpenEJBException {
+
+        List<String> resources = config.getConnectorIds();
         if (resources.size() == 0) {
             throw new OpenEJBException("A Connector must be declared in the configuration file to satisfy the resource-ref " + ref.getResRefName());
         }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java?view=diff&rev=496663&r1=496662&r2=496663
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java Tue Jan 16 03:48:40 2007
@@ -64,7 +64,7 @@
 import java.util.Map;
 import java.util.Properties;
 
-public class ConfigurationFactory implements OpenEjbConfigurationFactory, ProviderDefaults {
+public class ConfigurationFactory implements OpenEjbConfigurationFactory {
 
     public static final Logger logger = Logger.getInstance("OpenEJB.startup", "org.apache.openejb.util.resources");
     protected static final Messages messages = new Messages("org.apache.openejb.util.resources");
@@ -75,27 +75,38 @@
 
     public static OpenEjbConfiguration sys;
 
-    private final List<ContainerInfo> containers = new ArrayList<ContainerInfo>();
-    private Map<String, ContainerInfo> containerTable = new HashMap<String, ContainerInfo>();
-
-    private Properties props = new Properties();
     public EjbJarInfoBuilder ejbJarInfoBuilder = new EjbJarInfoBuilder();
+
     private Openejb openejb;
+
     private DynamicDeployer deployer;
     private final DeploymentLoader deploymentLoader;
 
     public ConfigurationFactory() {
         deploymentLoader = new DeploymentLoader();
-    }
 
-    public void init(Properties props) throws OpenEJBException {
-        this.props = props;
+        DynamicDeployer deployer;
+        // TODO: Create some way to enable one versus the other
+        if (false) {
+            deployer = new AutoDeployer(this);
 
-        findConfiguration(props);
+        } else {
+            deployer = new AutoConfigAndDeploy(this);
+        }
+
+        deployer = new AnnotationDeployer(deployer);
 
+        boolean shouldValidate = !SystemInstance.get().getProperty("openejb.validation.skip", "false").equalsIgnoreCase("true");
+        if (shouldValidate) {
+            deployer = new ValidateEjbModule(deployer);
+        } else {
+            DeploymentLoader.logger.info("Validation is disabled.");
+        }
+        this.deployer = deployer;
     }
 
-    private void findConfiguration(Properties props) throws OpenEJBException {
+    public void init(Properties props) throws OpenEJBException {
+
         configLocation = props.getProperty("openejb.conf.file");
 
         if (configLocation == null) {
@@ -104,8 +115,9 @@
 
         configLocation = ConfigUtils.searchForConfiguration(configLocation, props);
         if (configLocation != null) {
-            this.props.setProperty("openejb.configuration", configLocation);
+            props.setProperty("openejb.configuration", configLocation);
         }
+
     }
 
     public void install(ContainerInfo serviceInfo) throws OpenEJBException {
@@ -139,59 +151,56 @@
         sys.facilities = new FacilitiesInfo();
 
 
-        initJndiProviders(openejb, sys.facilities);
-        initSecutityService(openejb, sys.facilities);
-        initTransactionService(openejb, sys.facilities);
-        initConnectors(openejb, sys.facilities);
-        initConnectionManagers(openejb, sys.facilities);
-        initProxyFactory(openejb, sys.facilities);
-        initContainerInfos(openejb);
+        for (JndiProvider provider : openejb.getJndiProvider()) {
 
-        deployer = getDeployer();
-
-        List<String> jarList = DeploymentsResolver.resolveAppLocations(openejb.getDeployments());
+            JndiContextInfo info = configureService(provider, JndiContextInfo.class);
+            sys.facilities.remoteJndiContexts.add(info);
+        }
 
-        List<AppInfo> appInfos = new ArrayList<AppInfo>();
-        for (String pathname : jarList) {
+        sys.facilities.securityService = configureService(openejb.getSecurityService(), SecurityServiceInfo.class);
 
-            File jarFile = new File(pathname);
+        sys.facilities.transactionService = configureService(openejb.getTransactionService(), TransactionServiceInfo.class);
 
-            AppInfo appInfo = configureApplication(jarFile);
+        for (Connector connector : openejb.getConnector()) {
 
-            appInfos.add(appInfo);
+            ConnectorInfo connectorInfo = configureService(connector, ConnectorInfo.class);
+            sys.facilities.connectors.add(connectorInfo);
         }
 
+        ConnectionManagerInfo service = configureService(openejb.getConnectionManager(), ConnectionManagerInfo.class);
+        sys.facilities.connectionManagers.add(service);
 
-        sys.containerSystem.containers.addAll(containers);
-
+        sys.facilities.intraVmServer = configureService(openejb.getProxyFactory(), ProxyFactoryInfo.class);
 
-        sys.containerSystem.applications.addAll(appInfos);
+        for (Container declaration : openejb.getContainer()) {
 
-        return sys;
-    }
+            Class<? extends ContainerInfo> infoClass = getContainerInfoType(declaration.getCtype());
 
+            if (infoClass == null) {
+                throw new OpenEJBException("Unrecognized contianer type " + declaration.getCtype());
+            }
 
-    private DynamicDeployer getDeployer() {
-        DynamicDeployer deployer;
-        // TODO: Create some way to enable one versus the other
-        if (false) {
-            deployer = new AutoDeployer(this);
+            ContainerInfo info = configureService(declaration, infoClass);
 
-        } else {
-            deployer = new AutoConfigAndDeploy(this);
+            sys.containerSystem.containers.add(info);
         }
 
-        deployer = new AnnotationDeployer(deployer);
 
-        boolean shouldValidate = !SystemInstance.get().getProperty("openejb.validation.skip", "false").equalsIgnoreCase("true");
-        if (shouldValidate) {
-            deployer = new ValidateEjbModule(deployer);
-        } else {
-            DeploymentLoader.logger.info("Validation is disabled.");
+        List<String> jarList = DeploymentsResolver.resolveAppLocations(openejb.getDeployments());
+
+        for (String pathname : jarList) {
+
+            File jarFile = new File(pathname);
+
+            AppInfo appInfo = configureApplication(jarFile);
+
+            sys.containerSystem.applications.add(appInfo);
         }
-        return deployer;
+
+        return sys;
     }
 
+
     public AppInfo configureApplication(File jarFile) {
         logger.debug("Beginning load: " + jarFile.getAbsolutePath());
 
@@ -221,8 +230,23 @@
                 if (ejbJarInfo == null) {
                     continue;
                 }
-                assignBeansToContainers(ejbJarInfo.enterpriseBeans, ejbModule.getOpenejbJar().getDeploymentsByEjbName());
+
+                Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
+
+                for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
+                    EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
+
+                    if (!getContainerIds().contains(d.getContainerId())) {
+                        String msg = messages.format("config.noContainerFound", d.getContainerId(), d.getEjbName());
+                        logger.fatal(msg);
+                        throw new OpenEJBException(msg);
+                    }
+
+                    bean.containerId = d.getContainerId();
+                }
+
                 appInfo.ejbJars.add(ejbJarInfo);
+
             } catch (Exception e) {
                 e.printStackTrace();
                 ConfigUtils.logger.i18n.warning("conf.0004", ejbModule.getJarURI(), e.getMessage());
@@ -264,71 +288,6 @@
     }
 
 
-    private void initJndiProviders(Openejb openejb, FacilitiesInfo facilities)
-            throws OpenEJBException {
-        JndiProvider[] provider = openejb.getJndiProvider();
-
-        if (provider == null || provider.length < 1) return;
-
-        for (int i = 0; i < provider.length; i++) {
-            JndiContextInfo info = configureService(provider[i], JndiContextInfo.class);
-
-            facilities.remoteJndiContexts.add(info);
-        }
-    }
-
-    private void initSecutityService(Openejb openejb, FacilitiesInfo facilities) throws OpenEJBException {
-
-        facilities.securityService = configureService(openejb.getSecurityService(), SecurityServiceInfo.class);
-    }
-
-    private void initTransactionService(Openejb openejb, FacilitiesInfo facilities) throws OpenEJBException {
-
-        facilities.transactionService = configureService(openejb.getTransactionService(), TransactionServiceInfo.class);
-
-    }
-
-    private void initConnectors(Openejb openejb, FacilitiesInfo facilities)
-            throws OpenEJBException {
-
-        Connector[] conn = openejb.getConnector();
-
-        if (conn == null || conn.length < 1) return;
-
-        for (int i = 0; i < conn.length; i++) {
-
-            ConnectorInfo connectorInfo = configureService(conn[i], ConnectorInfo.class);
-
-            facilities.connectors.add(connectorInfo);
-        }
-    }
-
-    private void initConnectionManagers(Openejb openejb, FacilitiesInfo facilities)
-            throws OpenEJBException {
-
-        ConnectionManagerInfo service = configureService(openejb.getConnectionManager(), ConnectionManagerInfo.class);
-
-        facilities.connectionManagers.add(service);
-    }
-
-    private void initProxyFactory(Openejb openejb, FacilitiesInfo facilities) throws OpenEJBException {
-        String defaultId = null;
-        try {
-            String version = System.getProperty("java.vm.version");
-            if (version.startsWith("1.1") || version.startsWith("1.2")) {
-                defaultId = "Default JDK 1.2 ProxyFactory";
-            } else {
-                defaultId = "Default JDK 1.3 ProxyFactory";
-            }
-        } catch (Exception e) {
-
-            throw new RuntimeException("Unable to determine the version of your VM.  No ProxyFactory Can be installed");
-        }
-
-        facilities.intraVmServer = configureService(openejb.getProxyFactory(), ProxyFactoryInfo.class);
-
-    }
-
     public static class DefaultService {
         private final Class<? extends Service> type;
         private final String id;
@@ -342,16 +301,16 @@
     private static final Map<Class<? extends ServiceInfo>, DefaultService> defaultProviders = new HashMap();
 
     static {
-        defaultProviders.put(MdbContainerInfo.class, new DefaultService(DEFAULT_MDB_CONTAINER, Container.class));
-        defaultProviders.put(StatefulSessionContainerInfo.class, new DefaultService(DEFAULT_STATEFUL_CONTAINER, Container.class));
-        defaultProviders.put(StatelessSessionContainerInfo.class, new DefaultService(DEFAULT_STATELESS_CONTAINER, Container.class));
-        defaultProviders.put(CmpEntityContainerInfo.class, new DefaultService(DEFAULT_CMP_CONTAINER, Container.class));
-        defaultProviders.put(BmpEntityContainerInfo.class, new DefaultService(DEFAULT_BMP_CONTAINER, Container.class));
-        defaultProviders.put(SecurityServiceInfo.class, new DefaultService(DEFAULT_SECURITY_SERVICE, SecurityService.class));
-        defaultProviders.put(TransactionServiceInfo.class, new DefaultService(DEFAULT_TRANSACTION_MANAGER, TransactionManager.class));
-        defaultProviders.put(ConnectionManagerInfo.class, new DefaultService(DEFAULT_LOCAL_TX_CON_MANAGER, ConnectionManager.class));
-        defaultProviders.put(ProxyFactoryInfo.class, new DefaultService(DEFAULT_JDK_13_PROXYFACTORY, ProxyFactory.class));
-        defaultProviders.put(ConnectorInfo.class, new DefaultService(DEFAULT_JDBC_DATABASE, Connector.class));
+        defaultProviders.put(MdbContainerInfo.class, new DefaultService("Default MDB Container", Container.class));
+        defaultProviders.put(StatefulSessionContainerInfo.class, new DefaultService("Default Stateful Container", Container.class));
+        defaultProviders.put(StatelessSessionContainerInfo.class, new DefaultService("Default Stateless Container", Container.class));
+        defaultProviders.put(CmpEntityContainerInfo.class, new DefaultService("Default CMP Container", Container.class));
+        defaultProviders.put(BmpEntityContainerInfo.class, new DefaultService("Default BMP Container", Container.class));
+        defaultProviders.put(SecurityServiceInfo.class, new DefaultService("Default Security Service", SecurityService.class));
+        defaultProviders.put(TransactionServiceInfo.class, new DefaultService("Default Transaction Manager", TransactionManager.class));
+        defaultProviders.put(ConnectionManagerInfo.class, new DefaultService("Default Local TX ConnectionManager", ConnectionManager.class));
+        defaultProviders.put(ProxyFactoryInfo.class, new DefaultService("Default JDK 1.3 ProxyFactory", ProxyFactory.class));
+        defaultProviders.put(ConnectorInfo.class, new DefaultService("Default JDBC Database", Connector.class));
     }
 
     protected <T extends ServiceInfo> T configureDefault(Class<? extends T> type) throws OpenEJBException {
@@ -396,7 +355,7 @@
         Properties properties = ServiceUtils.assemblePropertiesFor(serviceType, service.getId(), service.getContent(), configLocation, provider);
 
         if (!provider.getProviderType().equals(serviceType)) {
-            handleException("conf.4902", service, serviceType);
+            throw new OpenEJBException(messages.format("conf.4902", service, serviceType));
         }
 
         info.serviceType = provider.getProviderType();
@@ -429,25 +388,6 @@
         containerTypes.put(Bean.MESSAGE, MdbContainerInfo.class);
     }
 
-    private void initContainerInfos(Openejb conf) throws OpenEJBException {
-
-        Container[] containers = conf.getContainer();
-
-        for (Container declaration : containers) {
-
-            Class<? extends ContainerInfo> infoClass = getContainerInfoType(declaration.getCtype());
-
-            if (infoClass == null) {
-                throw new OpenEJBException("Unrecognized contianer type " + declaration.getCtype());
-            }
-
-            ContainerInfo info = configureService(declaration, infoClass);
-
-            this.containers.add(info);
-            containerTable.put(info.id, info);
-        }
-    }
-
     public static Class<? extends ContainerInfo> getContainerInfoType(String ctype) {
         return containerTypes.get(ctype);
     }
@@ -460,28 +400,6 @@
         return Arrays.asList(constructor.split("[ ,]+"));
     }
 
-    private void assignBeansToContainers(List<EnterpriseBeanInfo> beans, Map ejbds) throws OpenEJBException {
-
-        List<String> containerIds = new ArrayList();
-        Container[] containers = openejb.getContainer();
-        for (Container container : containers) {
-            containerIds.add(container.getId());
-        }
-
-        for (EnterpriseBeanInfo bean : beans) {
-            EjbDeployment d = (EjbDeployment) ejbds.get(bean.ejbName);
-
-            if (!getContainerIds().contains(d.getContainerId())) {
-
-                String msg = messages.format("config.noContainerFound", d.getContainerId(), d.getEjbName());
-
-                logger.fatal(msg);
-                throw new OpenEJBException(msg);
-            }
-            bean.containerId = d.getContainerId();
-        }
-    }
-
 
     protected List<String> getConnectorIds() {
         List<String> connectorIds = new ArrayList();
@@ -495,7 +413,7 @@
             for (ConnectorInfo connectorInfo : sys.facilities.connectors) {
                 connectorIds.add(connectorInfo.id);
             }
-            
+
             // The only time we'd have one of these is if we were building
             // the above sys instance
             if (openejb != null){
@@ -550,12 +468,8 @@
 
 
     private OpenEjbConfiguration getRunningConfig() {
-        OpenEjbConfiguration runningConfig = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
-        return runningConfig;
+        return SystemInstance.get().getComponent(OpenEjbConfiguration.class);
     }
 
-    public static void handleException(String errorCode, Object... args) throws OpenEJBException {
-        throw new OpenEJBException(messages.format(errorCode, args));
-    }
 }