harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r447818 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/XMLDecoder.java test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
Date Tue, 19 Sep 2006 11:22:41 GMT
Author: tellison
Date: Tue Sep 19 04:22:41 2006
New Revision: 447818

URL: http://svn.apache.org/viewvc?view=rev&rev=447818
Log:
Apply patches for HARMONY-1479 ([classlib][beans] missing constructors for XMLDecoder)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java?view=diff&rev=447818&r1=447817&r2=447818
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
Tue Sep 19 04:22:41 2006
@@ -13,11 +13,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Maxim V. Berkultsev
- * @version $Revision: 1.14.6.4 $
- */
 package java.beans;
 
 import java.io.InputStream;
@@ -33,11 +28,6 @@
 
 import org.apache.harmony.beans.Handler;
 
-/**
- * @author Maxim V. Berkultsev
- * @version $Revision: 1.14.6.4 $
- */
-
 public class XMLDecoder {
 
     private InputStream is = null;
@@ -49,10 +39,17 @@
     private Vector<Object> objects = new Vector<Object>();
 
     private Iterator<Object> iterator = null;
+    
+    private ClassLoader classLoader = null;
+
+    public XMLDecoder(InputStream is, Object owner,
+            ExceptionListener exceptionListener, ClassLoader cl) {
+        this.is = is;
+        this.owner = owner;
+        this.exceptionListener = exceptionListener;
+        this.classLoader = cl;
+    }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public XMLDecoder(InputStream is, Object owner,
             ExceptionListener exceptionListener) {
         this.is = is;
@@ -60,31 +57,19 @@
         this.exceptionListener = exceptionListener;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public XMLDecoder(InputStream is, Object owner) {
         this.is = is;
         this.owner = owner;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public XMLDecoder(InputStream is) {
         this.is = is;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setOwner(Object owner) {
         this.owner = owner;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public Object readObject() {
         try {
             if (iterator == null) {
@@ -96,30 +81,18 @@
         }
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public Object getOwner() {
         return owner;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void setExceptionListener(ExceptionListener exceptionListener) {
         this.exceptionListener = exceptionListener;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public ExceptionListener getExceptionListener() {
         return exceptionListener;
     }
 
-    /**
-     * @com.intel.drl.spec_ref
-     */
     public void close() {
         try {
             is.close();
@@ -135,6 +108,8 @@
     }
 
     private void initialize() {
+        ClassLoader oldCL = null;
+        
         try {
             String saxParserClassName = System
                     .getProperty("org.xml.sax.driver"); //$NON-NLS-1$
@@ -145,7 +120,14 @@
             XMLReader xmlReader = XMLReaderFactory
                     .createXMLReader(saxParserClassName);
             xmlReader.setContentHandler(new Handler(this, objects));
+            if (classLoader != null) {
+                oldCL = Thread.currentThread().getContextClassLoader();
+                Thread.currentThread().setContextClassLoader(classLoader);
+            }
             xmlReader.parse(new InputSource(is));
+            if (classLoader != null) {
+                Thread.currentThread().setContextClassLoader(oldCL);
+            }
         } catch (SAXException saxe) {
             saxe.printStackTrace();
             handleException(saxe);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java?view=diff&rev=447818&r1=447817&r2=447818
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
Tue Sep 19 04:22:41 2006
@@ -22,6 +22,7 @@
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.Vector;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -53,6 +54,45 @@
         enc.writeObject(Integer.valueOf("3"));
         enc.close();
         xml123bytes = byteout.toByteArray();
+    }
+
+    static class MockClassLoader extends ClassLoader {
+        public Class<?> loadClass(String name) throws ClassNotFoundException {
+            throw new ClassNotFoundException();
+        }
+        
+        protected Class<?> findClass(String name)
+                throws ClassNotFoundException {
+            throw new ClassNotFoundException();
+        }
+
+    }
+
+    public void testConstructor_ClassLoader() {
+        XMLDecoder dec;
+        final Vector<Exception> exceptions = new Vector<Exception>();
+
+        ExceptionListener el = new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                exceptions.addElement(e);
+            }
+        };
+        
+        dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this,
+              el, Thread.currentThread().getContextClassLoader());
+        assertEquals(Integer.valueOf("1"), dec.readObject());
+        assertEquals(0, exceptions.size());
+        dec.close();
+        
+        dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this,
+              el, new MockClassLoader());
+        try {
+            dec.readObject();
+            assertTrue(exceptions.size() > 0);
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // also valid
+        }
+        dec.close();
     }
 
     public void testClose() {



Mime
View raw message