harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r598239 [2/3] - in /harmony/enhanced/classlib/branches/java6/modules: awt/src/main/java/common/java/awt/ awt/src/main/java/common/org/apache/harmony/awt/gl/ awt/src/main/java/common/org/apache/harmony/awt/gl/font/ awt/src/main/java/unix/org...
Date Mon, 26 Nov 2007 12:14:02 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java Mon Nov 26 04:13:58 2007
@@ -34,6 +34,11 @@
 import javax.naming.directory.DirContext;
 import javax.naming.directory.InvalidSearchFilterException;
 import javax.naming.directory.SearchControls;
+import javax.naming.event.EventContext;
+import javax.naming.event.NamespaceChangeListener;
+import javax.naming.event.NamingEvent;
+import javax.naming.event.NamingExceptionEvent;
+import javax.naming.event.NamingListener;
 import javax.naming.ldap.BasicControl;
 import javax.naming.ldap.Control;
 import javax.naming.ldap.LdapName;
@@ -41,6 +46,7 @@
 import junit.framework.TestCase;
 
 import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.event.PersistentSearchResult;
 
 public class LdapContextImplTest extends TestCase {
     private LdapContextImpl context;
@@ -503,4 +509,196 @@
         }
     }
 
+    public void test_addToEnvironment() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+
+        context = new LdapContextImpl(client, env, "cn=test");
+
+        Object preValue = context.addToEnvironment(Context.REFERRAL, "ignore");
+        assertNull(preValue);
+        Hashtable<Object, Object> returnedEnv = (Hashtable<Object, Object>) context
+                .getEnvironment();
+        assertTrue(returnedEnv.containsKey(Context.REFERRAL));
+        assertEquals("ignore", returnedEnv.get(Context.REFERRAL));
+
+        preValue = context.addToEnvironment(Context.REFERRAL, "follow");
+        assertEquals("ignore", preValue);
+        returnedEnv = (Hashtable<Object, Object>) context.getEnvironment();
+        assertTrue(returnedEnv.containsKey(Context.REFERRAL));
+        assertEquals("follow", returnedEnv.get(Context.REFERRAL));
+
+    }
+
+    public void test_removeFromEnvironment() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+
+        context = new LdapContextImpl(client, env, "cn=test");
+
+        Object preValue = context.removeFromEnvironment(Context.REFERRAL);
+        assertNull(preValue);
+        Hashtable<Object, Object> returnedEnv = (Hashtable<Object, Object>) context
+                .getEnvironment();
+        assertFalse(returnedEnv.containsKey(Context.REFERRAL));
+
+        env.clear();
+        env.put(Context.REFERRAL, "ignore");
+        context = new LdapContextImpl(client, env, "cn=test");
+        preValue = context.removeFromEnvironment(Context.REFERRAL);
+        assertEquals("ignore", preValue);
+        returnedEnv = (Hashtable<Object, Object>) context.getEnvironment();
+        assertFalse(returnedEnv.containsKey(Context.REFERRAL));
+    }
+
+    public void test_addNamingListener() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+
+        context = new LdapContextImpl(client, env, "cn=test");
+
+        context.addNamingListener("", EventContext.OBJECT_SCOPE,
+                new TestNamingListener());
+
+        SearchOp op = (SearchOp) client.getRequest();
+        assertEquals("cn=test", op.getBaseObject());
+        SearchControls controls = op.getControls();
+        assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+        assertEquals(0, controls.getCountLimit());
+        assertEquals(false, controls.getDerefLinkFlag());
+        assertEquals(false, controls.getReturningObjFlag());
+        assertEquals(null, controls.getReturningAttributes());
+
+        Filter filter = op.getFilter();
+        assertEquals(Filter.PRESENT_FILTER, filter.getType());
+        assertEquals("objectClass", filter.getValue());
+        assertTrue(op.getSearchResult() instanceof PersistentSearchResult);
+
+        try {
+            context.addNamingListener("cn=addlistener/use/bin",
+                    EventContext.OBJECT_SCOPE, new TestNamingListener());
+            fail("Should throw InvalidNameException");
+        } catch (InvalidNameException e) {
+            // expected
+        }
+
+        client = new MockLdapClient();
+        context = new LdapContextImpl(client, env, "cn=test");
+        // listener is null, do nothing
+        context.addNamingListener("", EventContext.OBJECT_SCOPE, null);
+        assertFalse(client.getRequest() instanceof SearchOp);
+
+        try {
+            context.addNamingListener("", 100, new TestNamingListener());
+            fail("Should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void test_addNamingListener_with_filter() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+
+        context = new LdapContextImpl(client, env, "cn=test");
+
+        SearchControls controls = new SearchControls();
+        controls.setCountLimit(100);
+        controls.setDerefLinkFlag(true);
+        controls.setReturningObjFlag(true);
+        controls.setTimeLimit(5);
+        context.addNamingListener("test=addlistener", "(objectClass=*)",
+                controls, new TestNamingListener());
+
+        SearchOp op = (SearchOp) client.getRequest();
+        assertEquals("test=addlistener,cn=test", op.getBaseObject());
+        Filter filter = op.getFilter();
+        assertEquals(Filter.PRESENT_FILTER, filter.getType());
+        assertEquals("objectClass", filter.getValue());
+        assertEquals(controls.getCountLimit(), op.getControls().getCountLimit());
+        assertEquals(controls.getDerefLinkFlag(), op.getControls()
+                .getDerefLinkFlag());
+        assertEquals(controls.getReturningObjFlag(), op.getControls()
+                .getReturningObjFlag());
+        assertEquals(controls.getSearchScope(), op.getControls()
+                .getSearchScope());
+        assertEquals(controls.getTimeLimit(), op.getControls().getTimeLimit());
+        assertTrue(op.getSearchResult() instanceof PersistentSearchResult);
+
+        try {
+            context.search("test=addlistener", "objectClass=*", controls);
+            fail("Should throw InvalidSearchFilterException");
+        } catch (InvalidSearchFilterException e) {
+            // expected
+        }
+
+        context.addNamingListener("test=addlistener", "(objectClass=*)", null,
+                new TestNamingListener());
+
+        op = (SearchOp) client.getRequest();
+        assertEquals(0, op.getControls().getCountLimit());
+        assertEquals(false, op.getControls().getDerefLinkFlag());
+        assertEquals(false, op.getControls().getReturningObjFlag());
+        assertEquals(SearchControls.ONELEVEL_SCOPE, op.getControls()
+                .getSearchScope());
+        assertEquals(0, op.getControls().getTimeLimit());
+        assertNull(controls.getReturningAttributes());
+        assertTrue(op.getSearchResult() instanceof PersistentSearchResult);
+    }
+
+    public void test_removeNamingListener() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+
+        context = new LdapContextImpl(client, env, "cn=test");
+        // remove not registered listener, do nothing
+        context.removeNamingListener(new TestNamingListener());
+
+        NamingListener listener = new TestNamingListener();
+
+        context.addNamingListener("test=listener", EventContext.OBJECT_SCOPE,
+                listener);
+        context.removeNamingListener(listener);
+
+        listener = new TestNamingListener();
+        context.addNamingListener("test=listener", EventContext.OBJECT_SCOPE,
+                listener);
+        context.addNamingListener("test=listener", EventContext.ONELEVEL_SCOPE,
+                listener);
+        context.removeNamingListener(listener);
+    }
+
+    public static class TestNamingListener implements NamespaceChangeListener {
+
+        private NamingEvent event;
+
+        private NamingExceptionEvent ex;
+
+        public void objectAdded(NamingEvent namingevent) {
+            this.event = namingevent;
+        }
+
+        public void objectRemoved(NamingEvent namingevent) {
+            this.event = namingevent;
+        }
+
+        public NamingEvent getEvent() {
+            return event;
+        }
+
+        public NamingExceptionEvent getExceptionEvent() {
+            return ex;
+        }
+
+        public void objectRenamed(NamingEvent namingevent) {
+            this.event = namingevent;
+        }
+
+        public void namingExceptionThrown(
+                NamingExceptionEvent namingExceptionEvent) {
+            this.ex = namingExceptionEvent;
+
+        }
+
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/MockLdapClient.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/MockLdapClient.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/MockLdapClient.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/MockLdapClient.java Mon Nov 26 04:13:58 2007
@@ -74,6 +74,13 @@
     }
 
     @Override
+    public int addPersistentSearch(SearchOp op) throws IOException {
+        request = op.getRequest();
+        response = op.getResponse();
+        return new LdapMessage(response).getMessageId();
+    }
+
+    @Override
     public void doOperationWithoutResponse(int opIndex, ASN1Encodable op,
             Control[] controls) throws IOException {
         request = op;

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java Mon Nov 26 04:13:58 2007
@@ -30,7 +30,7 @@
 public class SearchOpTest extends TestCase {
     public void test_encode_decode() throws Exception {
         SearchControls controls = new SearchControls();
-        Filter filter = new Filter(7);
+        Filter filter = new Filter(Filter.PRESENT_FILTER);
         filter.setValue(Utils.getBytes("objectClass"));
         SearchOp op = new SearchOp("test", controls, filter);
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringReader.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringReader.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringReader.java Mon Nov 26 04:13:58 2007
@@ -42,7 +42,7 @@
      *            the String to filter reads on.
      */
     public StringReader(String str) {
-        super(str);
+        super();
         this.str = str;
         this.count = str.length();
     }
@@ -54,12 +54,7 @@
      */
     @Override
     public void close() {
-        synchronized (lock) {
-            if (isClosed()) {
-                return;
-            }
-            str = null;
-        }
+        str = null;
     }
 
     /**
@@ -139,14 +134,17 @@
      */
     @Override
     public int read(char buf[], int offset, int len) throws IOException {
-        // avoid int overflow
-        if (offset < 0 || offset > buf.length || len < 0
-                || len > buf.length - offset) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
         synchronized (lock) {
             if (isClosed()) {
                 throw new IOException(Msg.getString("K0083")); //$NON-NLS-1$
+            }
+            // avoid int overflow
+            if (offset < 0 || offset > buf.length || len < 0
+                    || len > buf.length - offset) {
+                throw new ArrayIndexOutOfBoundsException();
+            }
+            if (len == 0) {
+                return 0;
             }
             if (pos == this.count) {
                 return -1;

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringWriter.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringWriter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/StringWriter.java Mon Nov 26 04:13:58 2007
@@ -84,9 +84,7 @@
      * @return this StringWriters local StringBuffer.
      */
     public StringBuffer getBuffer() {
-        synchronized (lock) {
-            return buf;
-        }
+        return buf;
     }
 
     /**
@@ -98,9 +96,7 @@
      */
     @Override
     public String toString() {
-        synchronized (lock) {
-            return buf.toString();
-        }
+        return buf.toString();
     }
 
     /**
@@ -124,9 +120,10 @@
                 || count > cbuf.length - offset) {
             throw new IndexOutOfBoundsException();
         }
-        synchronized (lock) {
-            this.buf.append(cbuf, offset, count);
+        if (count == 0) {
+            return;
         }
+        buf.append(cbuf, offset, count);
     }
 
     /**
@@ -139,9 +136,7 @@
      */
     @Override
     public void write(int oneChar) {
-        synchronized (lock) {
-            buf.append((char) oneChar);
-        }
+        buf.append((char) oneChar);
     }
 
     /**
@@ -153,9 +148,7 @@
      */
     @Override
     public void write(String str) {
-        synchronized (lock) {
-            buf.append(str);
-        }
+        buf.append(str);
     }
 
     /**
@@ -176,9 +169,7 @@
     @Override
     public void write(String str, int offset, int count) {
         String sub = str.substring(offset, offset + count);
-        synchronized (lock) {
-            buf.append(sub);
-        }
+        buf.append(sub);
     }
 
     /**
@@ -209,9 +200,9 @@
     @Override
     public StringWriter append(CharSequence csq) {
         if (null == csq) {
-            append(TOKEN_NULL, 0, TOKEN_NULL.length());
+            write(TOKEN_NULL);
         } else {
-            append(csq, 0, csq.length());
+            write(csq.toString());
         }
         return this;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java Mon Nov 26 04:13:58 2007
@@ -151,9 +151,6 @@
                 }
                 byte[] classFileBytes = ProxyClassFile.generateBytes(
                         nextClassName, interfaces);
-                if (loader == null) {
-                    loader = ClassLoader.getSystemClassLoader();
-                }
                 newClass = defineClassImpl(loader, nextClassName.replace('.',
                         '/'), classFileBytes);
                 // Need a weak reference to the class so it can
@@ -166,7 +163,10 @@
                 }
             } else {
                 newClass = ref.get();
-                assert newClass != null; 
+                assert newClass != null : "interfaceKey=" + interfaceKey
+                                        + "loaderCache=" + loaderCache 
+                                        + "\nintfCache=" + interfaceCache
+                                        + "\nproxyCache=" + proxyCache; 
             }
             return newClass;
         }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ArrayList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ArrayList.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ArrayList.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ArrayList.java Mon Nov 26 04:13:58 2007
@@ -43,10 +43,10 @@
     private transient E[] array;
 
     /**
-     * Constructs a new instance of ArrayList with zero capacity.
+     * Constructs a new instance of ArrayList with capacity for ten elements.
      */
     public ArrayList() {
-        this(0);
+        this(10);
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java Mon Nov 26 04:13:58 2007
@@ -147,22 +147,24 @@
                                 .equals(testString.substring(5, 7)));
 	}
 
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
+	// Regression test for HARMONY-5077
+    static boolean finish = false;
 
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
+    public void test_synchronization() {
+        String anything = "Hello world";
+        final StringReader sr = new StringReader(anything);
+        Thread other = new Thread(new Runnable() {
+            public void run() {
+                sr.close();
+                finish = true;
+            };
+        });
 
-		try {
-			sr.close();
-		} catch (Exception e) {
-		}
-	}
+        synchronized (anything) {
+            other.start();
+            while (!finish) {
+                Thread.yield();
+            }
+        }
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java Mon Nov 26 04:13:58 2007
@@ -22,6 +22,9 @@
 import java.lang.reflect.Proxy;
 import java.lang.reflect.UndeclaredThrowableException;
 
+import java.security.AllPermission;
+import java.security.ProtectionDomain;
+
 import tests.support.Support_Proxy_I1;
 import tests.support.Support_Proxy_I2;
 import tests.support.Support_Proxy_ParentException;
@@ -72,21 +75,19 @@
 				.isProxyClass(Proxy.getProxyClass(null,
 						new Class[] { Comparable.class })));
 
-		boolean aborted = false;
 		try {
 			Proxy.getProxyClass(null, new Class[] { Support_Proxy_I1.class,
 					Support_Proxy_I2.class });
-		} catch (IllegalArgumentException e) {
-			aborted = true;
+            fail("Default classLoader should not see app class ");
+		} catch (IllegalArgumentException expected) {
 		}
-		assertTrue("Default classLoader should not see app class ", aborted);
 	}
 
 	/**
 	 * @tests java.lang.reflect.Proxy#newProxyInstance(java.lang.ClassLoader,
 	 *        java.lang.Class[], java.lang.reflect.InvocationHandler)
 	 */
-	public void test_newProxyInstanceLjava_lang_ClassLoader$Ljava_lang_ClassLjava_lang_reflect_InvocationHandler() {
+	public void test_newProxyInstanceLjava_lang_ClassLoader$Ljava_lang_ClassLjava_lang_reflect_InvocationHandler() throws Exception {
 		Object p = Proxy.newProxyInstance(Support_Proxy_I1.class
 				.getClassLoader(), new Class[] { Support_Proxy_I1.class,
 				Support_Proxy_I2.class }, new InvocationHandler() {
@@ -116,42 +117,31 @@
 		int[] result = (int[]) proxy.array(new long[] { 100L, -200L });
 		assertEquals("Failed base type conversion test ", -200, result[0]);
 
-		boolean worked = false;
 		try {
 			proxy.string("");
+            fail("Problem converting exception");
 		} catch (Support_Proxy_SubException e) {
-			worked = true;
-		} catch (Support_Proxy_ParentException e) { // is never thrown
 		}
-		assertTrue("Problem converting exception ", worked);
 
-		worked = false;
 		try {
 			proxy.string("clone");
-		} catch (Support_Proxy_ParentException e) { // is never thrown
+            fail("Problem converting exception");
 		} catch (UndeclaredThrowableException e) {
-			worked = true;
+            assertSame(Support_Proxy_ParentException.class, e.getCause().getClass());
 		}
-		assertTrue("Problem converting exception ", worked);
 
-		worked = false;
 		try {
 			proxy.string("error");
-		} catch (Support_Proxy_ParentException e) { // is never thrown
-		} catch (UndeclaredThrowableException e) {
-		} catch (RuntimeException e) {
-			worked = e.getClass() == ArrayStoreException.class;
+            fail("Problem converting exception");
+		} catch (ArrayStoreException e) {
 		}
-		assertTrue("Problem converting exception ", worked);
 
-		worked = false;
 		try {
 			proxy.string("any");
-		} catch (Support_Proxy_ParentException e) { // is never thrown
+            fail("Problem converting exception");
 		} catch (UndeclaredThrowableException e) {
-			worked = true;
+            assertSame(IllegalAccessException.class, e.getCause().getClass());
 		}
-		assertTrue("Problem converting exception ", worked);
 
 		Broken1 proxyObject = (Broken1) Proxy.newProxyInstance(Broken1.class
 				.getClassLoader(), new Class[] { Broken1.class },
@@ -207,13 +197,11 @@
 
 		assertTrue("Did not return invocation handler ", Proxy
 				.getInvocationHandler(p) == handler);
-		boolean aborted = false;
 		try {
 			Proxy.getInvocationHandler("");
+            fail("Did not detect non proxy object");
 		} catch (IllegalArgumentException e) {
-			aborted = true;
 		}
-		assertTrue("Did not detect non proxy object ", aborted);
 	}
         
     //Regression Test for HARMONY-2355
@@ -226,6 +214,31 @@
         assertNotNull(o);
     }
 
+    public void test_getProxyClass_loader() {
+        Class pc = Proxy.getProxyClass(null,
+                new Class[] { Runnable.class});
+        assertSame(null, pc.getClassLoader());
+        
+        ProtectionDomain pd = pc.getProtectionDomain();
+        ProtectionDomain od = Object.class.getProtectionDomain();
+        assertTrue(pd.implies(new AllPermission()));
+        assertSame(od.getClassLoader(), pd.getClassLoader());
+        assertEquals(od.toString(), pd.toString());
+    }
+
+    public void test_getProxyClass_package() {
+        Class pc = Proxy.getProxyClass(PkgIntf.class.getClassLoader(),
+                new Class[] { PkgIntf.class});
+        assertSame(PkgIntf.class.getPackage(), pc.getPackage());
+        assertSame(PkgIntf.class.getClassLoader(), pc.getClassLoader());
+        
+        ProtectionDomain pd = pc.getProtectionDomain();
+        ProtectionDomain od = Object.class.getProtectionDomain();
+        assertTrue(pd.implies(new AllPermission()));
+        assertSame(od.getClassLoader(), pd.getClassLoader());
+        assertEquals(od.toString(), pd.toString());
+    }
+
     public void test_newProxyInstance_withNonCompatibleReturnTypes() {
         try {
             Proxy.newProxyInstance(this.getClass().getClassLoader(),
@@ -280,3 +293,5 @@
 	protected void tearDown() {
 	}
 }
+
+interface PkgIntf {}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java Mon Nov 26 04:13:58 2007
@@ -37,6 +37,10 @@
 		this.descriptor = new CPUTF8(descriptor.substring(colon+1));
 	}
 
+	protected ClassFileEntry[] getNestedClassFileEntries() {
+		return new ClassFileEntry[] { name, descriptor };
+	}
+
 	
 	protected void resolve(ClassConstantPool pool) {
 		super.resolve(pool);

Modified: harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java Mon Nov 26 04:13:58 2007
@@ -25,8 +25,10 @@
 import java.awt.Rectangle;
 import java.awt.Shape;
 import java.awt.font.GlyphVector;
+import java.awt.font.TextLayout;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.PathIterator;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.awt.image.BufferedImageOp;
 import java.awt.image.ImageObserver;
@@ -35,17 +37,30 @@
 import java.text.AttributedCharacterIterator;
 import java.text.CharacterIterator;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.harmony.awt.gl.CommonGraphics2D;
 
 public class Graphics2D2PS extends CommonGraphics2D {
 
-    private static final Font DEF_FONT = new Font("Courier", Font.PLAIN, 12); //$NON-NLS-1$
+    private static final Font                DEF_FONT;
+    private static final Map<String, String> FONT_MAP;
 
-    private final PrintStream out_stream;
-    private final PageFormat  format;
-    private final Rectangle   defaultClip;
-    private double            yscale   = 1;
+    private final PrintStream                out_stream;
+    private final PageFormat                 format;
+    private final Rectangle                  defaultClip;
+    private double                           yscale = 1;
+
+    static {
+        DEF_FONT = new Font("Dialog", Font.PLAIN, 12); //$NON-NLS-1$
+        FONT_MAP = new HashMap<String, String>();
+        FONT_MAP.put("Serif", "Times"); //$NON-NLS-1$ //$NON-NLS-2$
+        FONT_MAP.put("SansSerif", "Helvetica"); //$NON-NLS-1$ //$NON-NLS-2$
+        FONT_MAP.put("Monospaced", "Courier"); //$NON-NLS-1$ //$NON-NLS-2$
+        FONT_MAP.put("Dialog", "Helvetica"); //$NON-NLS-1$ //$NON-NLS-2$
+        FONT_MAP.put("DialogInput", "Courier"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
 
     public Graphics2D2PS(final PrintStream stream, final PageFormat format) {
         super();
@@ -56,15 +71,15 @@
         out_stream = stream;
         this.format = format != null ? format : new PageFormat();
         defaultClip = new Rectangle((int) this.format.getImageableX(),
-                        (int) this.format.getImageableY(), (int) this.format
-                                        .getImageableWidth(), (int) this.format
-                                        .getImageableHeight());
+                        (int) this.format.getImageableY(),
+                        (int) this.format.getImageableWidth(),
+                        (int) this.format.getImageableHeight());
         PS.printHeader(stream);
         resetGraphics();
         setColor(fgColor);
         setFont(DEF_FONT);
         setClip(defaultClip);
-        ps(PS.gsave);
+        ps(PS.setDefGstate);
     }
 
     public Graphics2D2PS(final PrintStream stream) {
@@ -78,7 +93,7 @@
 
     public void startPage(final int number) {
         ps(PS.comment, "Page: " + number + " " + number); //$NON-NLS-1$ //$NON-NLS-2$
-        ps(PS.grestore);
+        ps(PS.restoreDefGstate);
         resetGraphics();
     }
 
@@ -101,7 +116,7 @@
         final float h = (float) imageGIF.getHeight();
 
         drawImage(image, x, convY(y), true, ((float) width) / w,
-                        ((float) height) / h);
+            ((float) height) / h);
         return true;
     }
 
@@ -131,7 +146,7 @@
         fillRect(x, y, width, height);
         setColor(cur_color);
         drawImage(image, x, convY(y), true, ((float) width) / w,
-                        ((float) height) / h);
+            ((float) height) / h);
         return true;
     }
 
@@ -197,7 +212,7 @@
         setColor(cur_color);
 
         return drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
-                        imageObserver);
+            imageObserver);
 
     }
 
@@ -218,9 +233,29 @@
     }
 
     public void drawString(final String text, final int x, final int y) {
-        if (text != null) {
-            ps(PS.moveto, x, convY(y));
-            ps(PS.show, "(" + wrapString(text) + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+        if (text == null) {
+            return;
+        }
+
+        StringBuffer sb = new StringBuffer(text.length());
+        int lastX = x;
+
+        for (int i = 0; i < text.length(); i++) {
+            if (text.codePointAt(i) < 256) {
+                sb.append(text.charAt(i));
+            } else {
+                if (sb.length() > 0) {
+                    lastX += drawPSString(sb.toString(), lastX, y);
+                    sb = new StringBuffer(text.length() - i);
+                }
+
+                lastX += drawStringShape(String.valueOf(text.charAt(i)), lastX,
+                    y);
+            }
+        }
+
+        if (sb.length() > 0) {
+            drawPSString(sb.toString(), lastX, y);
         }
     }
 
@@ -235,8 +270,7 @@
         final char[] cc = new char[n];
         int i = 0;
 
-        for (char c = iterator.first(); c != CharacterIterator.DONE; c = iterator
-                        .next()) {
+        for (char c = iterator.first(); c != CharacterIterator.DONE; c = iterator.next()) {
             cc[i++] = c;
         }
         drawChars(cc, 0, n, x, y);
@@ -342,33 +376,44 @@
     private void drawShape(final Shape shape, final boolean fill,
                     final boolean stroke) {
         final float[] coords = new float[6];
-        final PathIterator pathIterator = shape
-                        .getPathIterator((AffineTransform) null);
-        int i;
+        final PathIterator pathIterator = shape.getPathIterator((AffineTransform) null);
+        float x = 0;
+        float y = 0;
 
         ps(PS.newpath);
 
         while (!pathIterator.isDone()) {
-            i = pathIterator.currentSegment(coords);
-            switch (i) {
+            switch (pathIterator.currentSegment(coords)) {
             case PathIterator.SEG_MOVETO: {
                 ps(PS.moveto, (int) coords[0], convY((int) coords[1]));
+                x = coords[0];
+                y = coords[1];
                 break;
             }
             case PathIterator.SEG_LINETO: {
                 ps(PS.lineto, (int) coords[0], convY((int) coords[1]));
+                x = coords[0];
+                y = coords[1];
                 break;
             }
             case PathIterator.SEG_QUADTO: {
-                // XXX: improvement required
-                ps(PS.lineto, (int) coords[0], convY((int) coords[1]));
-                ps(PS.lineto, (int) coords[2], convY((int) coords[3]));
+                final float x1 = (x + 2 * coords[0]) / 3;
+                final float y1 = (y + 2 * coords[1]) / 3;
+                final float x2 = (2 * coords[2] + coords[0]) / 3;
+                final float y2 = (2 * coords[3] + coords[1]) / 3;
+
+                x = coords[2];
+                y = coords[3];
+                ps(PS.curveto, x1, convY((int) y1), x2, convY((int) y2), x,
+                    convY((int) y));
                 break;
             }
             case PathIterator.SEG_CUBICTO: {
                 ps(PS.curveto, (int) coords[0], convY((int) coords[1]),
-                                (int) coords[2], convY((int) coords[3]),
-                                (int) coords[4], convY((int) coords[5]));
+                    (int) coords[2], convY((int) coords[3]), (int) coords[4],
+                    convY((int) coords[5]));
+                x = coords[4];
+                y = coords[5];
                 break;
             }
             case PathIterator.SEG_CLOSE: {
@@ -395,8 +440,23 @@
     }
 
     public void setFont(final Font font) {
+        // looking for direct mapping of <name>.<style> to PostScript name
+        String psName = FONT_MAP.get(font.getName() + "." + font.getStyle()); //$NON-NLS-1$
+
+        if (psName == null) {
+            // looking for font name mapping
+            final String name = FONT_MAP.get(font.getName());
+            if (name != null) {
+                psName = PSFont.getPSName(name, font.getStyle());
+            }
+        }
+
+        if (psName == null) {
+            psName = PSFont.Helvetica.psName;
+        }
+
+        ps(PS.setfnt, psName, font.getSize());
         super.setFont(font);
-        ps(PS.setfnt, font.getName(), font.getSize());
     }
 
     public void translate(final int x, final int y) {
@@ -463,12 +523,24 @@
     public void setTransform(final AffineTransform transform) {
         super.setTransform(transform);
         ps(PS.concat, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4],
-                        matrix[5]);
+            matrix[5]);
     }
 
     private static String wrapString(final String str) {
         return str.replace("\\", "\\\\").replace("\n", "\\\n").replace("\r", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
-                        "\\\r").replace("(", "\\(").replace(")", "\\)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+            "\\\r").replace("(", "\\(").replace(")", "\\)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+    }
+
+    private static String threebytes2Hex(int b) {
+        final char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+                        'A', 'B', 'C', 'D', 'E', 'F' };
+        final char[] ret = new char[6];
+
+        for (int i = 0; i < 6; i++) {
+            ret[5 - i] = hex[b & 0x0F];
+            b = b >> 4;
+        }
+        return new String(ret);
     }
 
     private void drawImage(final Image image, final int x, final int y) {
@@ -599,16 +671,20 @@
         ps(PS.stroke);
     }
 
-    private static String threebytes2Hex(int b) {
-        final char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
-                        'A', 'B', 'C', 'D', 'E', 'F' };
-        final char[] ret = new char[6];
+    private int drawPSString(final String text, final int x, final int y) {
+        final Rectangle2D r = font.getStringBounds(text, frc);
+        final double w = r.getWidth();
 
-        for (int i = 0; i < 6; i++) {
-            ret[5 - i] = hex[b & 0x0F];
-            b = b >> 4;
-        }
-        return new String(ret);
+        ps(PS.show, "(" + wrapString(text) + ")", w, x, convY(y)); //$NON-NLS-1$ //$NON-NLS-2$
+        return (int) w;
+    }
+
+    private int drawStringShape(final String str, final int x, final int y) {
+        final TextLayout l = new TextLayout(str, font, frc);
+
+        drawShape(l.getOutline(AffineTransform.getTranslateInstance(x, y)),
+            true, true);
+        return (int) font.getStringBounds(str, frc).getWidth();
     }
 
     /**
@@ -653,14 +729,16 @@
             scalefont,
             setfont,
             setlinewidth,
-            show,
+            show(null, "%s %s %s %s S"), //$NON-NLS-1$
             showpage,
             stroke,
             translate,
             comment(null, "%%%%%s"), //$NON-NLS-1$
             concat(null, "[%s %s %s %s %s %s] concat"), //$NON-NLS-1$
             setcolor("C", null), //$NON-NLS-1$
-            setfnt(null, "/%s %s F"); //$NON-NLS-1$
+            setfnt(null, "/%s %s F"), //$NON-NLS-1$
+            setDefGstate(null, "/DEF_GSTATE gstate def"), //$NON-NLS-1$
+            restoreDefGstate(null, "DEF_GSTATE setgstate"); //$NON-NLS-1$
 
         final String name;
         final String format;
@@ -670,7 +748,7 @@
         }
 
         PS(final String name, final String format) {
-            this.name = (name != null) ? name : toString();
+            this.name = (name != null) ? name : name();
             this.format = format;
         }
 
@@ -682,6 +760,8 @@
             out.println("%%EndComments"); //$NON-NLS-1$
             out.println("/F {exch findfont exch scalefont setfont} def"); //$NON-NLS-1$
             out.println("/C {setrgbcolor} bind def"); //$NON-NLS-1$
+            out.println("/S {gsave moveto 1 index stringwidth pop div 1 scale " //$NON-NLS-1$
+                + "show grestore} def"); //$NON-NLS-1$
         }
 
         static void printFooter(final PrintStream out) {
@@ -698,6 +778,40 @@
                 }
                 out.println(name);
             }
+        }
+    }
+
+    private enum PSFont {
+            Times_Roman("Times", null, Font.PLAIN), //$NON-NLS-1$
+            Times_Italic("Times", null, Font.ITALIC), //$NON-NLS-1$
+            Times_Bold("Times", null, Font.BOLD), //$NON-NLS-1$
+            Times_BoldItalic("Times", null, Font.BOLD + Font.ITALIC), //$NON-NLS-1$
+            Helvetica("Helvetica", null, Font.PLAIN), //$NON-NLS-1$
+            Helvetica_Oblique("Helvetica", null, Font.ITALIC), //$NON-NLS-1$
+            Helvetica_Bold("Helvetica", null, Font.BOLD), //$NON-NLS-1$
+            Helvetica_BoldOblique("Helvetica", null, Font.BOLD + Font.ITALIC), //$NON-NLS-1$
+            Courier("Courier", null, Font.PLAIN), //$NON-NLS-1$
+            Courier_Oblique("Courier", null, Font.ITALIC), //$NON-NLS-1$
+            Courier_Bold("Courier", null, Font.BOLD), //$NON-NLS-1$
+            Courier_BoldOblique("Courier", null, Font.BOLD + Font.ITALIC); //$NON-NLS-1$
+
+        final String name;
+        final String psName;
+        final int    style;
+
+        PSFont(final String name, final String psName, final int style) {
+            this.name = name;
+            this.psName = (psName != null) ? psName : name().replace('_', '-');
+            this.style = style;
+        }
+
+        static String getPSName(final String name, final int style) {
+            for (PSFont f : values()) {
+                if ((f.style == style) && f.name.equalsIgnoreCase(name)) {
+                    return f.psName;
+                }
+            }
+            return null;
         }
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=598239&r1=598238&r2=598239&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Mon Nov 26 04:13:58 2007
@@ -18,6 +18,7 @@
 
 import java.io.InputStream;
 import java.io.Reader;
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.sql.Array;
 import java.sql.Blob;
@@ -41,11 +42,15 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Map;
+import java.util.Vector;
 
 import javax.sql.RowSet;
 import javax.sql.RowSetEvent;
 import javax.sql.RowSetInternal;
+import javax.sql.RowSetListener;
 import javax.sql.RowSetMetaData;
 import javax.sql.RowSetWriter;
 import javax.sql.rowset.BaseRowSet;
@@ -71,8 +76,6 @@
 
     private CachedRow currentRow;
 
-    private CachedRow originalRow;
-
     // start from : 1.
     private int currentRowIndex;
 
@@ -103,6 +106,27 @@
 
     public CachedRowSetImpl(String providerID) throws SyncFactoryException {
         syncProvider = SyncFactory.getInstance(providerID);
+        initialProperties();
+    }
+
+    private void initialProperties() {
+        try {
+            setEscapeProcessing(true);
+            setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+            setConcurrency(ResultSet.CONCUR_UPDATABLE);
+            setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
+            setMaxRows(0);
+            setQueryTimeout(0);
+            setShowDeleted(false);
+            setUsername(null);
+            setPassword(null);
+            setMaxFieldSize(0);
+            setTypeMap(null);
+            setFetchSize(0);
+        } catch (SQLException e) {
+            // ignore, never reached
+        }
+
     }
 
     public CachedRowSetImpl() throws SyncFactoryException {
@@ -138,7 +162,10 @@
             RowSetWriter rowSetWriter = syncProvider.getRowSetWriter();
             CachedRowSetImpl input = (CachedRowSetImpl) createCopy();
             rowSetWriter.writeData(input);
-            // setOriginalRow();
+            /*
+             * FIXME: if no conflicts happen when writeData, then call
+             * setOriginalRow()
+             */
             notifyRowSetChanged();
         } catch (SQLException e) {
             // TODO deal with the exception
@@ -176,123 +203,112 @@
     public CachedRowSet createCopy() throws SQLException {
         CachedRowSetImpl output;
         try {
-            output = (CachedRowSetImpl) super.clone();
-            // restore "this"'s states
-            int temp = currentRowIndex;
-            CachedRow cr;
-            if (currentRow != null) {
-                cr = currentRow.createClone();
-            } else {
-                cr = null;
+            /*
+             * the attribute of BaseRowSet which are needed to deep copy
+             */
+            // BaseRowSet.params <Hashtable>
+            Object[] paramsObjArray = super.getParams().clone();
+            Hashtable<Object, Object> paramsHashtable = new Hashtable<Object, Object>();
+            for (int i = 0; i < paramsObjArray.length; i++) {
+                paramsHashtable.put(Integer.valueOf(i), paramsObjArray[i]);
             }
+            // BaseRowSet.listeners <Vector>
+            Vector<RowSetListener> listeners = new Vector<RowSetListener>();
 
-            first();
-
-            // Deep Copy
-            ArrayList<CachedRow> data = new ArrayList<CachedRow>();
+            /*
+             * deep copy BaseRowSet
+             */
+            output = (CachedRowSetImpl) super.clone();
+            // BaseRowSet.params
+            Field paramsField = output.getClass().getSuperclass()
+                    .getDeclaredField("params");
+            paramsField.setAccessible(true);
+            paramsField.set(output, paramsHashtable);
+            // BaseRowSet.listeners
+            Field listenersField = output.getClass().getSuperclass()
+                    .getDeclaredField("listeners");
+            listenersField.setAccessible(true);
+            listenersField.set(output, listeners);
+            // BaseRowSet.map
+            if (super.getTypeMap() != null) {
+                Map<String, Class<?>> originalTypeMap = super.getTypeMap();
+                Map<String, Class<?>> copyTypeMap = new HashMap<String, Class<?>>();
+                copyTypeMap.putAll(originalTypeMap);
+                output.setTypeMap(copyTypeMap);
+            }
 
-            do {
-                data.add(currentRow.createClone());
-            } while (next());
-
-            // TODO: should be the same granularity with RI using Debug tool
-            // inspect!
-            ((CachedRowSetImpl) output).setRows(data, columnCount);
-            output.setMetaData(((RowSetMetaDataImpl) getMetaData()));
-            output.originalResultSet = originalResultSet;
-            output.setUrl(getUrl());
-            output.setTableName(getTableName());
-
-            // Constraints
-            output.setReadOnly(isReadOnly());
-            output.setConcurrency(getConcurrency());
-            output.setType(getType());
-
-            // recovery this's state for the modification of the operation
-            // first() and next();
-            currentRow = cr;
-            currentRowIndex = temp;
+            /*
+             * deep copy CachedRowSetImpl
+             */
+            // CachedRowSetImpl.rows <ArrayList>
+            ArrayList<CachedRow> copyRows = new ArrayList<CachedRow>();
+            for (int i = 0; i < rows.size(); i++) {
+                copyRows.add(rows.get(i).createClone());
+            }
+            output.setRows(copyRows, columnCount);
+            // CachedRowSetImpl.meta <RowSetMetaData>
+            output.setMetaData(copyMetaData(getMetaData()));
+            // set currentRow
+            if ((currentRowIndex > 0) && (currentRowIndex <= rows.size())) {
+                output.absolute(currentRowIndex);
+            }
+            // others
+            if (getKeyColumns() != null) {
+                output.setKeyColumns(getKeyColumns().clone());
+            }
+            // CachedRowSetImpl.originalResultSet
+            CachedRowSetImpl copyOriginalRs = new CachedRowSetImpl();
+            copyOriginalRs.populate(getOriginal());
+            output.originalResultSet = copyOriginalRs;
+
+            /*
+             * TODO uncomment after getMatchColumnIndexes and
+             * getMatchColumnNames implemented
+             */
+            // if (getMatchColumnIndexes() != null) {
+            // output.setMatchColumn(getMatchColumnIndexes().clone());
+            // }
+            // if (getMatchColumnNames() != null) {
+            // output.setMatchColumn(getMatchColumnNames().clone());
+            // }
+            output.setSyncProvider(getSyncProvider().getProviderID());
+            if (insertRow != null) {
+                output.insertRow = insertRow.createClone();
+            }
 
             return output;
         } catch (CloneNotSupportedException e) {
-            // FIXME deal with the exception
-            e.printStackTrace();
-            return null;
+            // TODO add error message
+            throw new SQLException();
+        } catch (NoSuchFieldException e) {
+            // TODO add error message
+            throw new SQLException();
+        } catch (IllegalAccessException e) {
+            // TODO add error message
+            throw new SQLException();
         }
     }
 
     public CachedRowSet createCopyNoConstraints() throws SQLException {
-        CachedRowSetImpl output;
-        try {
-            output = (CachedRowSetImpl) super.clone();
-            // restore "this"'s states
-            int temp = currentRowIndex;
-            CachedRow cr;
-            if (currentRow != null) {
-                cr = currentRow.createClone();
-            } else {
-                cr = null;
-            }
-
-            first();
-
-            // Deep Copy
-            ArrayList<CachedRow> data = new ArrayList<CachedRow>();
-            do {
-                data.add(currentRow.createClone());
-            } while (next());
-
-            // TODO: should be the same granularity with RI using Debug tool
-            // inspect!
-            ((CachedRowSetImpl) output).setRows(data, columnCount);
-            output.setMetaData((RowSetMetaData) (getMetaData()));
-            output.originalResultSet = originalResultSet;
-            output.setUrl(getUrl());
-            output.setTableName(getTableName());
-
-            // recovery this's state for the modification of the operation
-            // first() and next();
-            currentRow = cr;
-            currentRowIndex = temp;
-
-            return output;
-        } catch (CloneNotSupportedException e) {
-            // FIXME deal with the exception
-            e.printStackTrace();
-            return null;
-        }
+        CachedRowSetImpl output = (CachedRowSetImpl) createCopy();
+        output.initialProperties();
+        return output;
     }
 
     public CachedRowSet createCopySchema() throws SQLException {
-        // For webRowSet: represent the table structure: Columns
-        CachedRowSetImpl result;
-        try {
-            // copy data from BaseRowSet
-            result = (CachedRowSetImpl) super.clone();
-            // deep copy meta data
-            result.meta = copyMetaData(meta);
-            result.columnCount = columnCount;
-            result.keyCols = keyCols == null ? null : keyCols.clone();
-            result.originalResultSet = new CachedRowSetImpl(syncProvider
-                    .getProviderID());
-            result.pageSize = pageSize;
-            result.setSyncProvider(syncProvider.getProviderID());
-            result.setTableName(getTableName());
-
-            // clean up rows data
-            result.currentColumn = null;
-            result.currentRowIndex = 0;
-            result.insertRow = null;
-            result.originalRow = null;
-            result.pageNumber = 1;
-            result.rememberedCursorPosition = 0;
-            result.rows = new ArrayList<CachedRow>();
-            result.sqlwarn = null;
-            return result;
-        } catch (CloneNotSupportedException e) {
-            // TODO add error message
-            throw new SQLException();
-        }
+        CachedRowSetImpl output = (CachedRowSetImpl) createCopy();
+
+        // clean up rows data
+        output.currentColumn = null;
+        output.currentRow = null;
+        output.currentRowIndex = 0;
+        output.insertRow = null;
+        output.pageNumber = 1;
+        output.rememberedCursorPosition = 0;
+        output.rows = new ArrayList<CachedRow>();
+        output.sqlwarn = null;
+
+        return output;
     }
 
     public RowSet createShared() throws SQLException {
@@ -340,11 +356,14 @@
             throw new SQLException();
         }
 
-        CachedRowSetImpl specialRset = new CachedRowSetImpl();
+        CachedRowSetImpl originalRowRset = new CachedRowSetImpl();
         ArrayList<CachedRow> data = new ArrayList<CachedRow>();
-        data.add(originalRow);
-        specialRset.setRows(data, columnCount);
-        return specialRset;
+        CachedRow originalCachedRow = rows.get(getRow() - 1).getOriginal();
+        data.add(originalCachedRow);
+        originalRowRset.setRows(data, columnCount);
+        originalRowRset.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
+        originalRowRset.setConcurrency(ResultSet.CONCUR_UPDATABLE);
+        return originalRowRset;
     }
 
     public int getPageSize() {
@@ -377,7 +396,6 @@
     }
 
     public void populate(ResultSet rs, int startRow) throws SQLException {
-        initParams();
         meta = copyMetaData(rs.getMetaData());
 
         new CachedRowSetReader(rs, startRow).readData(this);
@@ -400,23 +418,38 @@
         RowSetMetaDataImpl rowSetMetaData = new RowSetMetaDataImpl();
         rowSetMetaData.setColumnCount(metaData.getColumnCount());
         for (int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++) {
-            rowSetMetaData.setAutoIncrement(columnIndex, metaData.isAutoIncrement(columnIndex));
-            rowSetMetaData.setCaseSensitive(columnIndex, metaData.isCaseSensitive(columnIndex));
-            rowSetMetaData.setCatalogName(columnIndex, metaData.getCatalogName(columnIndex));
+            rowSetMetaData.setAutoIncrement(columnIndex, metaData
+                    .isAutoIncrement(columnIndex));
+            rowSetMetaData.setCaseSensitive(columnIndex, metaData
+                    .isCaseSensitive(columnIndex));
+            rowSetMetaData.setCatalogName(columnIndex, metaData
+                    .getCatalogName(columnIndex));
             rowSetMetaData.setColumnDisplaySize(columnIndex, metaData
                     .getColumnDisplaySize(columnIndex));
-            rowSetMetaData.setColumnLabel(columnIndex, metaData.getColumnLabel(columnIndex));
-            rowSetMetaData.setColumnName(columnIndex, metaData.getColumnName(columnIndex));
-            rowSetMetaData.setColumnType(columnIndex, metaData.getColumnType(columnIndex));
-            rowSetMetaData.setColumnTypeName(columnIndex, metaData.getColumnTypeName(columnIndex));
-            rowSetMetaData.setCurrency(columnIndex, metaData.isCurrency(columnIndex));
-            rowSetMetaData.setNullable(columnIndex, metaData.isNullable(columnIndex));
-            rowSetMetaData.setPrecision(columnIndex, metaData.getPrecision(columnIndex));
-            rowSetMetaData.setScale(columnIndex, metaData.getScale(columnIndex));
-            rowSetMetaData.setSchemaName(columnIndex, metaData.getSchemaName(columnIndex));
-            rowSetMetaData.setSearchable(columnIndex, metaData.isSearchable(columnIndex));
-            rowSetMetaData.setSigned(columnIndex, metaData.isSigned(columnIndex));
-            rowSetMetaData.setTableName(columnIndex, metaData.getTableName(columnIndex));
+            rowSetMetaData.setColumnLabel(columnIndex, metaData
+                    .getColumnLabel(columnIndex));
+            rowSetMetaData.setColumnName(columnIndex, metaData
+                    .getColumnName(columnIndex));
+            rowSetMetaData.setColumnType(columnIndex, metaData
+                    .getColumnType(columnIndex));
+            rowSetMetaData.setColumnTypeName(columnIndex, metaData
+                    .getColumnTypeName(columnIndex));
+            rowSetMetaData.setCurrency(columnIndex, metaData
+                    .isCurrency(columnIndex));
+            rowSetMetaData.setNullable(columnIndex, metaData
+                    .isNullable(columnIndex));
+            rowSetMetaData.setPrecision(columnIndex, metaData
+                    .getPrecision(columnIndex));
+            rowSetMetaData
+                    .setScale(columnIndex, metaData.getScale(columnIndex));
+            rowSetMetaData.setSchemaName(columnIndex, metaData
+                    .getSchemaName(columnIndex));
+            rowSetMetaData.setSearchable(columnIndex, metaData
+                    .isSearchable(columnIndex));
+            rowSetMetaData.setSigned(columnIndex, metaData
+                    .isSigned(columnIndex));
+            rowSetMetaData.setTableName(columnIndex, metaData
+                    .getTableName(columnIndex));
         }
         return rowSetMetaData;
     }
@@ -457,13 +490,12 @@
 
     public void setOriginalRow() throws SQLException {
 
+        // FIXME re-implements this method
         if (currentRow == null) {
             // TODO add error messages
             throw new SQLException();
         }
-        originalRow = currentRow;
         currentRow.setNonUpdateable();
-
     }
 
     public void setPageSize(int size) throws SQLException {
@@ -491,6 +523,9 @@
     }
 
     public int size() {
+        if (rows == null) {
+            return 0;
+        }
         return rows.size();
     }
 
@@ -565,42 +600,60 @@
     }
 
     public boolean absolute(int row) throws SQLException {
-        if (rows.size() == 0) {
+        return doAbsolute(row, true);
+    }
+
+    /**
+     * internal implement of absolute
+     * 
+     * @param row
+     *            index of row cursor to move
+     * @param checkType
+     *            whether to check property ResultSet.TYPE_FORWARD_ONLY
+     * @return whether the cursor is on result set
+     * @throws SQLException
+     */
+    private boolean doAbsolute(int row, boolean checkType) throws SQLException {
+        if (rows == null || rows.size() == 0) {
             return false;
         }
-        if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
-            // TODO add error messages
-            throw new SQLException();
+
+        if (checkType && getType() == ResultSet.TYPE_FORWARD_ONLY) {
+            // rowset.8=The Result Set Type is TYPE_FORWARD_ONLY
+            throw new SQLException(Messages.getString("rowset.8"));
         }
+
         if (row < 0) {
             row = rows.size() + row + 1;
-        } else if (row == 0) {
-            currentRowIndex = row;
+        }
+
+        if (row <= 0) {
+            currentRowIndex = 0;
             currentRow = null;
-            return true;
+            return false;
+        }
+
+        if (row > rows.size()) {
+            currentRowIndex = rows.size() + 1;
+            currentRow = null;
+            return false;
         }
 
         currentRowIndex = row;
-        currentRow = (CachedRow) rows.get(currentRowIndex - 1);
+        currentRow = rows.get(currentRowIndex - 1);
         return true;
     }
 
     public void afterLast() throws SQLException {
-        if (getType() == TYPE_FORWARD_ONLY) {
-            // rowset.8=The Result Set Type is TYPE_FORWARD_ONLY
-            throw new SQLException(Messages.getString("rowset.8"));
+        if (rows == null) {
+            return;
         }
-        currentRowIndex = rows.size() + 1;
-        currentRow = null;
+
+        doAbsolute(rows.size() + 1, true);
     }
 
     public void beforeFirst() throws SQLException {
-        if (getType() == TYPE_FORWARD_ONLY) {
-            // rowset.8=The Result Set Type is TYPE_FORWARD_ONLY
-            throw new SQLException(Messages.getString("rowset.8"));
-        }
-        currentRowIndex = 0;
-        currentRow = null;
+        doAbsolute(0, true);
     }
 
     public void cancelRowUpdates() throws SQLException {
@@ -614,7 +667,9 @@
     public void close() throws SQLException {
 
         // TODO need more concerns!
-        rows.clear();
+        if (rows != null) {
+            rows.clear();
+        }
         currentRowIndex = 0;
         currentRow = null;
         meta = null;
@@ -638,7 +693,7 @@
     }
 
     public boolean first() throws SQLException {
-        return absolute(1);
+        return doAbsolute(1, true);
     }
 
     public Array getArray(int columnIndex) throws SQLException {
@@ -840,7 +895,12 @@
     }
 
     public int getRow() throws SQLException {
-        throw new NotImplementedException();
+        // FIXME need more tests
+        if (currentRow == null) {
+            return 0;
+        }
+
+        return currentRowIndex;
     }
 
     public short getShort(int columnIndex) throws SQLException {
@@ -945,23 +1005,35 @@
     }
 
     public boolean isAfterLast() throws SQLException {
-        throw new NotImplementedException();
+        if (rows == null || rows.size() == 0) {
+            return false;
+        }
+
+        return currentRowIndex > rows.size();
     }
 
     public boolean isBeforeFirst() throws SQLException {
-        throw new NotImplementedException();
+        if (rows == null || rows.size() == 0) {
+            return false;
+        }
+
+        return currentRowIndex == 0;
     }
 
     public boolean isFirst() throws SQLException {
-        throw new NotImplementedException();
+        return currentRowIndex == 1;
     }
 
     public boolean isLast() throws SQLException {
-        throw new NotImplementedException();
+        if (rows == null || rows.size() == 0) {
+            return false;
+        }
+
+        return currentRowIndex == rows.size();
     }
 
     public boolean last() throws SQLException {
-        return absolute(-1);
+        return doAbsolute(-1, true);
     }
 
     public void moveToCurrentRow() throws SQLException {
@@ -981,29 +1053,40 @@
     }
 
     public boolean next() throws SQLException {
-        currentRowIndex++;
-        if (rows.size() < currentRowIndex) {
-            return false;
-        }
-        currentRow = rows.get(currentRowIndex - 1);
-        return true;
+        /*
+         * spec next() is identical with relative(1), but they can't:
+         * 
+         * next() doesn't check TYPE_FORWARD_ONLY property, relative(1) does.
+         */
+        return doAbsolute(currentRowIndex + 1, false);
     }
 
     public boolean previous() throws SQLException {
-        currentRowIndex--;
-        if (rows.size() < currentRowIndex) {
-            return false;
-        }
-        currentRow = rows.get(currentRowIndex - 1);
-        return true;
+        return doAbsolute(currentRowIndex - 1, true);
     }
 
     public void refreshRow() throws SQLException {
         throw new NotImplementedException();
     }
 
-    public boolean relative(int rows) throws SQLException {
-        throw new NotImplementedException();
+    public boolean relative(int moveRows) throws SQLException {
+        if (currentRow == null) {
+            // TODO add error message
+            throw new SQLException();
+        }
+
+        int index = getRow() + moveRows;
+        if (index <= 0) {
+            beforeFirst();
+            return false;
+        }
+
+        if (index > rows.size()) {
+            afterLast();
+            return false;
+        }
+
+        return doAbsolute(index, true);
     }
 
     public boolean rowDeleted() throws SQLException {



Mime
View raw message