[jboss-svn-commits] JBL Code SVN: r36843 - in labs/jbosstm/trunk: XTS/WS-C/dev/src/org/jboss/jbossts/xts/environment and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Mar 18 06:28:21 EDT 2011
Author: jhalliday
Date: 2011-03-18 06:28:20 -0400 (Fri, 18 Mar 2011)
New Revision: 36843
Modified:
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java
labs/jbosstm/trunk/XTS/WS-C/dev/src/org/jboss/jbossts/xts/environment/XTSPropertiesFactory.java
labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java
labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java
Log:
Classloading changes. JBTM-828
Modified: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java 2011-03-17 17:33:43 UTC (rev 36842)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java 2011-03-18 10:28:20 UTC (rev 36843)
@@ -137,7 +137,7 @@
try
{
- props = PropertiesFactory.getPropertiesFromFile(fileName);
+ props = PropertiesFactory.getPropertiesFromFile(fileName, BasicXARecovery.class.getClassLoader());
}
catch (Exception e)
{
Modified: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java 2011-03-17 17:33:43 UTC (rev 36842)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java 2011-03-18 10:28:20 UTC (rev 36843)
@@ -93,7 +93,7 @@
try
{
- _props = PropertiesFactory.getPropertiesFromFile(parameter);
+ _props = PropertiesFactory.getPropertiesFromFile(parameter, JDBCXARecovery.class.getClassLoader());
_dbName = _props.getProperty(DATABASE_JNDI_NAME);
_user = _props.getProperty(USER_NAME);
Modified: labs/jbosstm/trunk/XTS/WS-C/dev/src/org/jboss/jbossts/xts/environment/XTSPropertiesFactory.java
===================================================================
--- labs/jbosstm/trunk/XTS/WS-C/dev/src/org/jboss/jbossts/xts/environment/XTSPropertiesFactory.java 2011-03-17 17:33:43 UTC (rev 36842)
+++ labs/jbosstm/trunk/XTS/WS-C/dev/src/org/jboss/jbossts/xts/environment/XTSPropertiesFactory.java 2011-03-18 10:28:20 UTC (rev 36843)
@@ -58,18 +58,10 @@
}
// use the TS properties factory but supply the XTS property file name
- // we also need to set the context class loader in case we try to load
- // the fiel as a resource. this makes sure the resource load is performed
+ // we also need to pass the class loader in case we try to load
+ // the file as a resource. this makes sure the resource load is performed
// relative to the XTS deployment
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- try {
- ClassLoader xtsLoader = XTSPropertiesFactory.class.getClassLoader();
- Thread.currentThread().setContextClassLoader(xtsLoader);
- defaultProperties = PropertiesFactory.getPropertiesFromFile(propertyFileName);
- } finally {
- Thread.currentThread().setContextClassLoader(loader);
- }
+ defaultProperties = PropertiesFactory.getPropertiesFromFile(propertyFileName, XTSPropertiesFactory.class.getClassLoader());
}
}
Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java 2011-03-17 17:33:43 UTC (rev 36842)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java 2011-03-18 10:28:20 UTC (rev 36843)
@@ -52,155 +52,154 @@
class FileLocator
{
- /**
- * Locate the specific file.
- * Return the (URL decoded) abolute pathname to the file or null.
- */
- static String locateFile (String findFile) throws FileNotFoundException
- {
- URL url;
- String fullPathName;
- StringBuffer decodedPathName;
- int pos, len, start;
+ /**
+ * Locate the specific file.
+ * Return the (URL decoded) absolute pathname to the file or null.
+ */
+ static String locateFile (String findFile, ClassLoader classLoader) throws FileNotFoundException
+ {
+ URL url;
+ String fullPathName;
+ StringBuffer decodedPathName;
+ int pos, len, start;
- if (findFile == null)
- throw new FileNotFoundException("locateFile: null file name");
+ if (findFile == null)
+ throw new FileNotFoundException("locateFile: null file name");
- String testAbsolutePath = new File(findFile).getAbsolutePath();
- if(testAbsolutePath.equals(findFile)) {
- return testAbsolutePath;
- }
+ String testAbsolutePath = new File(findFile).getAbsolutePath();
+ if(testAbsolutePath.equals(findFile)) {
+ return testAbsolutePath;
+ }
- if (findFile.startsWith(absolutePath))
- return findFile.substring(absolutePath.length());
+ if (findFile.startsWith(absolutePath))
+ return findFile.substring(absolutePath.length());
- if ((fullPathName = locateByProperty(findFile)) != null)
- return fullPathName;
+ if ((fullPathName = locateByProperty(findFile)) != null)
+ return fullPathName;
- if ((url = locateByResource(findFile)) != null)
- {
- /*
- * The URL that we receive from getResource /might/ have ' '
- * (space) characters converted to "%20" strings. However,
- * it doesn't have other URL encoding (e.g '+' characters are
- * kept intact), so we'll just convert all "%20" strings to
- * ' ' characters and hope for the best.
- */
- fullPathName = url.getFile();
- pos = 0;
- len = fullPathName.length();
- start = 0;
- decodedPathName = new StringBuffer();
+ if ((url = locateByResource(findFile, classLoader)) != null)
+ {
+ /*
+ * The URL that we receive from getResource /might/ have ' '
+ * (space) characters converted to "%20" strings. However,
+ * it doesn't have other URL encoding (e.g '+' characters are
+ * kept intact), so we'll just convert all "%20" strings to
+ * ' ' characters and hope for the best.
+ */
+ fullPathName = url.getFile();
+ pos = 0;
+ len = fullPathName.length();
+ start = 0;
+ decodedPathName = new StringBuffer();
- while ((pos = fullPathName.indexOf(pct20, start)) != -1) {
- decodedPathName.append(fullPathName.substring(start, pos));
- decodedPathName.append(' ');
- start = pos + pct20len;
- }
+ while ((pos = fullPathName.indexOf(pct20, start)) != -1) {
+ decodedPathName.append(fullPathName.substring(start, pos));
+ decodedPathName.append(' ');
+ start = pos + pct20len;
+ }
- if (start < len)
- decodedPathName.append(fullPathName.substring(start, len));
+ if (start < len)
+ decodedPathName.append(fullPathName.substring(start, len));
- fullPathName=decodedPathName.toString();
+ fullPathName=decodedPathName.toString();
- if (platformIsWindows())
- fullPathName = fullPathName.substring(1, fullPathName.length());
+ if (platformIsWindows())
+ fullPathName = fullPathName.substring(1, fullPathName.length());
- return fullPathName;
- }
+ return fullPathName;
+ }
- throw new FileNotFoundException("locateFile: file not found: " + findFile);
- }
+ throw new FileNotFoundException("locateFile: file not found: " + findFile);
+ }
- /**
- * Search for a file using the properties: user.dir, user.home, java.home
- * Returns absolute path name or null.
- */
- private static synchronized String locateByProperty(String findFile)
- {
- String fullPathName = null;
- String dir = null;
- File f = null;
+ /**
+ * Search for a file using the properties: user.dir, user.home, java.home
+ * Returns absolute path name or null.
+ */
+ private static synchronized String locateByProperty(String findFile)
+ {
+ String fullPathName = null;
+ String dir = null;
+ File f = null;
- if (findFile == null)
- return null;
+ if (findFile == null)
+ return null;
- try
- {
- // System.err.println("Searching in user.dir for: " + findFile);
+ try
+ {
+ // System.err.println("Searching in user.dir for: " + findFile);
- dir = System.getProperty("user.dir");
- if (dir != null) {
- fullPathName = dir + File.separatorChar + findFile;
- f = new File(fullPathName);
- }
- if (f != null && f.exists())
- {
- // System.err.println("Found in user.dir");
- return fullPathName;
- }
+ dir = System.getProperty("user.dir");
+ if (dir != null) {
+ fullPathName = dir + File.separatorChar + findFile;
+ f = new File(fullPathName);
+ }
+ if (f != null && f.exists())
+ {
+ // System.err.println("Found in user.dir");
+ return fullPathName;
+ }
- dir = System.getProperty("user.home");
- if (dir != null) {
- fullPathName = dir + File.separatorChar + findFile;
- f = new File(fullPathName);
- }
- if (f != null && f.exists())
- {
- // System.err.println("Found in user.home");
- return fullPathName;
- }
+ dir = System.getProperty("user.home");
+ if (dir != null) {
+ fullPathName = dir + File.separatorChar + findFile;
+ f = new File(fullPathName);
+ }
+ if (f != null && f.exists())
+ {
+ // System.err.println("Found in user.home");
+ return fullPathName;
+ }
- dir = System.getProperty("java.home");
- if (dir != null) {
- fullPathName = dir + File.separatorChar + findFile;
- f = new File(fullPathName);
- }
- if (f != null && f.exists())
- {
- // System.err.println("Found in java.home");
- return fullPathName;
- }
- }
- catch (Exception e)
- {
- return null;
- }
- return null;
- }
+ dir = System.getProperty("java.home");
+ if (dir != null) {
+ fullPathName = dir + File.separatorChar + findFile;
+ f = new File(fullPathName);
+ }
+ if (f != null && f.exists())
+ {
+ // System.err.println("Found in java.home");
+ return fullPathName;
+ }
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ return null;
+ }
- /**
- * Search for a file using the properties: user.dir, user.home, java.home
- * Returns URL or null.
+ /**
+ * Search for a file using the properties: user.dir, user.home, java.home
+ * Returns URL or null.
+ */
+ private static URL locateByResource(String findFile, ClassLoader classLoader)
+ {
+ URL url = classLoader.getResource(findFile);
+ if (url == null)
+ {
+ url = FileLocator.class.getResource("/" + findFile);
+ }
+ // System.err.println("Search succeeded via getResource()");
+ return url;
+ }
+
+ /*
+ * Check the file separator to see if we're on a Windows platform.
+ *
+ * @return boolean True if the platform is Windows, false otherwise.
*/
- private static URL locateByResource(String findFile)
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- URL url = loader.getResource(findFile);
- if (url == null)
- {
- url = FileLocator.class.getResource("/" + findFile);
- }
- // System.err.println("Search succeeded via getResource()");
- return url;
- }
+ private static boolean platformIsWindows()
+ {
+ if(File.separatorChar == '\\')
+ {
+ return true;
+ }
+ return false;
+ }
- /*
- * Check the file separator to see if we're on a Windows platform.
- *
- * @return boolean True if the platform is Windows, false otherwise.
- */
- private static boolean platformIsWindows()
- {
- if(File.separatorChar == '\\')
- {
- return true;
- }
- return false;
- }
-
- private static final String absolutePath = "abs://";
- private static final String pct20 = "%20";
- private static final int pct20len = 3;
+ private static final String absolutePath = "abs://";
+ private static final String pct20 = "%20";
+ private static final int pct20len = 3;
}
Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java 2011-03-17 17:33:43 UTC (rev 36842)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java 2011-03-18 10:28:20 UTC (rev 36843)
@@ -65,14 +65,14 @@
* @param propertyFileName the file name. If relative, this is located using the FileLocator algorithm.
* @return the Properties loaded from the specified source.
*/
- public static Properties getPropertiesFromFile(String propertyFileName)
+ public static Properties getPropertiesFromFile(String propertyFileName, ClassLoader classLoader)
{
String filepath = null;
try
{
// Convert the possibly relative path into a canonical path, using FileLocator.
// This is the point where the search path is applied - user.dir (pwd), user.home, java.home, classpath
- filepath = com.arjuna.common.util.propertyservice.FileLocator.locateFile(propertyFileName);
+ filepath = com.arjuna.common.util.propertyservice.FileLocator.locateFile(propertyFileName, classLoader);
File propertyFile = new File(filepath);
if(!propertyFile.exists() || !propertyFile.isFile()) {
throw new RuntimeException("invalid property file "+filepath);
@@ -183,6 +183,6 @@
throw new RuntimeException("Unable to resolve property file name");
}
- defaultProperties = getPropertiesFromFile(propertyFileName);
+ defaultProperties = getPropertiesFromFile(propertyFileName, PropertiesFactory.class.getClassLoader());
}
}
More information about the jboss-svn-commits
mailing list