You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2012/12/24 12:50:00 UTC

svn commit: r1425636 - /openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java

Author: andygumbrecht
Date: Mon Dec 24 11:49:59 2012
New Revision: 1425636

URL: http://svn.apache.org/viewvc?rev=1425636&view=rev
Log:
Finals

Modified:
    openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java

Modified: openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java?rev=1425636&r1=1425635&r2=1425636&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java (original)
+++ openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java Mon Dec 24 11:49:59 2012
@@ -25,19 +25,9 @@ import org.apache.catalina.session.Stand
 import org.apache.catalina.startup.CatalinaProperties;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.coyote.http11.Http11Protocol;
-import org.apache.openejb.AppContext;
-import org.apache.openejb.BeanContext;
-import org.apache.openejb.NoSuchApplicationException;
-import org.apache.openejb.OpenEJB;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.UndeployException;
+import org.apache.openejb.*;
 import org.apache.openejb.assembler.WebAppDeployer;
-import org.apache.openejb.assembler.classic.AppInfo;
-import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
-import org.apache.openejb.assembler.classic.WebAppBuilder;
-import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.assembler.classic.*;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.IO;
@@ -46,7 +36,6 @@ import org.apache.openejb.spi.ContainerS
 import org.apache.openejb.util.Logger;
 import org.apache.tomee.catalina.TomEERuntimeException;
 import org.apache.tomee.catalina.TomcatLoader;
-import org.apache.tomee.catalina.TomcatWebAppBuilder;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
@@ -55,12 +44,7 @@ import org.apache.velocity.runtime.resou
 
 import javax.naming.Context;
 import javax.naming.NamingException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
+import java.io.*;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -77,9 +61,9 @@ public class Container {
 
     protected Configuration configuration;
     private File base;
-    private Map<String, String> moduleIds = new HashMap<String, String>(); // TODO: manage multimap
-    private Map<String, AppContext> appContexts = new HashMap<String, AppContext>(); // TODO: manage multimap
-    private Map<String, AppInfo> infos = new HashMap<String, AppInfo>(); // TODO: manage multimap
+    private final Map<String, String> moduleIds = new HashMap<String, String>(); // TODO: manage multimap
+    private final Map<String, AppContext> appContexts = new HashMap<String, AppContext>(); // TODO: manage multimap
+    private final Map<String, AppInfo> infos = new HashMap<String, AppInfo>(); // TODO: manage multimap
     private ConfigurationFactory configurationFactory;
     private Assembler assembler;
     private Tomcat tomcat;
@@ -91,7 +75,7 @@ public class Container {
         setup(configuration);
     }
 
-    public void setup(Configuration configuration) {
+    public void setup(final Configuration configuration) {
         this.configuration = configuration;
 
         if (configuration.isQuickSession()) {
@@ -162,7 +146,7 @@ public class Container {
         // Trigger loading of catalina.properties
         CatalinaProperties.getProperty("foo");
 
-        Connector connector = new Connector(Http11Protocol.class.getName());
+        final Connector connector = new Connector(Http11Protocol.class.getName());
         connector.setPort(configuration.getHttpPort());
         connector.setAttribute("connectionTimeout", "3000");
         tomcat.getService().addConnector(connector);
@@ -175,7 +159,7 @@ public class Container {
         // Bootstrap Tomcat
         System.out.println("Starting TomEE from: " + base.getAbsolutePath());
 
-        String catalinaBase = base.getAbsolutePath();
+        final String catalinaBase = base.getAbsolutePath();
         System.setProperty("openejb.deployments.classpath", "false");
         System.setProperty("catalina.home", catalinaBase);
         System.setProperty("catalina.base", catalinaBase);
@@ -190,7 +174,7 @@ public class Container {
 //        bootstrap.start();
 
         // Bootstrap OpenEJB
-        Properties properties = new Properties();
+        final Properties properties = new Properties();
         properties.setProperty("openejb.deployments.classpath", "false");
         properties.setProperty("openejb.loader", "tomcat-system");
         properties.setProperty("openejb.home", catalinaBase);
@@ -201,15 +185,15 @@ public class Container {
         }
 
         try {
-            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-            Properties tomcatServerInfo = IO.readProperties(classLoader.getResourceAsStream("org/apache/catalina/util/ServerInfo.properties"), new Properties());
+            final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            final Properties tomcatServerInfo = IO.readProperties(classLoader.getResourceAsStream("org/apache/catalina/util/ServerInfo.properties"), new Properties());
 
             String serverNumber = tomcatServerInfo.getProperty("server.number");
             if (serverNumber == null) {
                 // Tomcat5 only has server.info
-                String serverInfo = tomcatServerInfo.getProperty("server.info");
+                final String serverInfo = tomcatServerInfo.getProperty("server.info");
                 if (serverInfo != null) {
-                    int slash = serverInfo.indexOf('/');
+                    final int slash = serverInfo.indexOf('/');
                     serverNumber = serverInfo.substring(slash + 1);
                 }
             }
@@ -217,7 +201,7 @@ public class Container {
                 System.setProperty("tomcat.version", serverNumber);
             }
 
-            String serverBuilt = tomcatServerInfo.getProperty("server.built");
+            final String serverBuilt = tomcatServerInfo.getProperty("server.built");
             if (serverBuilt != null) {
                 System.setProperty("tomcat.built", serverBuilt);
             }
@@ -228,7 +212,7 @@ public class Container {
         SystemInstance.init(System.getProperties());
         SystemInstance.get().setComponent(StandardServer.class, (StandardServer) tomcat.getServer());
 
-        TomcatLoader loader = new TomcatLoader();
+        final TomcatLoader loader = new TomcatLoader();
         loader.initDefaults(properties);
         loader.initialize(properties);
 
@@ -255,13 +239,15 @@ public class Container {
         OpenEJB.destroy();
     }
 
-    public AppContext deploy(String name, File file) throws OpenEJBException, IOException, NamingException {
+    public AppContext deploy(final String name, final File file) throws OpenEJBException, IOException, NamingException {
         return deploy(name, file, false);
     }
 
-    public AppContext deploy(String name, File file, boolean overrideName) throws OpenEJBException, IOException, NamingException {
+    public AppContext deploy(final String name, final File file, final boolean overrideName) throws OpenEJBException, IOException, NamingException {
+
         final AppContext context;
         final AppInfo appInfo;
+
         if (WebAppDeployer.Helper.isWebApp(file)) {
             String contextRoot = file.getName();
             if (overrideName) {
@@ -279,18 +265,18 @@ public class Container {
             appInfo = configurationFactory.configureApplication(file);
             if (overrideName) {
                 appInfo.appId = name;
-                for (EjbJarInfo ejbJar : appInfo.ejbJars) {
+                for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
                     if (file.getName().equals(ejbJar.moduleName)) {
                         ejbJar.moduleName = name;
                         ejbJar.moduleId = name;
                     }
-                    for (EnterpriseBeanInfo ejb : ejbJar.enterpriseBeans) {
+                    for (final EnterpriseBeanInfo ejb : ejbJar.enterpriseBeans) {
                         if (BeanContext.Comp.openejbCompName(file.getName()).equals(ejb.ejbName)) {
                             ejb.ejbName = BeanContext.Comp.openejbCompName(name);
                         }
                     }
                 }
-                for (WebAppInfo webApp : appInfo.webApps) {
+                for (final WebAppInfo webApp : appInfo.webApps) {
                     if (sameApplication(file, webApp)) {
                         webApp.moduleId = name;
                         webApp.contextRoot = lastPart(name, webApp.contextRoot);
@@ -317,8 +303,8 @@ public class Container {
     }
 
     private static String lastPart(final String name, final String defaultValue) {
-        int idx = name.lastIndexOf("/");
-        int space = name.lastIndexOf(" ");
+        final int idx = name.lastIndexOf("/");
+        final int space = name.lastIndexOf(" ");
         if (idx >= 0 && space < idx) {
             return name.substring(idx);
         } else if (idx < 0 && space < 0) {
@@ -331,7 +317,7 @@ public class Container {
         return infos.get(name);
     }
 
-    public void undeploy(String name) throws UndeployException, NoSuchApplicationException {
+    public void undeploy(final String name) throws UndeployException, NoSuchApplicationException {
         final String moduleId = moduleIds.remove(name);
         infos.remove(name);
         appContexts.remove(name);
@@ -344,11 +330,11 @@ public class Container {
         return assembler.getContainerSystem().getJNDIContext();
     }
 
-    public AppContext getAppContexts(String moduleId) {
+    public AppContext getAppContexts(final String moduleId) {
         return appContexts.get(moduleId);
     }
 
-    private void deleteTree(File file) {
+    private void deleteTree(final File file) {
         if (file == null)
             return;
         if (!file.exists())
@@ -367,10 +353,10 @@ public class Container {
             if ("src/main".equals(file.getName()))
                 return;
 
-            File[] children = file.listFiles();
+            final File[] children = file.listFiles();
 
             if (children != null) {
-                for (File child : children) {
+                for (final File child : children) {
                     deleteTree(child);
                 }
             }
@@ -381,24 +367,24 @@ public class Container {
         }
     }
 
-    private void copyTemplateTo(File targetDir, String filename) throws Exception {
+    private void copyTemplateTo(final File targetDir, final String filename) throws Exception {
         Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
         Velocity.setProperty(Velocity.RESOURCE_LOADER, "class");
         Velocity.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
         Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
         Velocity.init();
-        Template template = Velocity.getTemplate("/org/apache/tomee/configs/" + filename);
-        VelocityContext context = new VelocityContext();
+        final Template template = Velocity.getTemplate("/org/apache/tomee/configs/" + filename);
+        final VelocityContext context = new VelocityContext();
         context.put("tomcatHttpPort", Integer.toString(configuration.getHttpPort()));
         context.put("tomcatShutdownPort", Integer.toString(configuration.getStopPort()));
-        Writer writer = new FileWriter(new File(targetDir, filename));
+        final Writer writer = new FileWriter(new File(targetDir, filename));
         template.merge(context, writer);
         writer.flush();
         writer.close();
     }
 
-    private void copyFileTo(File targetDir, String filename) throws IOException {
-        InputStream is = getClass().getResourceAsStream("/org/apache/tomee/configs/" + filename);
+    private void copyFileTo(final File targetDir, final String filename) throws IOException {
+        final InputStream is = getClass().getResourceAsStream("/org/apache/tomee/configs/" + filename);
         if (is != null) { // should be null since we are using default conf
             try {
                 IO.copy(is, new File(targetDir, filename));
@@ -408,8 +394,8 @@ public class Container {
         }
     }
 
-    private File createDirectory(File parent, String directory) {
-        File dir = new File(parent, directory);
+    private File createDirectory(final File parent, final String directory) {
+        final File dir = new File(parent, directory);
         if (!dir.exists() && !dir.mkdirs()) {
             throw new IllegalStateException("Unable to make dir " + dir.getAbsolutePath());
         }
@@ -426,11 +412,11 @@ public class Container {
         @Override
         public void start() throws LifecycleException {
             // Use fast, insecure session ID generation for all tests
-            Server server = getServer();
-            for (Service service : server.findServices()) {
-                org.apache.catalina.Container e = service.getContainer();
-                for (org.apache.catalina.Container h : e.findChildren()) {
-                    for (org.apache.catalina.Container c : h.findChildren()) {
+            final Server server = getServer();
+            for (final Service service : server.findServices()) {
+                final org.apache.catalina.Container e = service.getContainer();
+                for (final org.apache.catalina.Container h : e.findChildren()) {
+                    for (final org.apache.catalina.Container c : h.findChildren()) {
                         StandardManager m = (StandardManager) c.getManager();
                         if (m == null) {
                             m = new StandardManager();