dblevins    2005/08/04 16:17:43

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

  Moved openejb-jar methods into the EjbJarUtils class.
  Killed tons more of static methods
  
  Revision  Changes    Path
  1.12      +18 -184   
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ConfigUtils.java  9 Jul 2005 08:50:59 -0000       1.11
  +++ ConfigUtils.java  4 Aug 2005 20:17:42 -0000       1.12
  @@ -82,16 +82,16 @@
    */
   public class ConfigUtils {
   
  -    private static Messages messages = new 
Messages("org.openejb.util.resources");
  -    private static Logger _logger = Logger.getInstance("OpenEJB", 
"org.openejb.util.resources");
  +    public static Messages messages = new 
Messages("org.openejb.util.resources");
  +    public static Logger logger = Logger.getInstance("OpenEJB", 
"org.openejb.util.resources");
   
       public static Openejb readConfig() throws OpenEJBException {
           return readConfig(searchForConfiguration());
       }
   
       /*
  -        TODO: Use the java.net.URL instead of java.io.File so configs
  -        and jars can be located remotely in the network
  +     * TODO: Use the java.net.URL instead of java.io.File so configs
  +     * and jars can be located remotely in the network
        */
       public static Openejb readConfig(String confFile) throws 
OpenEJBException {
           Openejb obj = null;
  @@ -102,14 +102,14 @@
               unmarshaller.setWhitespacePreserve(true);
               obj = (Openejb) unmarshaller.unmarshal(reader);
           } catch (FileNotFoundException e) {
  -            handleException("conf.1900", confFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.1900", 
confFile, e.getLocalizedMessage()));
           } catch (MarshalException e) {
               if (e.getException() instanceof IOException) {
  -                handleException("conf.1110", confFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.1110", 
confFile, e.getLocalizedMessage()));
               } else if (e.getException() instanceof UnknownHostException) {
  -                handleException("conf.1121", confFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.1121", 
confFile, e.getLocalizedMessage()));
               } else {
  -                handleException("conf.1120", confFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.1120", 
confFile, e.getLocalizedMessage()));
               }
           } catch (ValidationException e) {
               /* TODO: Implement informative error handling here. 
  @@ -122,12 +122,12 @@
               /*
               NOTE: This doesn't seem to ever happen, anyone know why?
               */
  -            handleException("conf.1130", confFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.1130", 
confFile, e.getLocalizedMessage()));
           }
           try {
               reader.close();
           } catch (Exception e) {
  -            handleException("file.0020", confFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("file.0020", 
confFile, e.getLocalizedMessage()));
           }
           return obj;
       }
  @@ -146,12 +146,12 @@
               writer = new FileWriter(file);
               confObject.marshal(writer);
           } catch (IOException e) {
  -            handleException("conf.1040", confFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.1040", 
confFile, e.getLocalizedMessage()));
           } catch (MarshalException e) {
               if (e.getException() instanceof IOException) {
  -                handleException("conf.1040", confFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.1040", 
confFile, e.getLocalizedMessage()));
               } else {
  -                handleException("conf.1050", confFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.1050", 
confFile, e.getLocalizedMessage()));
               }
           } catch (ValidationException e) {
               /* TODO: Implement informative error handling here. 
  @@ -165,129 +165,12 @@
                * is invalid, the MarshalException is thrown, not this one as 
you
                * would think.
                */
  -            handleException("conf.1060", confFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.1060", 
confFile, e.getLocalizedMessage()));
           }
           try {
               writer.close();
           } catch (Exception e) {
  -            handleException("file.0020", confFile, e.getLocalizedMessage());
  -        }
  -    }
  -
  -    /**
  -     * Opens the specified jar file, locates the openejb-jar.xml file,
  -     * unmarshals it to a java object and returns it. If there is no
  -     * openejb-jar.xml in the jar an exception will be thrown.
  -     *
  -     * @param jarFile
  -     * @return OpenejbJar
  -     * @throws OpenEJBException
  -     */
  -    public static OpenejbJar readOpenejbJar(String jarFile) throws 
OpenEJBException {
  -
  -        /*[1.1]  Get the jar ***************/
  -        JarFile jar = JarUtils.getJarFile(jarFile);
  -
  -        /*[1.2]  Find the openejb-jar.xml from the jar ***************/
  -        JarEntry entry = jar.getJarEntry("META-INF/openejb-jar.xml");
  -        if (entry == null) entry = jar.getJarEntry("openejb-jar.xml");
  -//        if (entry == null) handleException("conf.2900", jarFile, "no 
message");
  -        if (entry == null) return null;
  -
  -        /*[1.3]  Get the openejb-jar.xml from the jar ***************/
  -        Reader reader = null;
  -        InputStream stream = null;
  -        try {
  -            stream = jar.getInputStream(entry);
  -            reader = new InputStreamReader(stream);
  -        } catch (Exception e) {
  -            handleException("conf.2110", jarFile, e.getLocalizedMessage());
  -        }
  -
  -        /*[1.4]  Get the OpenejbJar from the openejb-jar.xml ***************/
  -        OpenejbJar obj = null;
  -        try {
  -            Unmarshaller unmarshaller = new Unmarshaller(OpenejbJar.class);
  -            unmarshaller.setWhitespacePreserve(true);
  -            obj = (OpenejbJar) unmarshaller.unmarshal(reader);
  -        } catch (MarshalException e) {
  -            if (e.getException() instanceof IOException) {
  -                handleException("conf.2110", jarFile, 
e.getLocalizedMessage());
  -            } else if (e.getException() instanceof UnknownHostException) {
  -                handleException("conf.2121", jarFile, 
e.getLocalizedMessage());
  -            } else {
  -                handleException("conf.2120", jarFile, 
e.getLocalizedMessage());
  -            }
  -        } catch (ValidationException e) {
  -            handleException("conf.2130", jarFile, e.getLocalizedMessage());
  -        }
  -        
  -        /*[1.5]  Clean up ***************/
  -        try {
  -            stream.close();
  -            reader.close();
  -            jar.close();
  -        } catch (Exception e) {
  -            handleException("file.0020", jarFile, e.getLocalizedMessage());
  -        }
  -
  -        return obj;
  -    }
  -
  -    public static boolean checkForOpenejbJar(String jarFile) throws 
OpenEJBException {
  -        /*[1.1]  Get the jar ***************/
  -        JarFile jar = JarUtils.getJarFile(jarFile);
  -
  -        /*[1.2]  Find the openejb-jar.xml from the jar ***************/
  -        JarEntry entry = jar.getJarEntry("META-INF/openejb-jar.xml");
  -        if (entry == null) entry = jar.getJarEntry("openejb-jar.xml");
  -        if (entry == null) return false;
  -
  -        return true;
  -    }
  -
  -    public static void writeOpenejbJar(String xmlFile, OpenejbJar 
openejbJarObject) throws OpenEJBException {
  -        /* TODO:  Just to be picky, the xml file created by
  -        Castor is really hard to read -- it is all on one line.
  -        People might want to edit this in the future by hand, so if Castor 
can 
  -        make the output look better that would be great!  Otherwise we could
  -        just spruce the output up by adding a few new lines and tabs.
  -        */
  -        Writer writer = null;
  -        try {
  -            File file = new File(xmlFile);
  -            File dirs = file.getParentFile();
  -            if (dirs != null) dirs.mkdirs();
  -            writer = new FileWriter(file);
  -            openejbJarObject.marshal(writer);
  -        } catch (SecurityException e) {
  -            handleException("conf.2040", xmlFile, e.getLocalizedMessage());
  -        } catch (IOException e) {
  -            handleException("conf.2040", xmlFile, e.getLocalizedMessage());
  -        } catch (MarshalException e) {
  -            if (e.getException() instanceof IOException) {
  -                handleException("conf.2040", xmlFile, 
e.getLocalizedMessage());
  -            } else {
  -                handleException("conf.2050", xmlFile, 
e.getLocalizedMessage());
  -            }
  -        } catch (ValidationException e) {
  -            /* TODO: Implement informative error handling here. 
  -               The exception will say "X doesn't match the regular 
  -               expression Y" 
  -               This should be checked and more relevant information
  -               should be given -- not everyone understands regular 
  -               expressions. 
  -             */
  -            /* NOTE: This doesn't seem to ever happen. When the object graph
  -             * is invalid, the MarshalException is thrown, not this one as 
you
  -             * would think.
  -             */
  -            handleException("conf.2060", xmlFile, e.getLocalizedMessage());
  -        }
  -        try {
  -            writer.close();
  -        } catch (Exception e) {
  -            handleException("file.0020", xmlFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("file.0020", 
confFile, e.getLocalizedMessage()));
           }
       }
   
  @@ -345,7 +228,7 @@
   
           }
   
  -        _logger.warning("Cannot find the configuration file [" + path + "], 
Trying conf/openejb.conf instead.");
  +        logger.warning("Cannot find the configuration file [" + path + "], 
Trying conf/openejb.conf instead.");
   
           try {
               /*
  @@ -372,7 +255,7 @@
               } catch (java.io.FileNotFoundException e) {
               }
   
  -            _logger.warning("Cannot find the configuration file 
[conf/openejb.conf], Creating one.");
  +            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 
  @@ -472,53 +355,4 @@
           config.addDeployments(dep);
           return true;
       }
  -
  -    /*------------------------------------------------------*/
  -    /*    Methods for easy exception handling               */
  -    /*------------------------------------------------------*/
  -    public static void handleException(String errorCode, Object arg0, Object 
arg1, Object arg2, Object arg3) throws OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0, arg1, 
arg2, arg3));
  -    }
  -
  -    public static void handleException(String errorCode, Object arg0, Object 
arg1, Object arg2) throws OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0, arg1, 
arg2));
  -    }
  -
  -    public static void handleException(String errorCode, Object arg0, Object 
arg1) throws OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0, arg1));
  -    }
  -
  -    public static void handleException(String errorCode, Object arg0) throws 
OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0));
  -    }
  -
  -    public static void handleException(String errorCode) throws 
OpenEJBException {
  -        throw new OpenEJBException(messages.message(errorCode));
  -    }
  -
  -    /*------------------------------------------------------*/
  -    /*  Methods for logging exceptions that are noteworthy  */
  -    /*  but not bad enough to stop the container system.    */
  -    /*------------------------------------------------------*/
  -    public static void logWarning(String errorCode, Object arg0, Object 
arg1, Object arg2, Object arg3) {
  -        _logger.i18n.warning(errorCode, arg0, arg1, arg2, arg3);
  -    }
  -
  -    public static void logWarning(String errorCode, Object arg0, Object 
arg1, Object arg2) {
  -        _logger.i18n.warning(errorCode, arg0, arg1, arg2);
  -    }
  -
  -    public static void logWarning(String errorCode, Object arg0, Object 
arg1) {
  -        _logger.i18n.warning(errorCode, arg0, arg1);
  -    }
  -
  -    public static void logWarning(String errorCode, Object arg0) {
  -        _logger.i18n.warning(errorCode, arg0);
  -    }
  -
  -    public static void logWarning(String errorCode) {
  -        _logger.i18n.warning(errorCode);
  -    }
  -
  -
   }
  
  
  
  1.16      +8 -11     
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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ConfigurationFactory.java 4 Aug 2005 01:20:06 -0000       1.15
  +++ ConfigurationFactory.java 4 Aug 2005 20:17:42 -0000       1.16
  @@ -250,7 +250,7 @@
                   initEnterpriseBeanInfos(jars[i]);
               } catch (Exception e) {
                   e.printStackTrace();
  -                ConfigUtils.logWarning("conf.0004", jars[i].jarURI, 
e.getMessage());
  +                ConfigUtils.logger.i18n.warning("conf.0004", jars[i].jarURI, 
e.getMessage());
               }
           }
   
  @@ -618,7 +618,7 @@
           int beansInEjbJar = 
jar.ejbJar.getEnterpriseBeans().getEnterpriseBeansItemCount();
   
           if (beansInEjbJar != beansDeployed) {
  -            ConfigUtils.logWarning("conf.0008", jar.jarURI, "" + 
beansInEjbJar, "" + beansDeployed);
  +            ConfigUtils.logger.i18n.warning("conf.0008", jar.jarURI, "" + 
beansInEjbJar, "" + beansDeployed);
               // Not all ejb in this jar have been deployed.
               // This jar cannot be loaded into the system and must
               // be skipped.
  @@ -644,10 +644,7 @@
   
               // Check For Duplicate Deployment IDs
               if (deploymentIds.contains(beans[i].ejbDeploymentId)) {
  -                ConfigUtils.logWarning("conf.0100",
  -                        beans[i].ejbDeploymentId,
  -                        jar.jarURI,
  -                        beans[i].ejbName);
  +                ConfigUtils.logger.i18n.warning("conf.0100", 
beans[i].ejbDeploymentId, jar.jarURI, beans[i].ejbName);
                   // No two deployments can have the same deployment ID
                   // the entire ejb jar is invalid and must be redeployed.
                   // This jar cannot be loaded into the system and must
  @@ -868,7 +865,7 @@
   
               // Check For Duplicate Container IDs
               if (securityRoles.contains(sr[i].getRoleName())) {
  -                ConfigUtils.logWarning("conf.0102", jar.jarURI, 
sr[i].getRoleName());
  +                ConfigUtils.logger.i18n.warning("conf.0102", jar.jarURI, 
sr[i].getRoleName());
               } else {
                   securityRoles.add(sr[i].getRoleName());
               }
  @@ -927,7 +924,7 @@
               sr[i].roleName = refs[i].getRoleName();
   
               if (sr[i].roleLink == null) {
  -                ConfigUtils.logWarning("conf.0009", sr[i].roleName, 
bean.ejbName, jar.jarURI);
  +                ConfigUtils.logger.i18n.warning("conf.0009", sr[i].roleName, 
bean.ejbName, jar.jarURI);
                   sr[i].roleLink = DEFAULT_SECURITY_ROLE;
               }
           }
  @@ -1266,7 +1263,7 @@
   
                   /* If there is no openejb-jar.xml attempt to auto deploy it.
                    */
  -                OpenejbJar openejbJar = 
ConfigUtils.readOpenejbJar(jarLocation);
  +                OpenejbJar openejbJar = ejbJarUtils.getOpenejbJar();
                   if (openejbJar == null) {
                       openejbJar = deployer.deploy(ejbJarUtils, jarLocation);
                   }
  @@ -1280,7 +1277,7 @@
                   /* Add it to the Vector ***************/
                   jarsVect.add(new DeployedJar(jarLocation, ejbJar, 
openejbJar));
               } catch (OpenEJBException e) {
  -                ConfigUtils.logWarning("conf.0004", jarLocation, 
e.getMessage());
  +                ConfigUtils.logger.i18n.warning("conf.0004", jarLocation, 
e.getMessage());
               }
           }
   
  
  
  
  1.10      +2 -2      
openejb1/modules/core/src/java/org/openejb/alt/config/Deploy.java
  
  Index: Deploy.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/Deploy.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Deploy.java       4 Aug 2005 01:20:06 -0000       1.9
  +++ Deploy.java       4 Aug 2005 20:17:42 -0000       1.10
  @@ -712,7 +712,7 @@
           out.println("Done collecting deployment information!");
   
           out.print("Creating the openejb-jar.xml file...");
  -        ConfigUtils.writeOpenejbJar("META-INF/openejb-jar.xml", openejbJar);
  +        EjbJarUtils.writeOpenejbJar("META-INF/openejb-jar.xml", openejbJar);
   
           out.println("done");
   
  
  
  
  1.7       +141 -12   
openejb1/modules/core/src/java/org/openejb/alt/config/EjbJarUtils.java
  
  Index: EjbJarUtils.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/EjbJarUtils.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EjbJarUtils.java  4 Aug 2005 01:20:06 -0000       1.6
  +++ EjbJarUtils.java  4 Aug 2005 20:17:42 -0000       1.7
  @@ -65,6 +65,7 @@
   import org.openejb.loader.SystemInstance;
   import org.openejb.alt.config.ejb11.EjbJar;
   import org.openejb.alt.config.ejb11.EnterpriseBeansItem;
  +import org.openejb.alt.config.ejb11.OpenejbJar;
   import org.openejb.alt.config.sys.Container;
   import org.openejb.util.FileUtils;
   import org.openejb.util.JarUtils;
  @@ -76,16 +77,81 @@
    */
   public class EjbJarUtils {
   
  -    protected static final Messages _messages = new 
Messages("org.openejb.util.resources");
  +    private static final Messages messages = new 
Messages("org.openejb.util.resources");
   
       private final EjbJar ejbJar;
  -    private String jarLocation;
  +    private final String jarLocation;
  +    private OpenejbJar openejbJar;
   
       // TODO Make this a plain EjbJar instance with String jarFile as 
constructor
       // TODO Add support for unpacked jars (jarFile is a directory)
       public EjbJarUtils(String jarLocation) throws OpenEJBException {
           /*[1.1]  Get the jar ***************/
           this.jarLocation = jarLocation;
  +        this.ejbJar = readEjbJar(jarLocation);
  +        this.openejbJar = readOpenEjbJar(jarLocation);
  +    }
  +
  +    /**
  +     * Opens the specified jar file, locates the openejb-jar.xml file,
  +     * unmarshals it to a java object and returns it.
  +     *
  +     * @param jarLocation
  +     * @return null if there is no openejb-jar.xml
  +     * @throws OpenEJBException
  +     */
  +    private OpenejbJar readOpenEjbJar(String jarLocation) throws 
OpenEJBException {
  +
  +        /*[1.1]  Get the jar ***************/
  +        JarFile jar = JarUtils.getJarFile(jarLocation);
  +
  +        /*[1.2]  Find the openejb-jar.xml from the jar ***************/
  +        JarEntry entry = jar.getJarEntry("META-INF/openejb-jar.xml");
  +        if (entry == null) entry = jar.getJarEntry("openejb-jar.xml");
  +//        if (entry == null) handleException("conf.2900", jarFile, "no 
message");
  +        if (entry == null) return null;
  +
  +        /*[1.3]  Get the openejb-jar.xml from the jar ***************/
  +        Reader reader = null;
  +        InputStream stream = null;
  +        try {
  +            stream = jar.getInputStream(entry);
  +            reader = new InputStreamReader(stream);
  +        } catch (Exception e) {
  +            handleException("conf.2110", jarLocation, 
e.getLocalizedMessage());
  +        }
  +
  +        /*[1.4]  Get the OpenejbJar from the openejb-jar.xml ***************/
  +        OpenejbJar obj = null;
  +        try {
  +            Unmarshaller unmarshaller = new Unmarshaller(OpenejbJar.class);
  +            unmarshaller.setWhitespacePreserve(true);
  +            obj = (OpenejbJar) unmarshaller.unmarshal(reader);
  +        } catch (MarshalException e) {
  +            if (e.getException() instanceof IOException) {
  +                handleException("conf.2110", jarLocation, 
e.getLocalizedMessage());
  +            } else if (e.getException() instanceof UnknownHostException) {
  +                handleException("conf.2121", jarLocation, 
e.getLocalizedMessage());
  +            } else {
  +                handleException("conf.2120", jarLocation, 
e.getLocalizedMessage());
  +            }
  +        } catch (ValidationException e) {
  +            handleException("conf.2130", jarLocation, 
e.getLocalizedMessage());
  +        }
  +
  +        /*[1.5]  Clean up ***************/
  +        try {
  +            stream.close();
  +            reader.close();
  +            jar.close();
  +        } catch (Exception e) {
  +            handleException("file.0020", jarLocation, 
e.getLocalizedMessage());
  +        }
  +
  +        return obj;
  +    }
  +
  +    private EjbJar readEjbJar(String jarLocation) throws OpenEJBException {
           JarFile jar = JarUtils.getJarFile(jarLocation);
   
           /*[1.2]  Find the ejb-jar.xml from the jar ***************/
  @@ -130,8 +196,7 @@
           } catch (Exception e) {
               handleException("file.0020", jarLocation, 
e.getLocalizedMessage());
           }
  -
  -        this.ejbJar = obj;
  +        return obj;
       }
   
       public String getJarLocation() {
  @@ -142,6 +207,14 @@
           return ejbJar;
       }
   
  +    public OpenejbJar getOpenejbJar() {
  +        return openejbJar;
  +    }
  +
  +    public void setOpenejbJar(OpenejbJar openejbJar) {
  +        this.openejbJar = openejbJar;
  +    }
  +
       private static DTDResolver resolver = new DTDResolver();
   
       private EjbJar unmarshalEjbJar(java.io.Reader reader)
  @@ -226,7 +299,7 @@
                   if (overwrite) {
                       newFile.delete();
                   } else {
  -                    throw new 
OpenEJBException(_messages.format("deploy.m.061", origFile.getAbsolutePath(), 
beansDir.getAbsolutePath()));
  +                    throw new 
OpenEJBException(messages.format("deploy.m.061", origFile.getAbsolutePath(), 
beansDir.getAbsolutePath()));
                   }
               }
               moved = origFile.renameTo(newFile);
  @@ -276,7 +349,7 @@
                   if (overwrite) {
                       newFile.delete();
                   } else {
  -                    throw new 
OpenEJBException(_messages.format("deploy.c.061", origFile.getAbsolutePath(), 
beansDir.getAbsolutePath()));
  +                    throw new 
OpenEJBException(messages.format("deploy.c.061", origFile.getAbsolutePath(), 
beansDir.getAbsolutePath()));
                   }
               }
   
  @@ -333,23 +406,79 @@
       /*    Methods for easy exception handling               */
       /*------------------------------------------------------*/
       public static void handleException(String errorCode, Object arg0, Object 
arg1, Object arg2, Object arg3) throws OpenEJBException {
  -        throw new OpenEJBException(_messages.format(errorCode, arg0, arg1, 
arg2, arg3));
  +        throw new OpenEJBException(messages.format(errorCode, arg0, arg1, 
arg2, arg3));
       }
   
       public static void handleException(String errorCode, Object arg0, Object 
arg1, Object arg2) throws OpenEJBException {
  -        throw new OpenEJBException(_messages.format(errorCode, arg0, arg1, 
arg2));
  +        throw new OpenEJBException(messages.format(errorCode, arg0, arg1, 
arg2));
       }
   
       public static void handleException(String errorCode, Object arg0, Object 
arg1) throws OpenEJBException {
  -        throw new OpenEJBException(_messages.format(errorCode, arg0, arg1));
  +        throw new OpenEJBException(messages.format(errorCode, arg0, arg1));
       }
   
       public static void handleException(String errorCode, Object arg0) throws 
OpenEJBException {
  -        throw new OpenEJBException(_messages.format(errorCode, arg0));
  +        throw new OpenEJBException(messages.format(errorCode, arg0));
       }
   
       public static void handleException(String errorCode) throws 
OpenEJBException {
  -        throw new OpenEJBException(_messages.message(errorCode));
  +        throw new OpenEJBException(messages.message(errorCode));
       }
   
  +    public static boolean checkForOpenejbJar(String jarFile) throws 
OpenEJBException {
  +        /*[1.1]  Get the jar ***************/
  +        JarFile jar = JarUtils.getJarFile(jarFile);
  +
  +        /*[1.2]  Find the openejb-jar.xml from the jar ***************/
  +        JarEntry entry = jar.getJarEntry("META-INF/openejb-jar.xml");
  +        if (entry == null) entry = jar.getJarEntry("openejb-jar.xml");
  +        if (entry == null) return false;
  +
  +        return true;
  +    }
  +
  +    public static void writeOpenejbJar(String xmlFile, OpenejbJar 
openejbJarObject) throws OpenEJBException {
  +        /* TODO:  Just to be picky, the xml file created by
  +        Castor is really hard to read -- it is all on one line.
  +        People might want to edit this in the future by hand, so if Castor 
can
  +        make the output look better that would be great!  Otherwise we could
  +        just spruce the output up by adding a few new lines and tabs.
  +        */
  +        Writer writer = null;
  +        try {
  +            File file = new File(xmlFile);
  +            File dirs = file.getParentFile();
  +            if (dirs != null) dirs.mkdirs();
  +            writer = new FileWriter(file);
  +            openejbJarObject.marshal(writer);
  +        } catch (SecurityException e) {
  +            throw new OpenEJBException(messages.format("conf.2040", xmlFile, 
e.getLocalizedMessage()));
  +        } catch (IOException e) {
  +            throw new OpenEJBException(messages.format("conf.2040", xmlFile, 
e.getLocalizedMessage()));
  +        } catch (MarshalException e) {
  +            if (e.getException() instanceof IOException) {
  +                throw new OpenEJBException(messages.format("conf.2040", 
xmlFile, e.getLocalizedMessage()));
  +            } else {
  +                throw new OpenEJBException(messages.format("conf.2050", 
xmlFile, e.getLocalizedMessage()));
  +            }
  +        } catch (ValidationException e) {
  +            /* TODO: Implement informative error handling here.
  +               The exception will say "X doesn't match the regular
  +               expression Y"
  +               This should be checked and more relevant information
  +               should be given -- not everyone understands regular
  +               expressions.
  +             */
  +            /* NOTE: This doesn't seem to ever happen. When the object graph
  +             * is invalid, the MarshalException is thrown, not this one as 
you
  +             * would think.
  +             */
  +            throw new OpenEJBException(messages.format("conf.2060", xmlFile, 
e.getLocalizedMessage()));
  +        }
  +        try {
  +            writer.close();
  +        } catch (Exception e) {
  +            throw new OpenEJBException(messages.format("file.0020", xmlFile, 
e.getLocalizedMessage()));
  +        }
  +    }
   }
  
  
  
  1.7       +21 -72    
openejb1/modules/core/src/java/org/openejb/alt/config/ServiceUtils.java
  
  Index: ServiceUtils.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/ServiceUtils.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ServiceUtils.java 9 Jul 2005 05:14:47 -0000       1.6
  +++ ServiceUtils.java 4 Aug 2005 20:17:42 -0000       1.7
  @@ -122,8 +122,8 @@
   
       public static final String defaultProviderURL = "org.openejb";
       private static Map loadedServiceJars = new HashMap();
  -    private static Messages messages = new 
Messages("org.openejb.util.resources");
  -    private static Logger _logger = Logger.getInstance("OpenEJB", 
"org.openejb.util.resources");
  +    public static Messages messages = new 
Messages("org.openejb.util.resources");
  +    public static Logger logger = Logger.getInstance("OpenEJB", 
"org.openejb.util.resources");
   
   
       public static ServiceProvider getServiceProvider(Service service) throws 
OpenEJBException {
  @@ -175,7 +175,7 @@
           }
   
           if (service == null) {
  -            handleException("conf.4901", serviceName, providerName);
  +            throw new OpenEJBException(messages.format("conf.4901", 
serviceName, providerName));
           }
   
           return service;
  @@ -203,7 +203,7 @@
               stream = new 
URL(servicejarPath).openConnection().getInputStream();
               reader = new InputStreamReader(stream);
           } catch (Exception e) {
  -            handleException("conf.4110", servicejarPath, 
e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.4110", 
servicejarPath, e.getLocalizedMessage()));
           }
   
           /*[1.4]  Get the ServicesJar from the service-jar.xml 
***************/
  @@ -215,14 +215,14 @@
               obj = (ServicesJar) unmarshaller.unmarshal(reader);
           } catch (MarshalException e) {
               if (e.getException() instanceof IOException) {
  -                handleException("conf.4110", servicejarPath, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.4110", 
servicejarPath, e.getLocalizedMessage()));
               } else if (e.getException() instanceof UnknownHostException) {
  -                handleException("conf.4121", servicejarPath, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.4121", 
servicejarPath, e.getLocalizedMessage()));
               } else {
  -                handleException("conf.4120", providerName, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.4120", 
providerName, e.getLocalizedMessage()));
               }
           } catch (ValidationException e) {
  -            handleException("conf.4130", providerName, 
e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.4130", 
providerName, e.getLocalizedMessage()));
           }
   
           /*[1.5]  Clean up ***************/
  @@ -230,7 +230,7 @@
               stream.close();
               reader.close();
           } catch (Exception e) {
  -            handleException("file.0010", servicejarPath, 
e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("file.0010", 
servicejarPath, e.getLocalizedMessage()));
           }
   
           return obj;
  @@ -251,12 +251,12 @@
               writer = new FileWriter(file);
               servicesJarObject.marshal(writer);
           } catch (IOException e) {
  -            handleException("conf.4040", xmlFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.4040", xmlFile, 
e.getLocalizedMessage()));
           } catch (MarshalException e) {
               if (e.getException() instanceof IOException) {
  -                handleException("conf.4040", xmlFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.4040", 
xmlFile, e.getLocalizedMessage()));
               } else {
  -                handleException("conf.4050", xmlFile, 
e.getLocalizedMessage());
  +                throw new OpenEJBException(messages.format("conf.4050", 
xmlFile, e.getLocalizedMessage()));
               }
           } catch (ValidationException e) {
   
  @@ -273,13 +273,13 @@
                * would think.
                */
   
  -            handleException("conf.4060", xmlFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.4060", xmlFile, 
e.getLocalizedMessage()));
           }
   
           try {
               writer.close();
           } catch (Exception e) {
  -            handleException("file.0020", xmlFile, e.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("file.0020", xmlFile, 
e.getLocalizedMessage()));
           }
       }
   
  @@ -307,10 +307,7 @@
                   props = loadProperties(in, props);
               }
           } catch (OpenEJBException ex) {
  -            ConfigUtils.handleException("conf.0013",
  -                    service.getId(),
  -                    null,
  -                    ex.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.0013", 
service.getId(), null, ex.getLocalizedMessage()));
           }
   
           /* 3. Load properties from the content in the Container
  @@ -322,7 +319,7 @@
                   props = loadProperties(in, props);
               }
           } catch (OpenEJBException ex) {
  -            ConfigUtils.handleException("conf.0014", confItem, itemId, 
confFile, ex.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.0014", 
confItem, itemId, confFile, ex.getLocalizedMessage()));
           }
   
           return props;
  @@ -338,14 +335,12 @@
               InputStream in = new FileInputStream(pfile);
               return loadProperties(in, defaults);
           } catch (FileNotFoundException ex) {
  -            ConfigUtils.handleException("conf.0006", propertiesFile, 
ex.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.0006", 
propertiesFile, ex.getLocalizedMessage()));
           } catch (IOException ex) {
  -            ConfigUtils.handleException("conf.0007", propertiesFile, 
ex.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.0007", 
propertiesFile, ex.getLocalizedMessage()));
           } catch (SecurityException ex) {
  -            ConfigUtils.handleException("conf.0005", propertiesFile, 
ex.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.0005", 
propertiesFile, ex.getLocalizedMessage()));
           }
  -
  -        return defaults;
       }
   
       public static Properties loadProperties(InputStream in, Properties 
defaults)
  @@ -360,56 +355,10 @@
               */
               defaults.load(in);
           } catch (IOException ex) {
  -            ConfigUtils.handleException("conf.0012", 
ex.getLocalizedMessage());
  +            throw new OpenEJBException(messages.format("conf.0012", 
ex.getLocalizedMessage()));
           }
   
           return defaults;
       }
   
  -    /*------------------------------------------------------*/
  -    /*    Methods for easy exception handling               */
  -    /*------------------------------------------------------*/
  -    public static void handleException(String errorCode, Object arg0, Object 
arg1, Object arg2, Object arg3) throws OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0, arg1, 
arg2, arg3));
  -    }
  -
  -    public static void handleException(String errorCode, Object arg0, Object 
arg1, Object arg2) throws OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0, arg1, 
arg2));
  -    }
  -
  -    public static void handleException(String errorCode, Object arg0, Object 
arg1) throws OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0, arg1));
  -    }
  -
  -    public static void handleException(String errorCode, Object arg0) throws 
OpenEJBException {
  -        throw new OpenEJBException(messages.format(errorCode, arg0));
  -    }
  -
  -    public static void handleException(String errorCode) throws 
OpenEJBException {
  -        throw new OpenEJBException(messages.message(errorCode));
  -    }
  -
  -    /*------------------------------------------------------*/
  -    /*  Methods for logging exceptions that are noteworthy  */
  -    /*  but not bad enough to stop the container system.    */
  -    /*------------------------------------------------------*/
  -    public static void logWarning(String errorCode, Object arg0, Object 
arg1, Object arg2, Object arg3) {
  -        _logger.i18n.warning(errorCode, arg0, arg1, arg2, arg3);
  -    }
  -
  -    public static void logWarning(String errorCode, Object arg0, Object 
arg1, Object arg2) {
  -        _logger.i18n.warning(errorCode, arg0, arg1, arg2);
  -    }
  -
  -    public static void logWarning(String errorCode, Object arg0, Object 
arg1) {
  -        _logger.i18n.warning(errorCode, arg0, arg1);
  -    }
  -
  -    public static void logWarning(String errorCode, Object arg0) {
  -        _logger.i18n.warning(errorCode, arg0);
  -    }
  -
  -    public static void logWarning(String errorCode) {
  -        _logger.i18n.warning(errorCode);
  -    }
   }
  
  
  

Reply via email to