Commits

Anonymous committed be663c9

Removed all external deps so it's possible to have the 'core' ps stuff in a higher level classloader and all the mucky impl stuff lower down

git-svn-id: http://svn.opensymphony.com/svn/propertyset/trunk@151bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

Comments (0)

Files changed (2)

src/java/com/opensymphony/module/propertyset/AbstractPropertySet.java

 
 import com.opensymphony.util.Data;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import org.w3c.dom.Document;
 
 import java.util.*;
  * @version $Revision$
  */
 public abstract class AbstractPropertySet implements PropertySet {
-    //~ Static fields/initializers /////////////////////////////////////////////
-
-    private static final Log logger = LogFactory.getLog(AbstractPropertySet.class);
-
     //~ Instance fields ////////////////////////////////////////////////////////
 
     protected PropertySetSchema schema;
                 return ((Data) data).getBytes();
             } else if (data instanceof byte[]) {
                 return (byte[]) data;
-            } else {
-                logger.error("DATA type is " + data.getClass() + ", expected byte[] or Data");
             }
         } catch (NullPointerException e) {
             return null;

src/java/com/opensymphony/module/propertyset/config/PropertySetConfig.java

  */
 package com.opensymphony.module.propertyset.config;
 
-import com.opensymphony.util.ClassLoaderUtil;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import org.w3c.dom.*;
 
 import org.xml.sax.SAXException;
 import java.io.IOException;
 import java.io.InputStream;
 
+import java.net.URL;
+
 import java.util.HashMap;
 import java.util.Map;
 
 
     private static PropertySetConfig config;
     private static final Object lock = new Object();
-    private static final Log log = LogFactory.getLog(PropertySetConfig.class);
     private static final String[] CONFIG_LOCATIONS = new String[] {
         "propertyset.xml", "/propertyset.xml", "META-INF/propertyset.xml",
         "/META-INF/propertyset.xml", "META-INF/propertyset-default.xml",
     }
 
     /**
+    * Load a given resource.
+    *
+    * This method will try to load the resource using the following methods (in order):
+    * <ul>
+    *  <li>From Thread.currentThread().getContextClassLoader()
+    *  <li>From ClassLoaderUtil.class.getClassLoader()
+    *  <li>callingClass.getClassLoader()
+    * </ul>
+    *
+    * @param resourceName The name of the resource to load
+    * @param callingClass The Class object of the calling object
+    */
+    public static URL getResource(String resourceName, Class callingClass) {
+        URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
+
+        if (url == null) {
+            url = PropertySetConfig.class.getClassLoader().getResource(resourceName);
+        }
+
+        if (url == null) {
+            ClassLoader cl = callingClass.getClassLoader();
+
+            if (cl != null) {
+                url = cl.getResource(resourceName);
+            }
+        }
+
+        if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) {
+            return getResource('/' + resourceName, callingClass);
+        }
+
+        return url;
+    }
+
+    /**
      * Load the config from locations found in {@link #CONFIG_LOCATIONS}
      *
      * @return  An inputstream to load from
             String location = CONFIG_LOCATIONS[i];
 
             try {
-                is = ClassLoaderUtil.getResourceAsStream(location, this.getClass());
+                URL resource = getResource(location, this.getClass());
+
+                if (resource != null) {
+                    is = resource.openStream();
+                }
 
                 //if we have found something then stop looking
                 if (is != null) {
 
         if (is == null) {
             String exceptionMessage = "Could not load propertyset config using '" + CONFIG_LOCATIONS + "'.  Please check your classpath.";
-            log.fatal(exceptionMessage);
             throw new IllegalArgumentException(exceptionMessage);
         }