dblevins    2005/07/09 04:51:00

  Modified:    modules/core/src/java/org/openejb/loader
                        EmbeddingLoader.java SystemLoader.java
                        TomcatWebappLoader.java
  Added:       modules/core/src/java/org/openejb/loader SystemInstance.java
  Log:

  I can't fix this Tomcat integration issue with all the silly statics.  
Killing the statics.  Death to the statics!
  Added a class called SystemInstance, which is a singleton and hopefully the 
only important static for the 1.0 codebase someday.
  Changed FileUtils to get its instances from SystemInstance, then inlined all 
that code.
  Changed ClasspathUtils to get its Loader instance from SystemInstance and 
managed to inline all the remaining code.
  
  Revision  Changes    Path
  1.6       +6 -3      
openejb1/modules/core/src/java/org/openejb/loader/EmbeddingLoader.java
  
  Index: EmbeddingLoader.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/EmbeddingLoader.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EmbeddingLoader.java      6 Jul 2005 02:04:03 -0000       1.5
  +++ EmbeddingLoader.java      9 Jul 2005 08:51:00 -0000       1.6
  @@ -45,6 +45,7 @@
   package org.openejb.loader;
   
   import java.util.Hashtable;
  +import java.io.File;
   
   import org.openejb.util.ClasspathUtils;
   
  @@ -99,8 +100,10 @@
           try{
               String openejbLoader = (String) env.get("openejb.loader");
   
  -            ClasspathUtils.addJarsToPath("lib", (openejbLoader == null ? 
"tomcat" : openejbLoader), env);
  -            ClasspathUtils.addJarsToPath("dist", (openejbLoader == null ? 
"tomcat" : openejbLoader), env);
  +            File directory = 
SystemInstance.get().getHome().getDirectory("lib");
  +            SystemInstance.get().getLoader().addJarsToPath(directory);
  +            File directory1 = 
SystemInstance.get().getHome().getDirectory("dist");
  +            SystemInstance.get().getLoader().addJarsToPath(directory1);
           } catch (Exception e){
               throw new Exception( "Could not load OpenEJB libraries. 
Exception: "+
                                    e.getClass().getName()+" "+ e.getMessage());
  
  
  
  1.5       +3 -3      
openejb1/modules/core/src/java/org/openejb/loader/SystemLoader.java
  
  Index: SystemLoader.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/SystemLoader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SystemLoader.java 9 Jul 2005 05:53:21 -0000       1.4
  +++ SystemLoader.java 9 Jul 2005 08:51:00 -0000       1.5
  @@ -65,7 +65,7 @@
       private final ClasspathUtils.Loader loader;
   
       public SystemLoader() {
  -        this.loader = ClasspathUtils.sysLoader;
  +        this.loader = SystemInstance.get().getLoader();
       }
   
       /**
  @@ -121,7 +121,7 @@
   
       private void addJarsToPath(String dir) throws Exception {
           Hashtable env = System.getProperties();
  -        File dirAtHome = FileUtils.getHome().getDirectory(dir);
  +        File dirAtHome = SystemInstance.get().getHome().getDirectory(dir);
           loader.addJarsToPath(dirAtHome);
       }
   }
  
  
  
  1.7       +3 -7      
openejb1/modules/core/src/java/org/openejb/loader/TomcatWebappLoader.java
  
  Index: TomcatWebappLoader.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/TomcatWebappLoader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TomcatWebappLoader.java   9 Jul 2005 07:30:18 -0000       1.6
  +++ TomcatWebappLoader.java   9 Jul 2005 08:51:00 -0000       1.7
  @@ -61,7 +61,7 @@
       private final ClasspathUtils.Loader loader;
   
       public TomcatWebappLoader() {
  -        this.loader = ClasspathUtils.webappLoader;
  +        this.loader = SystemInstance.get().getLoader();
       }
   
       /**
  @@ -109,10 +109,6 @@
       private void importOpenEJBLibraries(  Hashtable env ) throws Exception{
           // Sets the openejb.home system variable
   
  -        Properties envProperties = new Properties();
  -        envProperties.putAll(env);
  -        FileUtils.init(envProperties);
  -
           try{
               // Loads all the libraries in the openejb.home/lib directory
               addJarsToPath("lib");
  @@ -128,7 +124,7 @@
   
       private void addJarsToPath(String dir) throws Exception {
           Hashtable env = System.getProperties();
  -        File dirAtHome = FileUtils.getHome().getDirectory(dir);
  +        File dirAtHome = SystemInstance.get().getHome().getDirectory(dir);
           loader.addJarsToPath(dirAtHome);
       }
   }
  
  
  
  1.1                  
openejb1/modules/core/src/java/org/openejb/loader/SystemInstance.java
  
  Index: SystemInstance.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: SystemInstance.java,v 1.1 2005/07/09 08:51:00 dblevins Exp $
   */
  
  package org.openejb.loader;
  
  import java.util.Properties;
  import java.util.HashMap;
  
  import org.openejb.util.FileUtils;
  import org.openejb.util.ClasspathUtils;
  
  /**
   * This class aims to be the one and only static in the entire system
   * A static, singleton, instance of this class can be created with the 
init(props) method
   *
   * It is assumed that only one singleton per classloader is possible in any 
given VM
   * Thus loading this instance in a classloader will mean there can only be 
one OpenEJB
   * instance for that classloader and all children classloaders.
   *
   * @version $Revision: 1.1 $ $Date: 2005/07/09 08:51:00 $
   */
  public class SystemInstance {
  
      private final long startTime = System.currentTimeMillis();
      private final Properties properties;
      private final FileUtils home;
      private final FileUtils base;
      private ClassLoader classLoader;
      private final HashMap components;
      private final ClasspathUtils.Loader loader;
  
      private SystemInstance(Properties properties) throws Exception {
          this.properties = properties;
          this.home = new FileUtils("openejb.home", "user.dir", properties);
          this.base = new FileUtils("openejb.base", "openejb.home", properties);
          this.components = new HashMap();
          loader = 
ClasspathUtils.LoaderFactory.createLoader(properties.getProperty("openejb.loader",
 "context"));
      }
  
  
      public long getStartTime() {
          return startTime;
      }
  
      public Properties getProperties() {
          return properties;
      }
  
      public String getProperty(String key) {
          return properties.getProperty(key);
      }
  
      public String getProperty(String key, String defaultValue) {
          return properties.getProperty(key, defaultValue);
      }
  
      public Object setProperty(String key, String value) {
          return properties.setProperty(key, value);
      }
  
      public FileUtils getHome() {
          return home;
      }
  
      public FileUtils getBase() {
          return base;
      }
  
      public ClasspathUtils.Loader getLoader() {
          return loader;
      }
  
      public ClassLoader getClassLoader() {
          return classLoader;
      }
  
      public void setClassLoader(ClassLoader classLoader) {
          this.classLoader = classLoader;
      }
  
      public Object getObject(String name) {
          return components.get(name);
      }
  
      public Object setObject(String name, Object value) {
          return components.put(name, value);
      }
  
      //----------------------------------------------------//
      // Static uglyness
      //----------------------------------------------------//
  
      private static SystemInstance system;
      static {
          try {
              system = new SystemInstance(System.getProperties());
          } catch (Exception e) {
              throw new RuntimeException("Failed to create default instance of 
SystemInstance",e);
          }
      }
  
      public static void init(Properties properties) throws Exception{
          system = new SystemInstance(properties);
      }
  
      public static SystemInstance get(){
          return system;
      }
  
  }
  
  
  

Reply via email to