[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: Robert's fix for bean helper class

Kaffe CVS cvs-commits at kaffe.org
Thu Feb 3 09:14:06 PST 2005


PatchSet 5967 
Date: 2005/02/03 17:09:13
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: Robert's fix for bean helper class

2005-02-03  Dalibor Topic  <robilad at kaffe.org>

Resynced with GNU Classpath.

2005-02-02  Robert Schuster  <thebohemian at gmx.net>

        * gnu/java/beans/decoder/GrowableArrayContext.java: Fixed
        assignment behavior by using java.lang.reflect.Array.set()
        directly.

Members: 
	ChangeLog:1.3506->1.3507 
	libraries/javalib/gnu/java/beans/decoder/GrowableArrayContext.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3506 kaffe/ChangeLog:1.3507
--- kaffe/ChangeLog:1.3506	Thu Feb  3 17:01:23 2005
+++ kaffe/ChangeLog	Thu Feb  3 17:09:13 2005
@@ -2,6 +2,16 @@
 
 	Resynced with GNU Classpath.
 	
+	2005-02-02  Robert Schuster  <thebohemian at gmx.net>
+
+        * gnu/java/beans/decoder/GrowableArrayContext.java: Fixed
+        assignment behavior by using java.lang.reflect.Array.set()
+        directly.
+	
+2005-02-03  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+	
 	2005-02-02  Sven de Marothy  <sven at physto.se>
 
 	* java/util/Calendar.java 
Index: kaffe/libraries/javalib/gnu/java/beans/decoder/GrowableArrayContext.java
diff -u kaffe/libraries/javalib/gnu/java/beans/decoder/GrowableArrayContext.java:1.1 kaffe/libraries/javalib/gnu/java/beans/decoder/GrowableArrayContext.java:1.2
--- kaffe/libraries/javalib/gnu/java/beans/decoder/GrowableArrayContext.java:1.1	Thu Jan  6 22:38:53 2005
+++ kaffe/libraries/javalib/gnu/java/beans/decoder/GrowableArrayContext.java	Thu Feb  3 17:09:13 2005
@@ -37,7 +37,6 @@
 package gnu.java.beans.decoder;
 
 import java.lang.reflect.Array;
-import java.util.ArrayList;
 
 /** A Context implementation for a growable array. The array
  * elements have to be set using expressions.
@@ -46,14 +45,17 @@
  */
 class GrowableArrayContext extends AbstractContext
 {
+    private static final int INITIAL_SIZE = 16;
+    
     private Class klass;
-    private ArrayList list = new ArrayList();
     private Object array;
-
+    private int length;
+    
     GrowableArrayContext(String id, Class newClass)
     {
         setId(id);
         klass = newClass;
+        array = Array.newInstance(klass, INITIAL_SIZE);
     }
 
     /* (non-Javadoc)
@@ -61,15 +63,18 @@
      */
     public void addParameterObject(Object o) throws AssemblyException
     {
-        if (!klass.isInstance(o))
-            throw new AssemblyException(
-                new IllegalArgumentException(
-                    "Cannot add object "
-                        + o
-                        + " to array where the elements are of class "
-                        + klass));
-
-        list.add(o);
+      if (length == Array.getLength(array))
+        {
+          Object tmp = Array.newInstance(klass, length * 2);
+          System.arraycopy(array, 0, tmp, 0, length);
+          array = tmp;
+        }
+        
+      try {
+        Array.set(array, length++, o);
+      } catch(IllegalArgumentException iae) {
+        throw new AssemblyException(iae);
+      }
     }
 
     /* (non-Javadoc)
@@ -86,14 +91,13 @@
      */
     public Object endContext(Context outerContext) throws AssemblyException
     {
-        if (array == null)
-        {
-            array = Array.newInstance(klass, list.size());
-
-            for (int i = 0; i < list.size(); i++)
-                Array.set(array, i, list.get(i));
-        }
-
+        if (length != Array.getLength(array))
+          {
+            Object tmp = Array.newInstance(klass, length);
+            System.arraycopy(array, 0, tmp, 0, length);
+            array = tmp;
+          }
+        
         return array;
     }
 
@@ -112,16 +116,11 @@
      */
     public void set(int index, Object o) throws AssemblyException
     {
-        if (array == null)
-        {
-            if (klass.isInstance(o))
-                list.add(index, o);
-            else
-                throw new AssemblyException(
-                    new IllegalArgumentException("Argument is not compatible to array component type."));
-        }
-        else
-            Array.set(array, index, o);
+      try {
+        Array.set(array, index, o);
+      } catch(IllegalArgumentException iae) {
+        throw new AssemblyException(iae);   
+      }
     }
 
     /* (non-Javadoc)
@@ -129,10 +128,7 @@
      */
     public Object get(int index) throws AssemblyException
     {
-        if (array == null)
-            return list.get(index);
-        else
-            return Array.get(array, index);
+      return Array.get(array, index);
     }
 
     public Object getResult()




More information about the kaffe mailing list