servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r962431 - /servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java
Date Fri, 09 Jul 2010 07:27:55 GMT
Author: jbonofre
Date: Fri Jul  9 07:27:55 2010
New Revision: 962431

URL: http://svn.apache.org/viewvc?rev=962431&view=rev
Log:
[SM-1901] Add file attribute to XBean <classpath/> element.

Modified:
    servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java

Modified: servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java?rev=962431&r1=962430&r2=962431&view=diff
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java
(original)
+++ servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java
Fri Jul  9 07:27:55 2010
@@ -68,11 +68,11 @@ public class ClassLoaderXmlPreprocessor 
         NodeList classpathElements = document.getDocumentElement().getElementsByTagName("classpath");
         if (classpathElements.getLength() == 0) {
             // Check if a classpath.xml file exists in the root of the SU
-            List<URL> classpathUrls = getResources(CLASSPATH_XML);
-            if (classpathUrls.size() == 1) {
+            URL url = getResource(CLASSPATH_XML);
+            if (url != null) {
                 try {
                     DocumentBuilder builder = new SourceTransformer().createDocumentBuilder();
-                    Document doc = builder.parse(classpathUrls.get(0).toString());
+                    Document doc = builder.parse(url.toString());
                     classLoader = getClassLoader(applicationContext, reader, doc);
                 } catch (Exception e) {
                     throw new FatalBeanException("Unable to load classpath.xml file", e);
@@ -139,6 +139,29 @@ public class ClassLoaderXmlPreprocessor 
 
     /**
      * <p>
+     * Get an URL from a String location.
+     * </p>
+     * 
+     * @param location
+     * @return
+     */
+    protected URL getResource(String location) {
+        URI uri = root.toURI().resolve(location);
+        File file = new File(uri);
+        
+        if (!file.canRead()) {
+            return null;
+        }
+        
+        try {
+            return file.toURL();
+        } catch (MalformedURLException e) {
+            throw new IllegalArgumentException("Malformed resource " + uri);
+        }
+    }
+    
+    /**
+     * <p>
      * Get the URLs for a classpath location. This method supports standard
      * relative file location, <code>file:</code> URL location (including entries
      * regexp filter support), <code>jar:</code> URL location (including entries
@@ -316,6 +339,21 @@ public class ClassLoaderXmlPreprocessor 
         } else {
             Element classpathElement = (Element) classpathElements.item(0);
             
+            String fileDelegation = classpathElement.getAttribute("file");
+            if (fileDelegation != null) {
+                URL url = getResource(fileDelegation);
+                if (url != null) {
+                    try {
+                        DocumentBuilder builder = new SourceTransformer().createDocumentBuilder();
+                        Document doc = builder.parse(url.toString());
+                        classLoader = getClassLoader(applicationContext, reader, doc);
+                        return classLoader;
+                    } catch (Exception e) {
+                        throw new FatalBeanException("Unable to load " + url + " file.",
e);
+                    }
+                }
+            }
+            
             // Delegation mode
             boolean inverse = false;
             String inverseAttr = classpathElement.getAttribute("inverse");



Mime
View raw message