geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r432515 - in /geronimo/xbean/trunk/xbean-server/src: main/java/org/apache/xbean/server/spring/configuration/ test/java/org/apache/xbean/server/spring/loader/ test/resources/org/apache/xbean/server/spring/loader/
Date Fri, 18 Aug 2006 08:26:24 GMT
Author: gnodet
Date: Fri Aug 18 01:26:24 2006
New Revision: 432515

URL: http://svn.apache.org/viewvc?rev=432515&view=rev
Log:
XBEAN-19: enable inverse classloading with the classpath element

Modified:
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/ClassLoaderXmlPreprocessor.java
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/spring/loader/SpringLoaderTest.java
    geronimo/xbean/trunk/xbean-server/src/test/resources/org/apache/xbean/server/spring/loader/classpath-xbean.xml

Modified: geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/ClassLoaderXmlPreprocessor.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/ClassLoaderXmlPreprocessor.java?rev=432515&r1=432514&r2=432515&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/ClassLoaderXmlPreprocessor.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/ClassLoaderXmlPreprocessor.java
Fri Aug 18 01:26:24 2006
@@ -21,11 +21,11 @@
 import java.util.List;
 import java.util.ListIterator;
 
-import org.apache.xbean.server.classloader.MultiParentClassLoader;
+import org.apache.xbean.server.classloader.JarFileClassLoader;
 import org.apache.xbean.server.repository.Repository;
 import org.apache.xbean.server.spring.loader.SpringLoader;
-import org.apache.xbean.spring.context.SpringXmlPreprocessor;
 import org.apache.xbean.spring.context.SpringApplicationContext;
+import org.apache.xbean.spring.context.SpringXmlPreprocessor;
 import org.springframework.beans.FatalBeanException;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.w3c.dom.Document;
@@ -73,17 +73,41 @@
             throw new FatalBeanException("Expected only classpath element but found " + classpathElements.getLength());
         } else {
             Element classpathElement = (Element) classpathElements.item(0);
+            
+            // Delegation mode
+            boolean inverse = false;
+            String inverseAttr = classpathElement.getAttribute("inverse");
+            if (inverseAttr != null && "true".equalsIgnoreCase(inverseAttr)) {
+                inverse = true;
+            }
+
+            // build hidden classes
+            List hidden = new ArrayList();
+            NodeList hiddenElems = classpathElement.getElementsByTagName("hidden");
+            for (int i = 0; i < hiddenElems.getLength(); i++) {
+                Element hiddenElement = (Element) hiddenElems.item(i);
+                String pattern = ((Text) hiddenElement.getFirstChild()).getData().trim();
+                hidden.add(pattern);
+            }
+
+            // build non overridable classes
+            List nonOverridable = new ArrayList();
+            NodeList nonOverridableElems = classpathElement.getElementsByTagName("nonOverridable");
+            for (int i = 0; i < nonOverridableElems.getLength(); i++) {
+                Element nonOverridableElement = (Element) nonOverridableElems.item(i);
+                String pattern = ((Text) nonOverridableElement.getFirstChild()).getData().trim();
+                nonOverridable.add(pattern);
+            }
 
             // build the classpath
             List classpath = new ArrayList();
             NodeList locations = classpathElement.getElementsByTagName("location");
             for (int i = 0; i < locations.getLength(); i++) {
                 Element locationElement = (Element) locations.item(i);
-
                 String location = ((Text) locationElement.getFirstChild()).getData().trim();
                 classpath.add(location);
             }
-
+            
             // convert the paths to URLS
             URL[] urls = new URL[classpath.size()];
             for (ListIterator iterator = classpath.listIterator(); iterator.hasNext();) {
@@ -97,7 +121,12 @@
 
             // create the classloader
             ClassLoader parentLoader = getClassLoader(applicationContext);
-            classLoader = new MultiParentClassLoader(applicationContext.getDisplayName(),
urls, parentLoader);
+            classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), 
+                                                 urls, 
+                                                 parentLoader,
+                                                 inverse,
+                                                 (String[]) hidden.toArray(new String[hidden.size()]),
+                                                 (String[]) nonOverridable.toArray(new String[nonOverridable.size()]));
 
             // remove the classpath element so Spring doesn't get confused
             document.getDocumentElement().removeChild(classpathElement);

Modified: geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/spring/loader/SpringLoaderTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/spring/loader/SpringLoaderTest.java?rev=432515&r1=432514&r2=432515&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/spring/loader/SpringLoaderTest.java
(original)
+++ geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/spring/loader/SpringLoaderTest.java
Fri Aug 18 01:26:24 2006
@@ -16,32 +16,35 @@
  */
 package org.apache.xbean.server.spring.loader;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collections;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
 import junit.framework.TestCase;
 import net.sf.cglib.core.DefaultGeneratorStrategy;
 import net.sf.cglib.core.NamingPolicy;
 import net.sf.cglib.core.Predicate;
 import net.sf.cglib.proxy.Enhancer;
 import net.sf.cglib.proxy.NoOp;
+
 import org.apache.xbean.kernel.Kernel;
 import org.apache.xbean.kernel.KernelFactory;
 import org.apache.xbean.kernel.ServiceName;
 import org.apache.xbean.kernel.StringServiceName;
+import org.apache.xbean.server.classloader.MultiParentClassLoader;
 import org.apache.xbean.server.repository.FileSystemRepository;
 import org.apache.xbean.server.spring.configuration.ClassLoaderXmlPreprocessor;
 import org.apache.xbean.server.spring.configuration.SpringConfigurationServiceFactory;
 import org.apache.xbean.spring.context.SpringApplicationContext;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Collections;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-
 /**
  * @author Dain Sundstrom
  * @version $Id$
@@ -76,6 +79,27 @@
             Object testService = kernel.getService(new StringServiceName("test"));
             assertEquals("TestClass", testService.getClass().getName());
             assertTrue(testService instanceof SortedSet);
+            
+            ClassLoader loader = kernel.getClassLoaderFor(new StringServiceName("test"));
+            assertNotNull(loader);
+            assertTrue(loader instanceof MultiParentClassLoader);
+            MultiParentClassLoader mpcl = (MultiParentClassLoader) loader;
+            Field f = MultiParentClassLoader.class.getDeclaredField("inverseClassLoading");
+            f.setAccessible(true);
+            assertEquals(Boolean.TRUE, f.get(mpcl));
+            f = MultiParentClassLoader.class.getDeclaredField("hiddenClasses");
+            f.setAccessible(true);
+            String[] hiddenClasses = (String[]) f.get(mpcl);
+            assertNotNull(hiddenClasses);
+            assertEquals(1, hiddenClasses.length);
+            assertEquals("org.apache.commons.logging.", hiddenClasses[0]);
+            f = MultiParentClassLoader.class.getDeclaredField("nonOverridableClasses");
+            f.setAccessible(true);
+            String[] nonOverridableClasses = (String[]) f.get(mpcl);
+            assertNotNull(nonOverridableClasses);
+            assertEquals(2, nonOverridableClasses.length);
+            assertEquals("java.", nonOverridableClasses[0]);
+            assertEquals("javax.", nonOverridableClasses[1]);
         } finally {
             kernel.destroy();
         }

Modified: geronimo/xbean/trunk/xbean-server/src/test/resources/org/apache/xbean/server/spring/loader/classpath-xbean.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-server/src/test/resources/org/apache/xbean/server/spring/loader/classpath-xbean.xml?rev=432515&r1=432514&r2=432515&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/src/test/resources/org/apache/xbean/server/spring/loader/classpath-xbean.xml
(original)
+++ geronimo/xbean/trunk/xbean-server/src/test/resources/org/apache/xbean/server/spring/loader/classpath-xbean.xml
Fri Aug 18 01:26:24 2006
@@ -1,7 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- START SNIPPET: xml -->
 <beans>
-  <classpath>
+  <classpath inverse="true">
+    <hidden>org.apache.commons.logging.</hidden>
+    <nonOverridable>java.</nonOverridable>
+    <nonOverridable>javax.</nonOverridable>
     <location>target/SpringLoaderTest.jar</location>
   </classpath>
 



Mime
View raw message