[jbpm-commits] JBoss JBPM SVN: r3334 - jbpm3/trunk/modules/core/src/main/java/org/jbpm/util.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 11 06:38:24 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-12-11 06:38:23 -0500 (Thu, 11 Dec 2008)
New Revision: 3334
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
Log:
[JBPM-1765] Unclosed InputStream in org.jbpm.util.ClassLoaderUtil.getProperties
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java 2008-12-11 11:32:22 UTC (rev 3333)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java 2008-12-11 11:38:23 UTC (rev 3334)
@@ -34,107 +34,126 @@
/**
* provides centralized classloader lookup.
*/
-public class ClassLoaderUtil {
+public class ClassLoaderUtil
+{
- private ClassLoaderUtil() {
+ private ClassLoaderUtil()
+ {
// hide default constructor to prevent instantiation
}
- public static Class loadClass(String className) {
- try {
+ public static Class loadClass(String className)
+ {
+ try
+ {
return getClassLoader().loadClass(className);
- } catch (ClassNotFoundException e) {
- throw new JbpmException("class not found '"+className+"'", e);
}
+ catch (ClassNotFoundException e)
+ {
+ throw new JbpmException("class not found '" + className + "'", e);
+ }
}
-
- /**
- * returns the {@link ClassLoader} which is used in jbpm.
- * Can be configured in jbpm.cfg.xml by the property
- * <b>'jbpm.classloader'</b>
- *
- * <td>
- * <li>'jbpm': (default value) uses the {@link ClassLoaderUtil}.class.getClassLoader()
- * {@link ClassLoader}. This was the only behavior available before <a href="https://jira.jboss.org/jira/browse/JBPM-1148">JBPM-1148</a>.</li>
- *
- * <li>'context': uses the Thread.currentThread().getContextClassLoader().</li>
- *
- * <li>'custom': means that a ClassLoader class has to be provided in the property
- * <b>'jbpm.classloader.classname'</b></li>
- * </td>
+
+ /*
+ * returns the {@link ClassLoader} which is used in jbpm. Can be configured in jbpm.cfg.xml by the property <b>'jbpm.classloader'</b> <td> <li>'jbpm': (default value)
+ * uses the {@link ClassLoaderUtil}.class.getClassLoader() {@link ClassLoader}. This was the only behavior available before <a
+ * href="https://jira.jboss.org/jira/browse/JBPM-1148">JBPM-1148</a>.</li> <li>'context': uses the Thread.currentThread().getContextClassLoader().</li> <li>'custom':
+ * means that a ClassLoader class has to be provided in the property <b>'jbpm.classloader.classname'</b></li> </td>
*/
- public static ClassLoader getClassLoader() {
- if (JbpmConfiguration.Configs.hasObject("jbpm.classLoader")) {
+ public static ClassLoader getClassLoader()
+ {
+ if (JbpmConfiguration.Configs.hasObject("jbpm.classLoader"))
+ {
String jbpmClassloader = JbpmConfiguration.Configs.getString("jbpm.classLoader");
- if (jbpmClassloader.equals("jbpm")) {
+ if (jbpmClassloader.equals("jbpm"))
+ {
return ClassLoaderUtil.class.getClassLoader();
- } else if (jbpmClassloader.equals("context")) {
+ }
+ else if (jbpmClassloader.equals("context"))
+ {
return Thread.currentThread().getContextClassLoader();
- } else if (jbpmClassloader.equals("custom")) {
+ }
+ else if (jbpmClassloader.equals("custom"))
+ {
String jbpmClassloaderClassname = null;
- try {
- if (!JbpmConfiguration.Configs.hasObject("jbpm.customClassLoader.className")) {
+ try
+ {
+ if (!JbpmConfiguration.Configs.hasObject("jbpm.customClassLoader.className"))
+ {
throw new JbpmException("'jbpm.classloader' property set to 'custom' but 'jbpm.customClassLoader.className' is empty!");
}
jbpmClassloaderClassname = JbpmConfiguration.Configs.getString("jbpm.customClassLoader.className");
- if (jbpmClassloaderClassname == null) {
+ if (jbpmClassloaderClassname == null)
+ {
throw new JbpmException("'jbpm.classloader' property set to 'custom' but 'jbpm.customClassLoader.className' is empty!");
}
-
+
Class clazz = ClassLoaderUtil.class.getClassLoader().loadClass(jbpmClassloaderClassname);
- if (clazz==null)
+ if (clazz == null)
clazz = Thread.currentThread().getContextClassLoader().loadClass(jbpmClassloaderClassname);
-
- return (ClassLoader) clazz.newInstance();
- } catch (InstantiationException e) {
+
+ return (ClassLoader)clazz.newInstance();
+ }
+ catch (InstantiationException e)
+ {
throw new JbpmException("Error instantiating custom classloader " + jbpmClassloaderClassname, e);
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e)
+ {
throw new JbpmException("Error accessing custom classloader " + jbpmClassloaderClassname, e);
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
throw new JbpmException("Custom classloader " + jbpmClassloaderClassname + " not found ", e);
}
- } else {
+ }
+ else
+ {
throw new JbpmException("'jbpm.classloader' property set to '" + jbpmClassloader + "' but only the values 'jbpm'/'context'/'custom' are supported!");
}
- } else {
- // default behavior like before https://jira.jboss.org/jira/browse/JBPM-1148
+ }
+ else
+ {
+ // default behavior like before https://jira.jboss.org/jira/browse/JBPM-1148
return ClassLoaderUtil.class.getClassLoader();
}
}
-
- public static InputStream getStream(String resource) {
- return getClassLoader().getResourceAsStream(resource);
+
+ public static InputStream getStream(String resource)
+ {
+ return getClassLoader().getResourceAsStream(resource);
}
-
- /**
- * Load jbpm configuration related resources as stream (normally jbpm.cfg.xml).
- *
- * This method first tries to load the resource from the {@link ClassLoaderUtil}
- * class loader, if not found it tries the context class loader.
- *
- * If this doesn't return any ressource the call is delegated to the class
- * loader configured by calling getClassLoader().
- *
- * This is a special method because the class loader which has to be used
- * for loading the jbpm.cfg.xml cannot be configured in the jbpm.cfg.xml
- * itself.
+
+ /*
+ * Load jbpm configuration related resources as stream (normally jbpm.cfg.xml). This method first tries to load the resource from the {@link ClassLoaderUtil} class
+ * loader, if not found it tries the context class loader. If this doesn't return any ressource the call is delegated to the class loader configured by calling
+ * getClassLoader(). This is a special method because the class loader which has to be used for loading the jbpm.cfg.xml cannot be configured in the jbpm.cfg.xml
+ * itself.
*/
- public static InputStream getJbpmConfigurationStream(String resource) {
+ public static InputStream getJbpmConfigurationStream(String resource)
+ {
InputStream jbpmCfgStream = ClassLoaderUtil.class.getClassLoader().getResourceAsStream(resource);
- if (jbpmCfgStream==null) {
+ if (jbpmCfgStream == null)
+ {
jbpmCfgStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
}
return jbpmCfgStream;
}
-
- public static Properties getProperties(String resource) {
+
+ public static Properties getProperties(String resource)
+ {
Properties properties = new Properties();
- try {
- properties.load(getStream(resource));
- } catch (IOException e) {
- throw new JbpmException("couldn't load properties file '"+resource+"'", e);
+ try
+ {
+ InputStream inStream = getStream(resource);
+ properties.load(inStream);
+ inStream.close();
}
+ catch (IOException e)
+ {
+ throw new JbpmException("couldn't load properties file '" + resource + "'", e);
+ }
return properties;
}
}
More information about the jbpm-commits
mailing list