Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 21022 invoked from network); 5 Dec 2007 12:28:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Dec 2007 12:28:37 -0000 Received: (qmail 55188 invoked by uid 500); 5 Dec 2007 12:28:25 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 55168 invoked by uid 500); 5 Dec 2007 12:28:25 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 55156 invoked by uid 99); 5 Dec 2007 12:28:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Dec 2007 04:28:25 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Dec 2007 12:28:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AABA91A9858; Wed, 5 Dec 2007 04:27:31 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r601315 [10/11] - in /harmony/enhanced/classlib/branches/java6: depends/build/ modules/accessibility/src/main/java/javax/accessibility/ modules/accessibility/src/test/api/java/common/javax/accessibility/ modules/awt/src/main/java/common/jav... Date: Wed, 05 Dec 2007 12:26:14 -0000 To: commits@harmony.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071205122731.AABA91A9858@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java Wed Dec 5 04:25:42 2007 @@ -63,8 +63,10 @@ * Constructs an instance with the specified bits. *

* - * @param mostSigBits The 64 most significant bits of the UUID. - * @param leastSigBits The 64 least significant bits of the UUID. + * @param mostSigBits + * The 64 most significant bits of the UUID. + * @param leastSigBits + * The 64 least significant bits of the UUID. */ public UUID(long mostSigBits, long leastSigBits) { super(); @@ -204,54 +206,58 @@ * Parses a UUID string with the format defined by {@link #toString()}. *

* - * @param uuid The UUID string to parse. + * @param uuid + * The UUID string to parse. * @return A UUID instance. - * @throws NullPointerException if uuid is null. - * @throws IllegalArgumentException if uuid is not formatted - * correctly. + * @throws NullPointerException + * if uuid is null. + * @throws IllegalArgumentException + * if uuid is not formatted correctly. */ public static UUID fromString(String uuid) { if (uuid == null) { throw new NullPointerException(); } - + int[] position = new int[5]; int lastPosition = 1; int startPosition = 0; - + int i = 0; - for (; i < position.length && lastPosition > 0; i++) { - position[i] = uuid.indexOf("-", startPosition); //$NON-NLS-1$ - lastPosition = position[i]; - startPosition = position[i] + 1; + for (; i < position.length && lastPosition > 0; i++) { + position[i] = uuid.indexOf("-", startPosition); //$NON-NLS-1$ + lastPosition = position[i]; + startPosition = position[i] + 1; } // should have and only can have four "-" in UUID - if(i != position.length || lastPosition != -1) - { - throw new IllegalArgumentException(Msg.getString("KA014") + uuid); //$NON-NLS-1$ - } - - long m1 = Long.parseLong(uuid.substring(0, position[0]), 16); - long m2 = Long.parseLong(uuid.substring(position[0]+ 1, position[1]), 16); - long m3 = Long.parseLong(uuid.substring(position[1] + 1, position[2]), 16); - - long lsb1 = Long.parseLong(uuid.substring(position[2] + 1, position[3]), 16); - long lsb2 = Long.parseLong(uuid.substring(position[3]+ 1), 16); - - long msb = (m1 << 32) | (m2 << 16) | m3; - long lsb = (lsb1 << 48) | lsb2; - - return new UUID(msb, lsb); - } - - /** - *

- * The 64 least significant bits of the UUID. - *

- * - * @return A long value. - */ + if (i != position.length || lastPosition != -1) { + throw new IllegalArgumentException(Msg.getString("KA014") + uuid); //$NON-NLS-1$ + } + + long m1 = Long.parseLong(uuid.substring(0, position[0]), 16); + long m2 = Long.parseLong(uuid.substring(position[0] + 1, position[1]), + 16); + long m3 = Long.parseLong(uuid.substring(position[1] + 1, position[2]), + 16); + + long lsb1 = Long.parseLong( + uuid.substring(position[2] + 1, position[3]), 16); + long lsb2 = Long.parseLong(uuid.substring(position[3] + 1), 16); + + long msb = (m1 << 32) | (m2 << 16) | m3; + long lsb = (lsb1 << 48) | lsb2; + + return new UUID(msb, lsb); + } + + /** + *

+ * The 64 least significant bits of the UUID. + *

+ * + * @return A long value. + */ public long getLeastSignificantBits() { return leastSigBits; } @@ -312,7 +318,8 @@ *

* * @return A long value. - * @throws UnsupportedOperationException if {@link #version()} is not 1. + * @throws UnsupportedOperationException + * if {@link #version()} is not 1. */ public long timestamp() { if (version != 1) { @@ -328,7 +335,8 @@ *

* * @return A long value. - * @throws UnsupportedOperationException if {@link #version()} is not 1. + * @throws UnsupportedOperationException + * if {@link #version()} is not 1. */ public int clockSequence() { if (version != 1) { @@ -344,7 +352,8 @@ *

* * @return A long value. - * @throws UnsupportedOperationException if {@link #version()} is not 1. + * @throws UnsupportedOperationException + * if {@link #version()} is not 1. */ public long node() { if (version != 1) { @@ -360,7 +369,8 @@ * significant. *

* - * @param uuid The UUID to compare to. + * @param uuid + * The UUID to compare to. * @return A value of -1, 0 or 1 if this UUID is less than, equal to or * greater than uuid. */ @@ -391,7 +401,8 @@ * then true is returned. *

* - * @param object The Object to compare to. + * @param object + * The Object to compare to. * @return A true if this UUID is equal to * object or false if not. */ @@ -485,9 +496,12 @@ * Resets the transient fields to match the behavior of the constructor. *

* - * @param in The InputStream to read from. - * @throws IOException if in throws it. - * @throws ClassNotFoundException if in throws it. + * @param in + * The InputStream to read from. + * @throws IOException + * if in throws it. + * @throws ClassNotFoundException + * if in throws it. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java Wed Dec 5 04:25:42 2007 @@ -20,10 +20,9 @@ /** * The unchecked exception will be thrown out if the format conversion is * unknown. - * - * */ public class UnknownFormatConversionException extends IllegalFormatException { + private static final long serialVersionUID = 19060418L; private String s; Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java Wed Dec 5 04:25:42 2007 @@ -20,42 +20,41 @@ /** * The unchecked exception will be thrown out if there is an unknown flag. - * */ public class UnknownFormatFlagsException extends IllegalFormatException { - private static final long serialVersionUID = 19370506L; + private static final long serialVersionUID = 19370506L; - private String flags; + private String flags; - /** - * Constructs an UnknownFormatFlagsException with the specified flags. - * - * @param f - * The specified flags. - */ - public UnknownFormatFlagsException(String f) { - if (null == f) { - throw new NullPointerException(); - } - flags = f; - } + /** + * Constructs an UnknownFormatFlagsException with the specified flags. + * + * @param f + * The specified flags. + */ + public UnknownFormatFlagsException(String f) { + if (null == f) { + throw new NullPointerException(); + } + flags = f; + } - /** - * Returns the flags associated with the exception. - * - * @return The flags associated with the exception. - */ - public String getFlags() { - return flags; - } + /** + * Returns the flags associated with the exception. + * + * @return The flags associated with the exception. + */ + public String getFlags() { + return flags; + } - /** - * Returns the message associated with the exception. - * - * @return The message associated with the exception. - */ - @Override + /** + * Returns the message associated with the exception. + * + * @return The message associated with the exception. + */ + @Override public String getMessage() { return Msg.getString("K034a", flags); } Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java Wed Dec 5 04:25:42 2007 @@ -400,7 +400,7 @@ } if (object instanceof List) { List list = (List) object; - if (list.size() != size()) { + if (list.size() != elementCount) { return false; } @@ -830,7 +830,7 @@ */ @Override protected void removeRange(int start, int end) { - if (start >= 0 && start <= end && end <= size()) { + if (start >= 0 && start <= end && end <= elementCount) { if (start == end) { return; } @@ -960,7 +960,7 @@ * * @exception IndexOutOfBoundsException * when start < 0 or end > size() - * @exception IllegalArgumentException when start > end + * @exception IllegalArgumentException when start > end */ @Override public synchronized List subList(int start, int end) { @@ -1022,7 +1022,7 @@ return "[]"; //$NON-NLS-1$ } int length = elementCount - 1; - StringBuffer buffer = new StringBuffer(size() * 16); + StringBuffer buffer = new StringBuffer(elementCount * 16); buffer.append('['); for (int i = 0; i < length; i++) { if (elementData[i] == this) { Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java Wed Dec 5 04:25:42 2007 @@ -1081,6 +1081,7 @@ // Response Code Sample : "HTTP/1.0 200 OK" // Call connect() first since getHeaderField() doesn't return exceptions + connect(); doRequest(); if (responseCode != -1) { return responseCode; Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c Wed Dec 5 04:25:42 2007 @@ -36,7 +36,7 @@ #define PORT_LIB_OPTION "_org.apache.harmony.vmi.portlib" -#define HY_COPYRIGHT_STRING "Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors, as applicable." +#define HY_COPYRIGHT_STRING "Apache Harmony Launcher : (c) Copyright 1991, 2007 The Apache Software Foundation or its licensors, as applicable." /* Tools launchers will invoke HY_TOOLS_PACKAGE+"."++"."+HY_TOOLS_MAIN_TYPE */ #define HY_TOOLS_PACKAGE "org.apache.harmony.tools" Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java Wed Dec 5 04:25:42 2007 @@ -17,6 +17,7 @@ package tests.api.java.io; +import java.io.ByteArrayInputStream; import java.io.CharArrayReader; import java.io.IOException; import java.io.PipedInputStream; @@ -382,6 +383,14 @@ assertTrue("toString failed." + st.toString(), st.toString().equals( "Token[ABC], line 1")); + + // Regression test for HARMONY-4070 + byte[] data = new byte[] { (byte) '-' }; + StreamTokenizer tokenizer = new StreamTokenizer( + new ByteArrayInputStream(data)); + tokenizer.nextToken(); + String result = tokenizer.toString(); + assertEquals("Token['-'], line 1", result); } /** Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java Wed Dec 5 04:25:42 2007 @@ -540,6 +540,18 @@ list.addAll(0, collection); assertEquals(14, list.size()); } + + public void test_override_size() throws Exception { + ArrayList testlist = new MockArrayList(); + // though size is overriden, it should passed without exception + testlist.add("test_0"); + testlist.add("test_1"); + testlist.add("test_2"); + testlist.add(1,"test_3"); + testlist.get(1); + testlist.remove(2); + testlist.set(1, "test_4"); + } public static class ArrayListExtend extends ArrayList { @@ -556,6 +568,12 @@ public int size() { return size; + } + } + + public class MockArrayList extends ArrayList { + public int size() { + return 0; } } Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java Wed Dec 5 04:25:42 2007 @@ -145,6 +145,19 @@ SimpleTimeZone timezone = new SimpleTimeZone(-3600 * 24 * 1000 * 2, "GMT"); GregorianCalendar gc = new GregorianCalendar(timezone); + + // Regression test for HARMONY-5195 + Calendar c1 = new GregorianCalendar(TimeZone.getTimeZone("GMT")); + c1.set(Calendar.YEAR,1999); + c1.set(Calendar.MONTH,Calendar.JUNE); + c1.set(Calendar.DAY_OF_MONTH,2); + c1.set(Calendar.HOUR,15); + c1.set(Calendar.MINUTE,34); + c1.set(Calendar.SECOND,16); + assertEquals(34,c1.get(Calendar.MINUTE)); + c1.setTimeZone(new SimpleTimeZone(60000, "ONE MINUTE")); + assertEquals(35,c1.get(Calendar.MINUTE)); + } /** Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java Wed Dec 5 04:25:42 2007 @@ -88,7 +88,7 @@ if (null == o1) { return -1; } - if (null == o2) { + if (null == o2) { // comparator should be symmetric return 1; } return o1.compareTo(o2); @@ -356,6 +356,21 @@ treemap = new TreeMap(); SortedMap headMap = treemap.headMap("100"); headMap.headMap("100"); + + SortedMap intMap,sub; + int size = 16; + intMap = new TreeMap(); + for(int i=0; i(); + for(int i=0; i intMap,sub; + int size = 16; + intMap = new TreeMap(); + for(int i=0; i(); + for(int i=0; i -1); } + + public void test_override_size() throws Exception { + Vector v = new Vector(); + Vector testv = new MockVector(); + // though size is overriden, it should passed without exception + testv.add(1); + testv.add(2); + testv.clear(); + + testv.add(1); + testv.add(2); + v.add(1); + v.add(2); + // RI's bug here + assertTrue(testv.equals(v)); + } /** * @tests java.util.Vector#trimToSize() @@ -922,6 +940,13 @@ protected Vector vectorClone(Vector s) { return (Vector) s.clone(); } + + public class MockVector extends Vector{ + @Override + public synchronized int size() { + return 0; + } + } /** * Sets up the fixture, for example, open a network connection. This method Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java Wed Dec 5 04:25:42 2007 @@ -22,8 +22,11 @@ import java.io.OutputStream; import java.util.ArrayList; +import org.apache.harmony.pack200.bytecode.Attribute; +import org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute; import org.apache.harmony.pack200.bytecode.ByteCode; import org.apache.harmony.pack200.bytecode.CodeAttribute; +import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute; import org.apache.harmony.pack200.bytecode.OperandManager; /** @@ -342,6 +345,7 @@ operandManager.setSegment(segment); int i = 0; + ArrayList orderedCodeAttributes = segment.getClassBands().getOrderedCodeAttributes(); for (int c = 0; c < classCount; c++) { int numberOfMethods = methodFlags[c].length; for (int m = 0; m < numberOfMethods; m++) { @@ -360,7 +364,22 @@ CodeAttribute attr = new CodeAttribute(maxStack, maxLocal, methodByteCodePacked[c][m], segment, operandManager); methodAttributes[c][m].add(attr); - i++; + // Should I add all the attributes in here? + ArrayList currentAttributes = (ArrayList)orderedCodeAttributes.get(i); + for(int index=0;index < currentAttributes.size(); index++) { + Attribute currentAttribute = (Attribute)currentAttributes.get(index); + // TODO: The line below adds the LocalVariableTable + // and LineNumber attributes. Currently things are + // broken because these tables don't get renumbered + // properly. Commenting out the add so the class files + // will verify. + //attr.attributes.add(currentAttribute); + // Fix up the line numbers if needed + if(currentAttribute.hasBCIRenumbering()) { + ((BCIRenumberedAttribute)currentAttribute).renumber(attr.byteCodeOffsets); + } + } + i++; } } } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Wed Dec 5 04:25:42 2007 @@ -20,10 +20,10 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import org.apache.harmony.pack200.IcBands.ICTuple; +import org.apache.harmony.pack200.bytecode.Attribute; import org.apache.harmony.pack200.bytecode.CPClass; import org.apache.harmony.pack200.bytecode.CPUTF8; import org.apache.harmony.pack200.bytecode.ConstantValueAttribute; @@ -997,6 +997,27 @@ public long[][] getFieldFlags() { return fieldFlags; + } + + /** + * Answer an ArrayList of ArrayLists which hold the the code attributes + * corresponding to all classes in order. + * + * If a class doesn't have any attributes, the corresponding element in this + * list will be an empty ArrayList. + * @return ArrayList + */ + public ArrayList getOrderedCodeAttributes() { + ArrayList orderedAttributeList = new ArrayList(); + for(int classIndex=0; classIndex < codeAttributes.length; classIndex++) { + ArrayList currentAttributes = new ArrayList(); + for(int attributeIndex = 0; attributeIndex < codeAttributes[classIndex].size(); attributeIndex++) { + Attribute attribute = (Attribute)codeAttributes[classIndex].get(attributeIndex); + currentAttributes.add(attribute); + } + orderedAttributeList.add(currentAttributes); + } + return orderedAttributeList; } public ArrayList[][] getMethodAttributes() { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java Wed Dec 5 04:25:42 2007 @@ -17,7 +17,6 @@ package org.apache.harmony.pack200; import java.util.ArrayList; -import java.util.Arrays; import org.apache.harmony.pack200.bytecode.CPClass; import org.apache.harmony.pack200.bytecode.CPDouble; @@ -29,7 +28,6 @@ import org.apache.harmony.pack200.bytecode.CPMethodRef; import org.apache.harmony.pack200.bytecode.CPString; import org.apache.harmony.pack200.bytecode.CPUTF8; -import org.apache.harmony.pack200.bytecode.ClassFileEntry; import org.apache.harmony.pack200.bytecode.ConstantPoolEntry; public class SegmentConstantPool { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java Wed Dec 5 04:25:42 2007 @@ -92,4 +92,19 @@ private SegmentUtils() { // Intended to be a helper class } + + /** + * This is a debugging message to aid the developer in writing this + * class. If the property 'debug.pack200' is set, this will + * generate messages to stderr; otherwise, it will be silent. + * + * @param message + * @deprecated this may be removed from production code + */ + public static void debug(String message) { + if (System.getProperty("debug.pack200") != null) { + System.err.println(message); + } + } + } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java Wed Dec 5 04:25:42 2007 @@ -20,59 +20,82 @@ import java.io.IOException; public abstract class Attribute extends ClassFileEntry { - private final CPUTF8 attributeName; + private final CPUTF8 attributeName; - private int attributeNameIndex; + private int attributeNameIndex; - public Attribute(String attributeName) { - this.attributeName = new CPUTF8(attributeName); - } - - protected void doWrite(DataOutputStream dos) throws IOException { - dos.writeShort(attributeNameIndex); - dos.writeInt(getLength()); - writeBody(dos); - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (this.getClass() != obj.getClass()) - return false; - final Attribute other = (Attribute) obj; - if (attributeName == null) { - if (other.attributeName != null) - return false; - } else if (!attributeName.equals(other.attributeName)) - return false; - return true; - } - - protected CPUTF8 getAttributeName() { - return attributeName; - } - - protected abstract int getLength(); - - protected ClassFileEntry[] getNestedClassFileEntries() { - return new ClassFileEntry[] { getAttributeName() }; - } - - public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result - + ((attributeName == null) ? 0 : attributeName.hashCode()); - return result; - } - - protected void resolve(ClassConstantPool pool) { - super.resolve(pool); - attributeNameIndex = pool.indexOf(attributeName); - } + public Attribute(String attributeName) { + this.attributeName = new CPUTF8(attributeName); + } + + protected void doWrite(DataOutputStream dos) throws IOException { + dos.writeShort(attributeNameIndex); + dos.writeInt(getLength()); + writeBody(dos); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final Attribute other = (Attribute) obj; + if (attributeName == null) { + if (other.attributeName != null) + return false; + } else if (!attributeName.equals(other.attributeName)) + return false; + return true; + } + + protected CPUTF8 getAttributeName() { + return attributeName; + } + + protected abstract int getLength(); + + /** + * Answer the length of the receiver including its header (the u2 for the + * attribute name and the u4 for the attribute length). This is relevant + * when attributes are nested within other attributes - the outer attribute + * needs to take the inner attribute headers into account when calculating + * its length. + * + * @return int adjusted length + */ + protected int getLengthIncludingHeader() { + return getLength() + 2 + 4; + } + + protected ClassFileEntry[] getNestedClassFileEntries() { + return new ClassFileEntry[] { getAttributeName() }; + } + + /** + * Answer true if the receiver needs to have BCI renumbering applied to it; + * otherwise answer false. + * + * @return boolean BCI renumbering required + */ + public boolean hasBCIRenumbering() { + return false; + } + + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + + ((attributeName == null) ? 0 : attributeName.hashCode()); + return result; + } + + protected void resolve(ClassConstantPool pool) { + super.resolve(pool); + attributeNameIndex = pool.indexOf(attributeName); + } - protected abstract void writeBody(DataOutputStream dos) throws IOException; + protected abstract void writeBody(DataOutputStream dos) throws IOException; -} \ No newline at end of file +} Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java Wed Dec 5 04:25:42 2007 @@ -18,7 +18,9 @@ import java.io.DataOutputStream; import java.io.IOException; + import org.apache.harmony.pack200.Segment; +import org.apache.harmony.pack200.SegmentUtils; import org.apache.harmony.pack200.bytecode.forms.ByteCodeForm; public class ByteCode extends ClassFileEntry { @@ -33,6 +35,9 @@ private int[][] nestedPositions; private int[] rewrite; + private int byteCodeOffset = -1; + private int byteCodeTarget = -1; + protected ByteCode(int opcode) { this(opcode, ClassFileEntry.NONE); } @@ -131,12 +136,12 @@ case 4: // TODO: need to handle wides? - System.out.println("Need to handle wides"); + SegmentUtils.debug("Need to handle wides"); // figure out and if so, handle and put a break here. // break; default: - System.out.println("Unhandled resolve " + this); + SegmentUtils.debug("Unhandled resolve " + this); } } } @@ -181,7 +186,7 @@ */ public void setOperandInt(int operand, int position) { int firstOperandIndex = getByteCodeForm().firstOperandIndex(); - int byteCodeFormLength = getByteCodeForm().operandLength(); + int byteCodeFormLength = getByteCodeForm().getRewrite().length; if (firstOperandIndex < 1) { // No operand rewriting permitted for this bytecode throw new Error("Trying to rewrite " + this + " that has no rewrite"); @@ -191,11 +196,26 @@ throw new Error("Trying to rewrite " + this + " with an int at position " + position + " but this won't fit in the rewrite array"); } - rewrite[firstOperandIndex + position] = (operand & 0xFF00) >> 8; - rewrite[firstOperandIndex + position + 1] = operand & 0xFF; + rewrite[firstOperandIndex + position] = (operand & 0xFF00) >> 8; + rewrite[firstOperandIndex + position + 1] = operand & 0xFF; } /** + * This is just like setOperandInt, but takes special care when the + * operand is less than 0 to make sure it's written correctly. + * @param operand int to set the rewrite bytes to + * @param position int position of the operands in the rewrite bytes + */ + public void setOperandSignedInt(int operand, int position) { + if(operand >= 0) { + setOperandInt(operand, position); + } else { + int twosComplementOperand = 0x10000 + operand; + setOperandInt(twosComplementOperand, position); + } + } + + /** * Given an int operand, treat it as a byte and set * the rewrite byte for that position to that value. * Mask of anything beyond 0xFF. @@ -260,4 +280,66 @@ public int[] getNestedPosition(int index) { return getNestedPositions()[index]; } + + /** + * This method will answer true if the receiver is + * a multi-bytecode instruction (such as + * aload0_putfield_super); otherwise, it will answer + * false. + * + * @return boolean true if multibytecode, false otherwise + */ + public boolean hasMultipleByteCodes() { + return getByteCodeForm().hasMultipleByteCodes(); + } + + /** + * ByteCodes may need to know their position in the + * code array (in particular, label byte codes need + * to know where they are in order to calculate their + * targets). This method lets the CodeAttribute specify + * where the byte code is. + * + * Since there are no aload0+label instructions, this + * method doesn't worry about multioperation bytecodes. + * + * @param byteCodeOffset int position in code array. + */ + public void setByteCodeIndex(int byteCodeOffset) { + this.byteCodeOffset = byteCodeOffset; + } + + + public int getByteCodeIndex() { + return byteCodeOffset; + } + + /** + * Some ByteCodes (in particular, LabelForm bytecodes) + * have to keep track of a byteCodeTarget. This is + * initially an offset in the CodeAttribute array + * relative to the byteCodeOffset, but later gets fixed + * up to point to the absolute position in the CodeAttribute + * array. This method sets the target. + * + * @param byteCodeTarget int index in array + */ + public void setByteCodeTarget(int byteCodeTarget) { + this.byteCodeTarget = byteCodeTarget; + } + + public int getByteCodeTarget() { + return byteCodeTarget; + } + + /** + * Some ByteCodes (in particular, those with the Label + * form) need to be fixed up after all the bytecodes + * in the CodeAttribute have been added. (This can't + * be done beforehand because the CodeAttribute needs + * to be complete before targets can be assigned.) + */ + public void applyByteCodeTargetFixup(CodeAttribute codeAttribute) { + getByteCodeForm().fixUpByteCodeTarget(this, codeAttribute); + } } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java Wed Dec 5 04:25:42 2007 @@ -21,8 +21,10 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; + import org.apache.harmony.pack200.Pack200Exception; import org.apache.harmony.pack200.Segment; +import org.apache.harmony.pack200.SegmentUtils; public class ClassConstantPool { @@ -60,7 +62,12 @@ public int indexOf(ClassFileEntry entry) { if (!resolved) throw new IllegalStateException("Constant pool is not yet resolved; this does not make any sense"); - return entries.indexOf(entry) + 1; + int entryIndex = entries.indexOf(entry); + // If the entry isn't found, answer -1. Otherwise answer the entry. + if(entryIndex != -1) { + return entryIndex + 1; + } + return -1; } public int size() { @@ -74,7 +81,7 @@ } public void resolve(Segment segment) { - System.out.println("\n\nResolving (Segment.resolve(Segment)"); + SegmentUtils.debug("\n\nResolving (Segment.resolve(Segment)"); HashMap sortMap = new HashMap(); List cpAll = null; // TODO: HACK - this is a 1.5 api. @@ -101,7 +108,7 @@ } } for(int xindex=0; xindex < sortedList.size(); xindex++) { - System.out.println(sortedList.get(xindex)); + SegmentUtils.debug(sortedList.get(xindex).toString()); } resolve(); } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java Wed Dec 5 04:25:42 2007 @@ -56,7 +56,7 @@ fields[i].write(dos); } dos.writeShort(methods.length); - for(int i=0;i 1) { + // Currently, all multi-bytecode instructions + // begin with aload_0, so this is how we test. + if(rewrite[0] == 42) { + // If there's an instruction (not a negative + // number, which is an operand) after the + // aload_0, it's a multibytecode instruction. + return(rewrite[1] > 0); + } + } + return false; + } + /** * When passed a byteCode, an OperandTable and a * SegmentConstantPool, this method will set the @@ -553,5 +577,18 @@ public void setByteCodeOperands(ByteCode byteCode, OperandManager operandManager) { throw new Error("My subclass should have implemented this"); + } + + /** + * The ByteCodeForm knows how to fix up a bytecode if + * it needs to be fixed up because it holds a Label + * bytecode. + * @param byteCode a ByteCode to be fixed up + * @param codeAttribute a CodeAttribute used to determine how + * the ByteCode should be fixed up. + */ + public void fixUpByteCodeTarget(ByteCode byteCode, CodeAttribute codeAttribute) { + // Most ByteCodeForms don't have any fixing up to do. + return; } } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java Wed Dec 5 04:25:42 2007 @@ -17,6 +17,7 @@ package org.apache.harmony.pack200.bytecode.forms; import org.apache.harmony.pack200.bytecode.ByteCode; +import org.apache.harmony.pack200.bytecode.CodeAttribute; import org.apache.harmony.pack200.bytecode.OperandManager; /** @@ -47,17 +48,34 @@ } /* (non-Javadoc) - * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool) + * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#fixUpByteCodeTarget(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.CodeAttribute) */ - public void setByteCodeOperands(ByteCode byteCode, - OperandManager operandManager) { - // TODO: if this is widened, probably need to do something - // different from setOperandInt(). - byteCode.setOperandInt(operandManager.nextLabel(), 0); + public void fixUpByteCodeTarget(ByteCode byteCode, CodeAttribute codeAttribute) { + // LabelForms need to fix up the target of label operations + int originalTarget = byteCode.getByteCodeTarget(); + int sourceIndex = byteCode.getByteCodeIndex(); + int absoluteInstructionTargetIndex = sourceIndex + originalTarget; + int targetValue = ((Integer)codeAttribute.byteCodeOffsets.get(absoluteInstructionTargetIndex)).intValue(); + int sourceValue = ((Integer)codeAttribute.byteCodeOffsets.get(sourceIndex)).intValue(); + // The operand is the difference between the source instruction + // and the destination instruction. + // TODO: Probably have to do something other than setOperandInt if this is widened. + byteCode.setOperandSignedInt(targetValue - sourceValue, 0); if(widened) { byteCode.setNestedPositions(new int[][] {{0,4}}); } else { byteCode.setNestedPositions(new int[][] {{0,2}}); } + } + + /* (non-Javadoc) + * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool) + */ + public void setByteCodeOperands(ByteCode byteCode, + OperandManager operandManager) { + byteCode.setByteCodeTarget(operandManager.nextLabel()); + // The byte code operands actually get set later - + // once we have all the bytecodes - in fixUpByteCodeTarget(). + return; } } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java Wed Dec 5 04:25:42 2007 @@ -31,6 +31,8 @@ import org.apache.harmony.pack200.Segment; import org.apache.harmony.pack200.SegmentConstantPool; import org.apache.harmony.pack200.SegmentHeader; +import org.apache.harmony.pack200.bytecode.Attribute; +import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute; import junit.framework.TestCase; @@ -179,6 +181,19 @@ } return attributes; } + + public ArrayList getOrderedCodeAttributes() { + int totalMethods = 0; + for(int classIndex = 0; classIndex < numMethods.length; classIndex++) { + totalMethods = totalMethods + numMethods[classIndex]; + } + ArrayList orderedAttributeList = new ArrayList(); + for(int classIndex=0; classIndex < totalMethods; classIndex++) { + ArrayList currentAttributes = new ArrayList(); + orderedAttributeList.add(currentAttributes); + } + return orderedAttributeList; + } } public class MockSegment extends AbstractBandsTestCase.MockSegment { @@ -364,7 +379,9 @@ (byte) 162, (byte) 163, (byte) 164, (byte) 165, (byte) 166, (byte) 167, (byte) 168, (byte) 170, (byte) 171, (byte) 198, (byte) 199, (byte) 200, (byte) 201, (byte) 255, 0, 0, // bc_case_count (required by tableswitch (170) and lookupswitch (171)) - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}; // bc_label band +// Now that we're actually doing real label lookup, need valid labels +// 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; // bc_label band + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // bc_label band InputStream in = new ByteArrayInputStream(bytes); bcBands.unpack(in); assertEquals(16, bcBands.getMethodByteCodePacked()[0][0].length); Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Wed Dec 5 04:25:42 2007 @@ -70,6 +70,8 @@ public void setDelete() { isDelete = true; + isUpdate = false; + isInsert = false; } public void undoDelete() { @@ -82,6 +84,8 @@ public void setInsert() { isInsert = true; + isUpdate = false; + isDelete = false; } public boolean isInsert() { @@ -90,6 +94,8 @@ public void setUpdate() { isUpdate = true; + isInsert = false; + isDelete = false; } public void undoUpdate() { 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=601315&r1=601314&r2=601315&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 Wed Dec 5 04:25:42 2007 @@ -52,7 +52,6 @@ import javax.sql.RowSetInternal; import javax.sql.RowSetListener; import javax.sql.RowSetMetaData; -import javax.sql.RowSetWriter; import javax.sql.rowset.BaseRowSet; import javax.sql.rowset.CachedRowSet; import javax.sql.rowset.RowSetMetaDataImpl; @@ -139,7 +138,7 @@ } public void acceptChanges() throws SyncProviderException { - if (currentRow == insertRow) { + if (currentRow == insertRow && currentRow != null) { throw new SyncProviderException(); } @@ -152,25 +151,28 @@ } public void acceptChanges(Connection con) throws SyncProviderException { - if (currentRow == insertRow) { + if (currentRow == insertRow && currentRow != null) { // TODO add error messages throw new SyncProviderException(); } try { - setUrl(con.getMetaData().getURL()); - RowSetWriter rowSetWriter = syncProvider.getRowSetWriter(); - CachedRowSetImpl input = (CachedRowSetImpl) createCopy(); - rowSetWriter.writeData(input); + CachedRowSetWriter rowSetWriter = (CachedRowSetWriter) syncProvider + .getRowSetWriter(); + rowSetWriter.setConnection(con); + int beforeWriteIndex = currentRowIndex; + rowSetWriter.writeData(this); + absolute(beforeWriteIndex); /* * FIXME: if no conflicts happen when writeData, then call * setOriginalRow() */ notifyRowSetChanged(); + + } catch (SyncProviderException e) { + throw e; } catch (SQLException e) { - // TODO deal with the exception - e.printStackTrace(); - throw new SyncProviderException(); + throw new SyncProviderException(e.getMessage()); } } @@ -338,7 +340,7 @@ ps.setObject(i + 1, params[i]); if (ps.execute()) { - populate(ps.getResultSet()); + doPopulate(ps.getResultSet(), true); } } @@ -391,25 +393,51 @@ return false; } - public void populate(ResultSet data) throws SQLException { - populate(data, -1); + public void populate(ResultSet rs) throws SQLException { + doPopulate(rs, false); } public void populate(ResultSet rs, int startRow) throws SQLException { + if (startRow == 1) { + rs.beforeFirst(); + } else if (startRow <= 0 || !rs.absolute(startRow - 1)) { + // rowset.7=Not a valid cursor + throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$ + } + + doPopulate(rs, true); + } + + private void doPopulate(ResultSet rs, boolean isPaging) throws SQLException { meta = copyMetaData(rs.getMetaData()); - new CachedRowSetReader(rs, startRow).readData(this); + /* + * this method not support paging, so before readData set pageSize and + * maxRowsto 0 and restore previous values after readData + */ + if (!isPaging) { + int prePageSize = getPageSize(); + setPageSize(0); + int preMaxRows = getMaxRows(); + setMaxRows(0); + // FIXME use SyncProvider to get RowSetReader + new CachedRowSetReader(rs).readData(this); + setPageSize(prePageSize); + setMaxRows(preMaxRows); + } else { + // FIXME use SyncProvider to get RowSetReader + new CachedRowSetReader(rs).readData(this); + } setTableName(rs.getMetaData().getTableName(1)); originalResultSet = new CachedRowSetImpl(); - new CachedRowSetReader(this, startRow).readData(originalResultSet); + // FIXME use SyncProvider to get RowSetReader + new CachedRowSetReader(this).readData(originalResultSet); originalResultSet.setMetaData((RowSetMetaData) (getMetaData())); // recovery the states - currentRow = null; - currentRowIndex = 0; - + beforeFirst(); } // deep copy of ResultSetMetaData @@ -843,7 +871,6 @@ } public int getInt(int columnIndex) throws SQLException { - checkCursorValid(); checkValidRow(); Object value = currentRow.getObject(columnIndex); if (value == null) { @@ -997,11 +1024,9 @@ // rowset.4=Not an insert row throw new SQLException(Messages.getString("rowset.4")); } - currentRow.setInsert(); + insertRow.setInsert(); rows.add(insertRow); - currentRowIndex++; - // TODO insert the data into database - // insertRowToDB(rows); + insertRow = null; } public boolean isAfterLast() throws SQLException { @@ -1037,19 +1062,22 @@ } public void moveToCurrentRow() throws SQLException { - - if (currentRow == insertRow) { + if (rememberedCursorPosition != -1) { currentRowIndex = rememberedCursorPosition; - currentRow = rows.get(currentRowIndex - 1); + if (currentRowIndex >= 1 && currentRowIndex <= size()) { + currentRow = rows.get(currentRowIndex - 1); + } else { + currentRow = null; + } + rememberedCursorPosition = -1; } - } public void moveToInsertRow() throws SQLException { insertRow = new CachedRow(new Object[columnCount]); currentRow = insertRow; rememberedCursorPosition = currentRowIndex; - currentRowIndex = rows.size(); + currentRowIndex = -1; } public boolean next() throws SQLException { @@ -1096,21 +1124,23 @@ } public boolean rowInserted() throws SQLException { - - /** - * FIXME: Determin the currentRow if have had a insertion 1. Need - * traverse the rows and find if the data hava been added - */ + if (currentRow == null || currentRow == insertRow) { + // TODO add error message + throw new SQLException(); + } return currentRow.isInsert(); } public boolean rowUpdated() throws SQLException { - - boolean sign = false; - for (int i = 0; i < meta.getColumnCount(); ++i) { - sign = currentRow.getUpdateMask(i) | sign; + if (!currentRow.isUpdate()) { + return false; + } else { + boolean sign = false; + for (int i = 0; i < meta.getColumnCount(); ++i) { + sign = currentRow.getUpdateMask(i) | sign; + } + return sign; } - return sign; } public void updateArray(int columnIndex, Array x) throws SQLException { @@ -1133,12 +1163,12 @@ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { - throw new NotImplementedException(); + updateBigDecimal(getIndexByName(columnName), x); } public void updateBinaryStream(int columnIndex, InputStream x, int length) @@ -1202,27 +1232,27 @@ } public void updateDate(int columnIndex, Date x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateDate(String columnName, Date x) throws SQLException { - throw new NotImplementedException(); + updateDate(getIndexByName(columnName), x); } public void updateDouble(int columnIndex, double x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateDouble(String columnName, double x) throws SQLException { - throw new NotImplementedException(); + updateDouble(getIndexByName(columnName), x); } public void updateFloat(int columnIndex, float x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateFloat(String columnName, float x) throws SQLException { - throw new NotImplementedException(); + updateFloat(getIndexByName(columnName), x); } public void updateInt(int columnIndex, int x) throws SQLException { @@ -1234,11 +1264,11 @@ } public void updateLong(int columnIndex, long x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateLong(String columnName, long x) throws SQLException { - throw new NotImplementedException(); + updateLong(getIndexByName(columnName), x); } public void updateNull(int columnIndex) throws SQLException { @@ -1281,7 +1311,7 @@ // TODO add error messages throw new SQLException(); } - rows.set(currentRowIndex, currentRow); + currentRow.setUpdate(); notifyRowChanged(); } @@ -1302,21 +1332,21 @@ } public void updateTime(int columnIndex, Time x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateTime(String columnName, Time x) throws SQLException { - throw new NotImplementedException(); + updateTime(getIndexByName(columnName), x); } public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - throw new NotImplementedException(); + currentRow.updateObject(columnIndex, x); } public void updateTimestamp(String columnName, Timestamp x) throws SQLException { - throw new NotImplementedException(); + updateTimestamp(getIndexByName(columnName), x); } public boolean wasNull() throws SQLException { Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java?rev=601315&r1=601314&r2=601315&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java Wed Dec 5 04:25:42 2007 @@ -23,47 +23,47 @@ import javax.sql.RowSetInternal; import javax.sql.RowSetReader; -import javax.sql.rowset.CachedRowSet; public class CachedRowSetReader implements RowSetReader { private ResultSet rs; - private int startRow; - private ResultSetMetaData metadata; - public CachedRowSetReader(ResultSet rs, int startRow) throws SQLException { + public CachedRowSetReader(ResultSet rs) throws SQLException { this.rs = rs; - this.startRow = startRow; this.metadata = rs.getMetaData(); } + /** + * TODO disable all listeners + */ public void readData(RowSetInternal theCaller) throws SQLException { - int pageSize = ((CachedRowSet)theCaller).getPageSize(); + CachedRowSetImpl cachedRowSet = (CachedRowSetImpl) theCaller; + int pageSize = cachedRowSet.getPageSize(); + int maxRows = cachedRowSet.getMaxRows(); + ArrayList data = new ArrayList(); - int columnCount = metadata.getColumnCount(); - int tempCursor = 0; - - if (startRow >= 0) { - if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) - throw new SQLException(); - else { - rs.beforeFirst(); - for (int j = 1; j++ < startRow; rs.next()) - ; - } - } - - while ((rs.next())) { + int columnCount = metadata.getColumnCount(); + + while (rs.next()) { Object[] columnData = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { - columnData[i] = rs.getObject(i+1); + columnData[i] = rs.getObject(i + 1); + } + + data.add(new CachedRow(columnData)); + + if (maxRows > 0 && maxRows == data.size()) { + break; + } + + if (pageSize > 0 && data.size() == pageSize) { + break; } - if((pageSize>0)&&(pageSize<++tempCursor)) break; - data.add(new CachedRow(columnData)); - + } - ((CachedRowSetImpl) theCaller).setRows(data, columnCount); + + cachedRowSet.setRows(data, columnCount); } }