jlaskowski    2004/07/05 11:47:45

  Modified:    modules/core/src/java/org/openejb/alt/config
                        ConfigUtils.java ConfigurationFactory.java
  Log:

  Further enhancements to make OpenEJB instances to not interfere with each other when 
embedded in separate webapps
  
  Revision  Changes    Path
  1.5       +71 -27    
openejb1/modules/core/src/java/org/openejb/alt/config/ConfigUtils.java
  
  Index: ConfigUtils.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/ConfigUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConfigUtils.java  12 May 2004 11:04:13 -0000      1.4
  +++ ConfigUtils.java  5 Jul 2004 15:47:45 -0000       1.5
  @@ -57,6 +57,7 @@
   import java.net.URL;
   import java.net.UnknownHostException;
   import java.util.Enumeration;
  +import java.util.Properties;
   import java.util.jar.JarEntry;
   import java.util.jar.JarFile;
   
  @@ -301,50 +302,93 @@
       }
   
       public static String searchForConfiguration(String path) throws 
OpenEJBException{
  -        File file = null;
  -        try{
  +        return ConfigUtils.searchForConfiguration(path, System.getProperties());
  +    }
   
  -            /* [1] Try finding the file relative to the 
  -             *     current working directory
  +    public static String searchForConfiguration(String path, Properties props) 
throws OpenEJBException{
  +        File file = null;
  +        if (path != null) {
  +            /*
  +             * [1] Try finding the file relative to the current working
  +             * directory
                */
  -            try{
  -                file = new File(path);
  -                if (file != null && file.exists() && file.isFile()) {
  -                    return file.getAbsolutePath();
  -                }
  -            } catch (NullPointerException e){
  +            file = new File(path);
  +            if (file != null && file.exists() && file.isFile()) {
  +                return file.getAbsolutePath();
  +            }
  +            
  +            /*
  +             * [2] Try finding the file relative to the openejb.base directory
  +             */
  +            try
  +            {
  +            file = FileUtils.getBase(props).getFile(path);
  +            if (file != null && file.exists() && file.isFile()) {
  +                return file.getAbsolutePath();
  +            }
  +            }
  +            catch (FileNotFoundException ignored)
  +            {
  +            }
  +            catch (IOException ignored)
  +            {
  +            }
  +            
  +            /*
  +             * [3] Try finding the file relative to the openejb.home directory
  +             */
  +            try
  +            {
  +            file = FileUtils.getHome(props).getFile(path);
  +            if (file != null && file.exists() && file.isFile()) {
  +                return file.getAbsolutePath();
  +            }
  +            }
  +            catch (FileNotFoundException ignored)
  +            {
  +            }
  +            catch (IOException ignored)
  +            {
               }
               
  -            /* [2] Try finding the file relative to the 
  -             *     openejb.home directory
  +        }
  +
  +        _logger.warning("Cannot find the configuration file ["+path+"], Trying 
conf/openejb.conf instead.");
  +
  +        try
  +        {
  +            /*
  +             * [4] Try finding the standard openejb.conf file relative to the
  +             * openejb.base directory
                */
  -            try{
  -                file = FileUtils.getBase().getFile(path);
  +            try {
  +                file = FileUtils.getBase(props).getFile("conf/openejb.conf");
                   if (file != null && file.exists() && file.isFile()) {
                       return file.getAbsolutePath();
                   }
  -            } catch (NullPointerException e){
  -            } catch (java.io.FileNotFoundException e){
  -                _logger.warning("Cannot find the configuration file ["+path+"], 
Using default OPENEJB_HOME/conf/openejb.conf instead.");
  +            } catch (java.io.FileNotFoundException e) {
               }
  -
  -            /* [3] Try finding the standard openejb.conf file 
  -             *     relative to the openejb.home directory
  +                        
  +            /*
  +             * [5] Try finding the standard openejb.conf file relative to the
  +             * openejb.home directory
                */
  -            try{
  -                file = FileUtils.getBase().getFile("conf/openejb.conf");
  +            try {
  +                file = FileUtils.getHome(props).getFile("conf/openejb.conf");
                   if (file != null && file.exists() && file.isFile()) {
                       return file.getAbsolutePath();
                   }
  -            } catch (java.io.FileNotFoundException e){
  +            } catch (java.io.FileNotFoundException e) {
               }
  -                        
  -            /* [4] No config found! Create a config for them
  +
  +            _logger.warning("Cannot find the configuration file 
[conf/openejb.conf], Creating one.");
  +
  +            /* [6] No config found! Create a config for them
                *     using the default.openejb.conf file from 
                *     the openejb-x.x.x.jar
                */
               //Gets the conf directory, creating it if needed.
  -            File confDir = FileUtils.getBase().getDirectory("conf", true);
  +            File confDir = FileUtils.getBase(props).getDirectory("conf", true);
               
               //TODO:1: We cannot find the user's conf file and
               // are taking the liberty of creating one for them.
  
  
  
  1.3       +25 -17    
openejb1/modules/core/src/java/org/openejb/alt/config/ConfigurationFactory.java
  
  Index: ConfigurationFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/ConfigurationFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConfigurationFactory.java 12 May 2004 11:04:13 -0000      1.2
  +++ ConfigurationFactory.java 5 Jul 2004 15:47:45 -0000       1.3
  @@ -163,9 +163,11 @@
   
       /** Hash of container info objects for quick reference */
       private HashMap containerTable = new HashMap();
  +    
  +    private Properties props;
   
       public void init(Properties props) throws OpenEJBException {
  -        if ( props == null ) props = new Properties();
  +        this.props = props;
   
           configLocation = props.getProperty("openejb.conf.file");
   
  @@ -173,8 +175,8 @@
               configLocation = props.getProperty("openejb.configuration");
           }
   
  -        configLocation = ConfigUtils.searchForConfiguration(configLocation);
  -        System.setProperty("openejb.configuration", configLocation);
  +        configLocation = ConfigUtils.searchForConfiguration(configLocation, props);
  +        this.props.setProperty("openejb.configuration", configLocation);
   
       }
   
  @@ -1106,8 +1108,12 @@
                   if (d.getDir() == null && d.getJar() != null) {
                       File jar = null;
                       try {
  -                        jar = FileUtils.getBase().getFile(d.getJar(), false);
  -                    } catch (Exception e) {
  +                        jar = FileUtils.getBase(this.props).getFile(d.getJar(), 
false);
  +                    } catch (Exception ignored) {
  +                        try {
  +                            jar = FileUtils.getHome(this.props).getFile(d.getJar(), 
false);
  +                        } catch (Exception ignoredAgain) {
  +                        }
                       }
                       if (!jarList.contains(jar.getAbsolutePath())) {
                           jarList.add(jar.getAbsolutePath());
  @@ -1120,15 +1126,25 @@
   
                   File dir = null;
                   try {
  -                    dir = FileUtils.getBase().getFile(d.getDir(), false);
  -                } catch (Exception e) {
  +                    dir = FileUtils.getBase(this.props).getFile(d.getDir(), false);
  +                } catch (Exception ignored) {
  +                }
  +                if (dir == null || !dir.exists()) {
  +                    try {
  +                        dir = FileUtils.getHome(this.props).getFile(d.getDir(), 
false);
  +                    } catch (Exception ignoredAgain) {
  +                    }
                   }
   
                   // Opps! Not a directory
  -                if ( !dir.isDirectory() ) continue;
  +                if ( dir == null || !dir.isDirectory() ) continue;
   
                   String[] files = dir.list();
   
  +                if ( files == null ) {
  +                    continue;
  +                }
  +                
                   for (int x = 0; x < files.length; x++) {
   
                       String f = files[x];
  @@ -1175,14 +1191,6 @@
           for (int i = 0; i < jarsToLoad.length; i++) {
   
               String jarLocation = jarsToLoad[i];
  -            try {
  -                // Try to resolve path relative to openejb.home
  -                jarLocation = 
FileUtils.getBase().getFile(jarLocation,false).getAbsolutePath();
  -            } catch (java.io.IOException e) {
  -                // The methods below have more specific exception 
  -                // handling for this
  -            }
  -
               try {
                   EjbJar ejbJar = EjbJarUtils.readEjbJar(jarLocation);
   
  
  
  

Reply via email to