harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r596693 [8/9] - in /harmony/enhanced/classlib/branches/java6: ./ depends/jars/ depends/libs/build/ make/ modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/ modules/auth/src/main/java/common/org/apache/harmony/auth/jgss...
Date Tue, 20 Nov 2007 14:43:29 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.java Tue Nov 20 06:42:33 2007
@@ -16,12 +16,19 @@
  */
 package org.apache.harmony.sql.tests.internal.rowset;
 
+import java.math.BigDecimal;
 import java.sql.Connection;
+import java.sql.Date;
 import java.sql.DriverManager;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
 
+import javax.sql.RowSetEvent;
+import javax.sql.RowSetListener;
 import javax.sql.RowSetMetaData;
 import javax.sql.rowset.CachedRowSet;
 
@@ -33,7 +40,7 @@
 
     private static final String DERBY_URL = "jdbc:derby:src/test/resources/TESTDB";
 
-    private Connection conn;
+    private Connection conn = null;
 
     private Statement st;
 
@@ -41,8 +48,11 @@
 
     private CachedRowSet crset;
 
-    public void setUp() throws IllegalAccessException, InstantiationException,
-            ClassNotFoundException, SQLException {
+    private final static int DEFAULT_COLUMN_COUNT = 12;
+
+    private final static int DEFAULT_ROW_COUNT = 4;
+
+    public void setUp() throws Exception {
         Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
 
         try {
@@ -57,20 +67,18 @@
         ;
 
         st = conn.createStatement();
-
         rs = conn.getMetaData().getTables(null, "APP", "USER_INFO", null);
-        // careful: Integer, rather than int!
+        String createTableSQL = "create table USER_INFO (ID INTEGER NOT NULL,NAME VARCHAR(10) NOT NULL, BIGINT_T BIGINT, "
+                + "NUMERIC_T NUMERIC, DECIMAL_T DECIMAL, SMALLINT_T SMALLINT, FLOAT_T FLOAT, REAL_T REAL, DOUBLE_T DOUBLE,"
+                + "DATE_T DATE, TIME_T TIME, TIMESTAMP_T TIMESTAMP)";
+        String alterTableSQL = "ALTER TABLE USER_INFO  ADD CONSTRAINT USER_INFO_PK Primary Key (ID)";
 
         if (!rs.next()) {
-            st
-                    .execute("create table USER_INFO (ID INTEGER NOT NULL,NAME VARCHAR(10) NOT NULL)");
-            st
-                    .execute("ALTER TABLE USER_INFO  ADD CONSTRAINT USER_INFO_PK Primary Key (ID)");
+            st.execute(createTableSQL);
+            st.execute(alterTableSQL);
         }
 
-        st.executeUpdate("delete from USER_INFO");
-        st.executeUpdate("insert into USER_INFO(ID,NAME) values (1,'hermit')");
-        st.executeUpdate("insert into USER_INFO(ID,NAME) values (2,'test')");
+        insertData();
         rs = st.executeQuery("select * from USER_INFO");
         try {
             crset = (CachedRowSet) Class.forName(
@@ -93,12 +101,19 @@
         crset.setUrl(DERBY_URL);
     }
 
-    public void tearDown() throws SQLException {
+    public void tearDown() throws Exception {
         if (rs != null) {
             rs.close();
         }
-        if (crset != null)
+        if (crset != null) {
             crset.close();
+        }
+        if (st != null) {
+            st.close();
+        }
+        if (conn != null) {
+            conn.close();
+        }
     }
 
     public void testSetSyncProvider() throws Exception {
@@ -186,7 +201,7 @@
     }
 
     public void testSize() {
-        assertEquals(2, crset.size());
+        assertEquals(DEFAULT_ROW_COUNT, crset.size());
     }
 
     public void testDeleteRow() throws SQLException {
@@ -200,7 +215,7 @@
         crset.next();
         assertFalse(crset.rowDeleted());
         crset.deleteRow();
-        assertEquals(2, crset.size());
+        assertEquals(DEFAULT_ROW_COUNT, crset.size());
         assertTrue(crset.rowDeleted());
     }
 
@@ -243,15 +258,16 @@
     }
 
     public void testAcceptChanges() throws SQLException {
+        // FIXME: if the value of column is null, it would go wrong when
+        // call acceptChanges(). And if one method in TestCase throws
+        // SQLException, the following method will be affected.
         rs.next();
         assertEquals(1, rs.getInt(1));
-
         assertEquals("hermit", rs.getString(2));
-        crset.first();
-
-        assertEquals(1, crset.getInt(1));
 
-        assertEquals("hermit", crset.getString(2));
+        crset.absolute(3);
+        assertEquals(3, crset.getInt(1));
+        assertEquals("test3", crset.getString(2));
         crset.updateString(2, "HarmonY");
 
         crset.moveToInsertRow();
@@ -268,9 +284,10 @@
 
         rs = st.executeQuery("select * from USER_INFO");
         rs.next();
-        assertEquals(rs.getString(2), "test");
+        assertEquals(rs.getString(2), "hermit");
+        rs.next();
         rs.next();
-        assertEquals(rs.getString(2), "Apache");
+        assertEquals(rs.getString(2), "test4");
 
     }
 
@@ -307,12 +324,45 @@
     }
 
     public void testCreateShared() throws Exception {
+        crset.setUsername("testUsername");
+        crset.setPassword("testPassword");
+        crset.setPageSize(5);
+        Listener listener = new Listener(); // a class implements RowSetListener
+        crset.addRowSetListener(listener);
+        crset.absolute(3); // move to the third row for testing
+        // TODO: when the cursor moved, notifyCursorMoved() should be called
+        // assertEquals("cursorMoved", listener.getTag());
+
         CachedRowSet crsetShared = (CachedRowSet) crset.createShared();
-        crsetShared.first();
-        crset.first();
-        crsetShared.updateString(2, "copyTest2");
-        assertEquals(crsetShared.getString(2), "copyTest2");
-        assertEquals(crset.getString(2), "copyTest2");
+        assertEquals("testUsername", crsetShared.getUsername());
+        assertEquals("testPassword", crsetShared.getPassword());
+        assertEquals(5, crsetShared.getPageSize());
+        // check whether modify the attribute of the original is visible to the
+        // duplicate
+        crset.setUsername("modifyUsername");
+        crset.setPageSize(10);
+        assertEquals("modifyUsername", crset.getUsername());
+        assertEquals("testUsername", crsetShared.getUsername());
+        assertEquals(10, crset.getPageSize());
+        assertEquals(5, crsetShared.getPageSize());
+
+        // compare the current row, that is the third row
+        assertEquals(3, crset.getInt(1));
+        assertEquals("test3", crset.getString(2));
+        assertEquals(3, crsetShared.getInt(1));
+        assertEquals("test3", crsetShared.getString(2));
+        // check whether update the duplicate is visible to the original
+        crsetShared.updateString(2, "modify3");
+        assertEquals("modify3", crsetShared.getString(2));
+        assertEquals("modify3", crset.getString(2));
+        crsetShared.updateRow();
+        crsetShared.acceptChanges();
+        assertEquals("rowSetChanged", listener.getTag());
+
+        // when move the duplicate's cursor, the original shouldn't be affected
+        crsetShared.absolute(1);
+        assertEquals(1, crsetShared.getInt(1));
+        assertEquals(3, crset.getInt(1));
     }
 
     public void testcreateCopyNoConstraints() throws Exception {
@@ -340,49 +390,105 @@
     }
 
     public void testCopySchema() throws Exception {
-        crset.first();
-        CachedRowSet crsetCopySchema = (CachedRowSet) crset.createCopySchema();
+        // the original's addtribute and meta data
+        crset.setCommand("testCommand");
+        crset.setConcurrency(ResultSet.CONCUR_UPDATABLE);
+        crset.setDataSourceName("testDataSource");
+        crset.setFetchDirection(ResultSet.FETCH_UNKNOWN);
+        crset.setPageSize(20);
+        crset.setMaxRows(20);
+        crset.setTableName("USER_INFO");
+        /*
+         * NOTICE: spec say copy must not has any content, but when run on RI,
+         * if call next() before call createCopySchema(), the copy can get the
+         * current row's data
+         */
 
-        RowSetMetaData rsmCopySchema = (RowSetMetaData) crsetCopySchema
+        /*
+         * NOTICE: when run on RI, if add the listener first, then it will go
+         * wrong when call createCopySchema().It's said that clone failed.
+         */
+        // Listener listener = new Listener();
+        // crset.addRowSetListener(listener);
+        RowSetMetaData rsmd = (RowSetMetaData) crset.getMetaData();
+        // the copy
+        CachedRowSet crsetCopySchema = crset.createCopySchema();
+        RowSetMetaData rsmdCopySchema = (RowSetMetaData) crsetCopySchema
                 .getMetaData();
-        assertEquals("USER_INFO", rsmCopySchema.getTableName(1));
-        assertEquals(2, rsmCopySchema.getColumnCount());
 
-        RowSetMetaData rsm = (RowSetMetaData) crset.getMetaData();
-        rsm.setTableName(1, "newBorn");
-        assertEquals("newBorn", rsm.getTableName(1));
-
-        crset.setTableName("test");
-        assertEquals("test", crset.getTableName());
+        // compare the meta data between the duplicate and the original
+        assertNotSame(crset.getMetaData(), crsetCopySchema.getMetaData());
+        assertNotSame(crset.getOriginal(), crsetCopySchema.getOriginal());
+        // assertNotSame(crset.getSyncProvider(), crsetCopySchema
+        // .getSyncProvider());
+
+        assertEquals("USER_INFO", crset.getTableName());
+        assertEquals("USER_INFO", rsmdCopySchema.getTableName(1));
+        assertEquals(DEFAULT_COLUMN_COUNT, rsmdCopySchema.getColumnCount());
+        assertEquals(rsmd.getColumnName(1), rsmdCopySchema.getColumnName(1));
+        // check the primary key
+        // TODO: RI doesn't evalute the keyColumns. The value of
+        // crset.getKeyColumns() is null.
+        assertEquals(crset.getKeyColumns(), crsetCopySchema.getKeyColumns());
+
+        // check the attributes in the duplicate. These are supposed to be the
+        // same as the original
+        // System.out.println("crsetCopySchema: " + crsetCopySchema.getInt(1));
+        assertFalse(crsetCopySchema.next());
+        assertEquals("testCommand", crsetCopySchema.getCommand());
+        assertEquals(ResultSet.CONCUR_UPDATABLE, crsetCopySchema
+                .getConcurrency());
+        assertEquals("testDataSource", crsetCopySchema.getDataSourceName());
+        assertEquals(ResultSet.FETCH_UNKNOWN, crsetCopySchema
+                .getFetchDirection());
+        assertEquals(20, crsetCopySchema.getPageSize());
+        assertEquals(20, crsetCopySchema.getMaxRows());
+
+        // fill the duplicate CachedRowSet with data, check the listener
+        Listener listener = new Listener();
+        crsetCopySchema.addRowSetListener(listener);
+        assertNull(listener.getTag());
+        rs = st.executeQuery("select * from USER_INFO");
+        crsetCopySchema.populate(rs);
+        // TODO: in the Harmony implementation, need to call notifyRowSetChanged
+        // at the suitable place
+        // assertEquals("rowSetChanged", listener.getTag());
+        listener.setTag(null);
+        // the move of the original's cursor shouldn't affect the duplicate
+        crset.next();
+        assertNull(listener.getTag());
     }
 
     public void testCreateCopy() throws Exception {
-        crset.first();
-        assertEquals(crset.getString(2), "hermit");
-        crset.updateString(2, "copyTest");
+        // crset.first();
+        crset.absolute(3);
+        assertEquals(crset.getString(2), "test3");
+        crset.updateString(2, "copyTest3");
         crset.updateRow();
         crset.acceptChanges();
 
         rs = st.executeQuery("select * from USER_INFO");
         rs.next();
-        assertEquals(rs.getString(2), "copyTest");
+        assertEquals(rs.getString(2), "hermit");
 
         CachedRowSet crsetCopy = (CachedRowSet) crset.createCopy();
 
-        crsetCopy.first();
-        crsetCopy.updateString(2, "copyTest2");
+        // crsetCopy.first();
+        crsetCopy.absolute(3);
+        crsetCopy.updateString(2, "copyTest3");
         crsetCopy.updateRow();
         crsetCopy.acceptChanges();
 
-        assertEquals(crsetCopy.getString(2), "copyTest2");
-        assertEquals(crset.getString(2), "copyTest");
+        assertEquals(crsetCopy.getString(2), "copyTest3");
+        assertEquals(crset.getString(2), "copyTest3");
 
         rs = st.executeQuery("select * from USER_INFO");
         rs.next();
-        assertEquals(rs.getString(2), "copyTest2");
+        assertEquals(rs.getString(2), "hermit");
 
-        crset.first();
-        assertEquals(crset.getString(2), "copyTest");
+        // crset.first();
+        crset.absolute(3);
+        assertEquals(crset.getString(2), "copyTest3");
     }
 
     public void testAfterLast() throws Exception {
@@ -395,7 +501,7 @@
 
         crset.afterLast();
         crset.previous();
-        assertEquals(2, crset.getInt(1));
+        assertEquals(4, crset.getInt(1));
     }
 
     public void testNextandPreviousPage() throws Exception {
@@ -460,5 +566,83 @@
         crset.populate(cc, 1);
         crset.first();
         assertEquals("hermit", crset.getString(2));
+    }
+
+    private void insertData() throws Exception {
+
+        st.executeUpdate("delete from USER_INFO");
+
+        // first row
+        st.executeUpdate("insert into USER_INFO(ID,NAME) values (1,'hermit')");
+        // second row
+        st.executeUpdate("insert into USER_INFO(ID,NAME) values (2,'test')");
+
+        String insertSQL = "INSERT INTO USER_INFO(ID, NAME, BIGINT_T, NUMERIC_T, DECIMAL_T, SMALLINT_T, "
+                + "FLOAT_T, REAL_T, DOUBLE_T, DATE_T, TIME_T, TIMESTAMP_T) VALUES(?, ?, ?, ?, ?, ?,"
+                + "?, ?, ?, ?, ?, ? )";
+        PreparedStatement preStmt = conn.prepareStatement(insertSQL);
+        // third row
+        preStmt.setInt(1, 3);
+        preStmt.setString(2, "test3");
+        preStmt.setLong(3, 3333L);
+        preStmt.setBigDecimal(4, new BigDecimal(123));
+        preStmt.setBigDecimal(5, new BigDecimal(23));
+        preStmt.setInt(6, 13);
+        preStmt.setFloat(7, 3.7F);
+        preStmt.setFloat(8, 3.888F);
+        preStmt.setDouble(9, 3.9999);
+        preStmt.setDate(10, new Date(523654123));
+        preStmt.setTime(11, new Time(966554221));
+        preStmt.setTimestamp(12, new Timestamp(521342100));
+        preStmt.executeUpdate();
+        // fourth row
+        preStmt.setInt(1, 4);
+        preStmt.setString(2, "test4");
+        preStmt.setLong(3, 444423L);
+        preStmt.setBigDecimal(4, new BigDecimal(12));
+        preStmt.setBigDecimal(5, new BigDecimal(23));
+        preStmt.setInt(6, 41);
+        preStmt.setFloat(7, 4.8F);
+        preStmt.setFloat(8, 4.888F);
+        preStmt.setDouble(9, 4.9999);
+        preStmt.setDate(10, new Date(965324512));
+        preStmt.setTime(11, new Time(452368512));
+        preStmt.setTimestamp(12, new Timestamp(874532105));
+        preStmt.executeUpdate();
+
+        if (preStmt != null) {
+            preStmt.close();
+        }
+    }
+
+    public class Listener implements RowSetListener, Cloneable {
+
+        private String tag = null;
+
+        public void cursorMoved(RowSetEvent theEvent) {
+            tag = "cursorMoved";
+        }
+
+        public void rowChanged(RowSetEvent theEvent) {
+            tag = "rowChanged";
+        }
+
+        public void rowSetChanged(RowSetEvent theEvent) {
+            tag = "rowSetChanged";
+        }
+
+        public String getTag() {
+            return tag;
+        }
+
+        public void setTag(String tag) {
+            this.tag = tag;
+        }
+
+        public Listener clone() throws CloneNotSupportedException {
+            Listener listener = (Listener) super.clone();
+            listener.tag = tag;
+            return listener;
+        }
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTabbedPaneUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTabbedPaneUI.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTabbedPaneUI.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTabbedPaneUI.java Tue Nov 20 06:42:33 2007
@@ -1690,15 +1690,13 @@
 
     protected void setVisibleComponent(final Component component) {
         Component oldVisible = getVisibleComponent();
-        if (oldVisible == component) {
-            return;
-        }
-
+        if (oldVisible != component) {
         if (oldVisible != null) {
             oldVisible.setVisible(false);
         }
-
         visibleComponent = component;
+        }
+
         if (visibleComponent != null) {
             visibleComponent.setVisible(true);
         }

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/windows/org/apache/harmony/x/swing/filechooser/windows/WinFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/windows/org/apache/harmony/x/swing/filechooser/windows/WinFile.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/windows/org/apache/harmony/x/swing/filechooser/windows/WinFile.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/windows/org/apache/harmony/x/swing/filechooser/windows/WinFile.java Tue Nov 20 06:42:33 2007
@@ -67,10 +67,6 @@
         return WinFileManager.getManager().getParentShellInfo(absoluteItemId);
     }
 
-    public String getName() {
-        return isFileSystem() ? super.getName() : getDisplayName();
-    }
-
     public File getParentFile() {
         Win32.ITEMIDLIST parentItemId = WinFileManager.getManager().getParentItemId(absoluteItemId);
         return parentItemId != null ? WinFileManager.getManager().getWinFile(parentItemId) : null;
@@ -147,6 +143,10 @@
         return getDescription() == WindowsDefs.SHDID_COMPUTER_CDROM;
     }
 
+    public String toString() {
+        return isFileSystem() ? super.toString() : getDisplayName();
+    }
+    
     public boolean isFixedDrive() {
         return getDescription() == WindowsDefs.SHDID_COMPUTER_FIXED;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/make/exclude.common?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/make/exclude.common (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/make/exclude.common Tue Nov 20 06:42:33 2007
@@ -1,5 +1,2 @@
 org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
 org/apache/harmony/text/tests/java/text/MessageFormatTest.java
-org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java
-org/apache/harmony/text/tests/java/text/NumberFormatTest.java
-org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormat.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormat.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormat.java Tue Nov 20 06:42:33 2007
@@ -22,6 +22,7 @@
 import java.util.Date;
 import java.util.Hashtable;
 import java.util.Locale;
+import java.util.ResourceBundle;
 import java.util.TimeZone;
 
 import org.apache.harmony.text.internal.nls.Messages;
@@ -320,8 +321,9 @@
      */
     public final static DateFormat getDateInstance(int style, Locale locale) {
         checkDateStyle(style);
-        com.ibm.icu.text.DateFormat icuFormat = com.ibm.icu.text.DateFormat.getDateInstance(style, locale);
-        return new SimpleDateFormat(locale, (com.ibm.icu.text.SimpleDateFormat)icuFormat);
+        ResourceBundle bundle = getBundle(locale);
+        String pattern = bundle.getString("Date_" + getStyleName(style)); //$NON-NLS-1$
+        return new SimpleDateFormat(pattern, locale);
     }
 
     /**
@@ -368,8 +370,10 @@
             int timeStyle, Locale locale) {
         checkTimeStyle(timeStyle);
         checkDateStyle(dateStyle);
-        com.ibm.icu.text.DateFormat icuFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
-        return new SimpleDateFormat(locale, (com.ibm.icu.text.SimpleDateFormat)icuFormat);
+        ResourceBundle bundle = getBundle(locale);
+        String pattern = bundle.getString("Date_" + getStyleName(dateStyle)) //$NON-NLS-1$
+                + " " + bundle.getString("Time_" + getStyleName(timeStyle)); //$NON-NLS-1$ //$NON-NLS-2$
+        return new SimpleDateFormat(pattern, locale);
     }
 
     /**
@@ -447,8 +451,9 @@
      */
     public final static DateFormat getTimeInstance(int style, Locale locale) {
         checkTimeStyle(style);
-        com.ibm.icu.text.DateFormat icuFormat = com.ibm.icu.text.DateFormat.getTimeInstance(style, locale);
-        return new SimpleDateFormat(locale, (com.ibm.icu.text.SimpleDateFormat)icuFormat);
+        ResourceBundle bundle = getBundle(locale);
+        String pattern = bundle.getString("Time_" + getStyleName(style)); //$NON-NLS-1$
+        return new SimpleDateFormat(pattern, locale);
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DateFormatSymbols.java Tue Nov 20 06:42:33 2007
@@ -20,6 +20,7 @@
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Locale;
+import java.util.ResourceBundle;
 
 /**
  * DateFormatSymbols holds the Strings used in the formating and parsing of
@@ -51,16 +52,15 @@
      *            the Locale
      */
     public DateFormatSymbols(Locale locale) {
-        com.ibm.icu.text.DateFormatSymbols icuSymbols = new com.ibm.icu.text.DateFormatSymbols(locale);
-        
-        localPatternChars = icuSymbols.getLocalPatternChars();
-        ampms = icuSymbols.getAmPmStrings();
-        eras = icuSymbols.getEras();
-        months = icuSymbols.getMonths();
-        shortMonths = icuSymbols.getShortMonths();
-        shortWeekdays = icuSymbols.getShortWeekdays();
-        weekdays = icuSymbols.getWeekdays();
-        zoneStrings = icuSymbols.getZoneStrings();
+        ResourceBundle bundle = Format.getBundle(locale);
+        localPatternChars = bundle.getString("LocalPatternChars"); //$NON-NLS-1$
+        ampms = bundle.getStringArray("ampm"); //$NON-NLS-1$
+        eras = bundle.getStringArray("eras"); //$NON-NLS-1$
+        months = bundle.getStringArray("months"); //$NON-NLS-1$
+        shortMonths = bundle.getStringArray("shortMonths"); //$NON-NLS-1$
+        shortWeekdays = bundle.getStringArray("shortWeekdays"); //$NON-NLS-1$
+        weekdays = bundle.getStringArray("weekdays"); //$NON-NLS-1$
+        zoneStrings = (String[][]) bundle.getObject("timezones"); //$NON-NLS-1$
     }
 
     /**
@@ -273,9 +273,7 @@
         }
         for (String[] element : zoneStrings) {
             for (int j = 0; j < element.length; j++) {
-                if (element[j] != null) {
-                    hashCode += element[j].hashCode();
-                }
+                hashCode += element[j].hashCode();
             }
         }
         return hashCode;

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormat.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormat.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormat.java Tue Nov 20 06:42:33 2007
@@ -54,15 +54,7 @@
      * default Locale.
      */
     public DecimalFormat() {
-        Locale locale = Locale.getDefault();
-        icuSymbols = new com.ibm.icu.text.DecimalFormatSymbols(locale);
-        symbols = new DecimalFormatSymbols(locale);
-        dform = new com.ibm.icu.text.DecimalFormat();
-
-        super.setMaximumFractionDigits(dform.getMaximumFractionDigits());
-        super.setMaximumIntegerDigits(dform.getMaximumIntegerDigits());
-        super.setMinimumFractionDigits(dform.getMinimumFractionDigits());
-        super.setMinimumIntegerDigits(dform.getMinimumIntegerDigits());
+        this(getPattern(Locale.getDefault(), "Number")); //$NON-NLS-1$
     }
 
     /**
@@ -76,15 +68,7 @@
      *                when the pattern cannot be parsed
      */
     public DecimalFormat(String pattern) {
-        Locale locale = Locale.getDefault();
-        icuSymbols = new com.ibm.icu.text.DecimalFormatSymbols(locale);
-        symbols = new DecimalFormatSymbols(locale);
-        dform = new com.ibm.icu.text.DecimalFormat(pattern, icuSymbols);
-
-        super.setMaximumFractionDigits(dform.getMaximumFractionDigits());
-        super.setMaximumIntegerDigits(dform.getMaximumIntegerDigits());
-        super.setMinimumFractionDigits(dform.getMinimumFractionDigits());
-        super.setMinimumIntegerDigits(dform.getMinimumIntegerDigits());
+        this(pattern, new DecimalFormatSymbols());
     }
 
     /**
@@ -101,7 +85,7 @@
      */
     public DecimalFormat(String pattern, DecimalFormatSymbols value) {
         symbols = (DecimalFormatSymbols) value.clone();
-        Locale locale = (Locale) Format.getInternalField("locale", symbols); //$NON-NLS-1$
+        Locale locale = (Locale) this.getInternalField("locale", symbols); //$NON-NLS-1$
         icuSymbols = new com.ibm.icu.text.DecimalFormatSymbols(locale);
         copySymbols(icuSymbols, symbols);
 
@@ -727,16 +711,16 @@
         fields.put("positiveSuffix", dform.getPositiveSuffix());
         fields.put("negativePrefix", dform.getNegativePrefix());
         fields.put("negativeSuffix", dform.getNegativeSuffix());
-        String posPrefixPattern = (String) Format.getInternalField(
+        String posPrefixPattern = (String) this.getInternalField(
                 "posPrefixPattern", dform);
         fields.put("posPrefixPattern", posPrefixPattern);
-        String posSuffixPattern = (String) Format.getInternalField(
+        String posSuffixPattern = (String) this.getInternalField(
                 "posSuffixPattern", dform);
         fields.put("posSuffixPattern", posSuffixPattern);
-        String negPrefixPattern = (String) Format.getInternalField(
+        String negPrefixPattern = (String) this.getInternalField(
                 "negPrefixPattern", dform);
         fields.put("negPrefixPattern", negPrefixPattern);
-        String negSuffixPattern = (String) Format.getInternalField(
+        String negSuffixPattern = (String) this.getInternalField(
                 "negSuffixPattern", dform);
         fields.put("negSuffixPattern", negSuffixPattern);
         fields.put("multiplier", dform.getMultiplier());
@@ -745,10 +729,10 @@
                 .isDecimalSeparatorAlwaysShown());
         fields.put("parseBigDecimal", parseBigDecimal);
         fields.put("symbols", symbols);
-        boolean useExponentialNotation = ((Boolean) Format.getInternalField(
+        boolean useExponentialNotation = ((Boolean) this.getInternalField(
                 "useExponentialNotation", dform)).booleanValue();
         fields.put("useExponentialNotation", useExponentialNotation);
-        byte minExponentDigits = ((Byte) Format.getInternalField(
+        byte minExponentDigits = ((Byte) this.getInternalField(
                 "minExponentDigits", dform)).byteValue();
         fields.put("minExponentDigits", minExponentDigits);
         fields.put("maximumIntegerDigits", dform.getMaximumIntegerDigits());
@@ -802,7 +786,7 @@
         int minimumFractionDigits = fields.get("minimumFractionDigits", 340);
         this.serialVersionOnStream = fields.get("serialVersionOnStream", 0);
 
-        Locale locale = (Locale) Format.getInternalField("locale", symbols);
+        Locale locale = (Locale) getInternalField("locale", symbols);
         dform = new com.ibm.icu.text.DecimalFormat("",
                 new com.ibm.icu.text.DecimalFormatSymbols(locale));
         setInternalField("useExponentialNotation", dform, Boolean
@@ -847,14 +831,8 @@
      */
     private void copySymbols(final com.ibm.icu.text.DecimalFormatSymbols icu,
             final DecimalFormatSymbols dfs) {
-        Currency currency = dfs.getCurrency();
-        if (currency == null) {
-            icu.setCurrency(com.ibm.icu.util.Currency.getInstance("XXX"));
-        } else {
-            icu.setCurrency(com.ibm.icu.util.Currency.getInstance(dfs
-                    .getCurrency().getCurrencyCode()));
-        }
-       
+        icu.setCurrency(com.ibm.icu.util.Currency.getInstance(dfs.getCurrency()
+                .getCurrencyCode()));
         icu.setCurrencySymbol(dfs.getCurrencySymbol());
         icu.setDecimalSeparator(dfs.getDecimalSeparator());
         icu.setDigit(dfs.getDigit());
@@ -895,6 +873,32 @@
                         return field;
                     }
                 });
+    }
+
+    /*
+     * Gets private field value by reflection.
+     * 
+     * @param fieldName the field name to be set @param target the object which
+     * field to be gotten
+     */
+    private Object getInternalField(final String fieldName, final Object target) {
+        Object value = AccessController
+                .doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        Object result = null;
+                        java.lang.reflect.Field field = null;
+                        try {
+                            field = target.getClass().getDeclaredField(
+                                    fieldName);
+                            field.setAccessible(true);
+                            result = field.get(target);
+                        } catch (Exception e1) {
+                            return null;
+                        }
+                        return result;
+                    }
+                });
+        return value;
     }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormatSymbols.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormatSymbols.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormatSymbols.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/DecimalFormatSymbols.java Tue Nov 20 06:42:33 2007
@@ -19,9 +19,13 @@
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
 import java.io.Serializable;
+import java.util.Arrays;
 import java.util.Currency;
 import java.util.Locale;
+import java.util.ResourceBundle;
 
 /**
  * DecimalFormatSymbols holds the symbols used in the formating and parsing of
@@ -31,26 +35,18 @@
 
     private static final long serialVersionUID = 5772796243397350300L;
 
-    private char zeroDigit;
-    private char groupingSeparator;
-    private char decimalSeparator;
-    private char perMill;
-    private char percent;
-    private char digit;
-    private char patternSeparator;
-    private String infinity;
-    private String NaN;
-    private char minusSign;
-    private String currencySymbol;
-    private String intlCurrencySymbol;
-    private char monetarySeparator;
-    private char exponential;
-    private Locale locale;
-    // 3 indicates version 5 and later
-    private int serialVersionOnStream = 3;
+    private final int ZeroDigit = 0, Digit = 1, DecimalSeparator = 2,
+            GroupingSeparator = 3, PatternSeparator = 4, Percent = 5,
+            PerMill = 6, Exponent = 7, MonetaryDecimalSeparator = 8,
+            MinusSign = 9;
+
+    transient char[] patternChars;
+
     private transient Currency currency;
 
-    private transient com.ibm.icu.text.DecimalFormatSymbols icuSymbols;
+    private transient Locale locale;
+
+    private String infinity, NaN, currencySymbol, intlCurrencySymbol;
 
     /**
      * Constructs a new DecimalFormatSymbols containing the symbols for the
@@ -68,27 +64,20 @@
      *            the Locale
      */
     public DecimalFormatSymbols(Locale locale) {
-        icuSymbols = new com.ibm.icu.text.DecimalFormatSymbols(locale);
-        infinity = icuSymbols.getInfinity();
-        NaN = icuSymbols.getNaN();
+        ResourceBundle bundle = Format.getBundle(locale);
+        patternChars = bundle.getString("DecimalPatternChars").toCharArray(); //$NON-NLS-1$
+        infinity = bundle.getString("Infinity"); //$NON-NLS-1$
+        NaN = bundle.getString("NaN"); //$NON-NLS-1$
         this.locale = locale;
-        currencySymbol = icuSymbols.getCurrencySymbol();
-        intlCurrencySymbol = icuSymbols.getInternationalCurrencySymbol();
-        if (locale.getCountry().length() == 0) {
-            currency = Currency.getInstance("XXX");
-        } else {
+        try {
             currency = Currency.getInstance(locale);
+            currencySymbol = currency.getSymbol(locale);
+            intlCurrencySymbol = currency.getCurrencyCode();
+        } catch (IllegalArgumentException e) {
+            currency = Currency.getInstance("XXX"); //$NON-NLS-1$
+            currencySymbol = bundle.getString("CurrencySymbol"); //$NON-NLS-1$
+            intlCurrencySymbol = bundle.getString("IntCurrencySymbol"); //$NON-NLS-1$
         }
-        zeroDigit = icuSymbols.getZeroDigit();
-        digit = icuSymbols.getDigit();
-        decimalSeparator = icuSymbols.getDecimalSeparator();
-        groupingSeparator = icuSymbols.getGroupingSeparator();
-        patternSeparator = icuSymbols.getPatternSeparator();
-        percent = icuSymbols.getPercent();
-        perMill = icuSymbols.getPerMill();
-        exponential = 'E';
-        monetarySeparator = icuSymbols.getMonetaryDecimalSeparator();
-        minusSign = icuSymbols.getMinusSign();
     }
 
     /**
@@ -103,6 +92,7 @@
     public Object clone() {
         try {
             DecimalFormatSymbols symbols = (DecimalFormatSymbols) super.clone();
+            symbols.patternChars = patternChars.clone();
             return symbols;
         } catch (CloneNotSupportedException e) {
             return null;
@@ -130,15 +120,8 @@
             return false;
         }
         DecimalFormatSymbols obj = (DecimalFormatSymbols) object;
-        return zeroDigit == obj.zeroDigit && digit == obj.digit
-                && decimalSeparator == obj.decimalSeparator
-                && groupingSeparator == obj.groupingSeparator
-                && patternSeparator == obj.patternSeparator
-                && percent == obj.percent && perMill == obj.perMill
-                && exponential == obj.exponential
-                && monetarySeparator == obj.monetarySeparator
-                && minusSign == obj.minusSign && infinity.equals(obj.infinity)
-                && NaN.equals(obj.NaN)
+        return Arrays.equals(patternChars, obj.patternChars)
+                && infinity.equals(obj.infinity) && NaN.equals(obj.NaN)
                 && currencySymbol.equals(obj.currencySymbol)
                 && intlCurrencySymbol.equals(obj.intlCurrencySymbol);
     }
@@ -151,8 +134,8 @@
      * with a value that is not a valid ISO 4217 currency code.
      * <p>
      *
-     * @return      the currency that was set in the constructor, <code>setCurrency()</code>,
-     *              or <code>setInternationalCurrencySymbol()</code>, or </code>null</code>
+     * @return		the currency that was set in the constructor, <code>setCurrency()</code>,
+     * 				or <code>setInternationalCurrencySymbol()</code>, or </code>null</code>
      * 
      * @see #setCurrency(Currency)
      * @see #setInternationalCurrencySymbol(String)
@@ -185,7 +168,7 @@
      * @return a char
      */
     public char getDecimalSeparator() {
-        return decimalSeparator;
+        return patternChars[DecimalSeparator];
     }
 
     /**
@@ -195,7 +178,7 @@
      * @return a char
      */
     public char getDigit() {
-        return digit;
+        return patternChars[Digit];
     }
 
     /**
@@ -204,7 +187,7 @@
      * @return a char
      */
     public char getGroupingSeparator() {
-        return groupingSeparator;
+        return patternChars[GroupingSeparator];
     }
 
     /**
@@ -218,8 +201,7 @@
 
     String getLocalPatternChars() {
         // Don't include the MonetaryDecimalSeparator or the MinusSign
-        return new String(new char[]{zeroDigit, digit, decimalSeparator, groupingSeparator,
-                patternSeparator, percent, perMill, exponential});
+        return new String(patternChars, 0, patternChars.length - 2);
     }
 
     /**
@@ -228,7 +210,7 @@
      * @return a char
      */
     public char getMinusSign() {
-        return minusSign;
+        return patternChars[MinusSign];
     }
 
     /**
@@ -238,7 +220,7 @@
      * @return a char
      */
     public char getMonetaryDecimalSeparator() {
-        return monetarySeparator;
+        return patternChars[MonetaryDecimalSeparator];
     }
 
     /**
@@ -257,7 +239,7 @@
      * @return a char
      */
     public char getPatternSeparator() {
-        return patternSeparator;
+        return patternChars[PatternSeparator];
     }
 
     /**
@@ -266,7 +248,7 @@
      * @return a char
      */
     public char getPercent() {
-        return percent;
+        return patternChars[Percent];
     }
 
     /**
@@ -275,7 +257,7 @@
      * @return a char
      */
     public char getPerMill() {
-        return perMill;
+        return patternChars[PerMill];
     }
 
     /**
@@ -284,11 +266,11 @@
      * @return a char
      */
     public char getZeroDigit() {
-        return zeroDigit;
+        return patternChars[ZeroDigit];
     }
 
     char getExponential() {
-        return exponential;
+        return patternChars[Exponent];
     }
 
     /**
@@ -301,12 +283,9 @@
      */
     @Override
     public int hashCode() {
-        return new String(new char[] { zeroDigit, digit, decimalSeparator,
-                groupingSeparator, patternSeparator, percent, perMill,
-                exponential, monetarySeparator, minusSign }).hashCode()
-                + infinity.hashCode()
-                + NaN.hashCode()
-                + currencySymbol.hashCode() + intlCurrencySymbol.hashCode();
+        return new String(patternChars).hashCode() + infinity.hashCode()
+                + NaN.hashCode() + currencySymbol.hashCode()
+                + intlCurrencySymbol.hashCode();
     }
 
     /**
@@ -382,7 +361,7 @@
      *            the decimal separator character
      */
     public void setDecimalSeparator(char value) {
-        decimalSeparator = value;
+        patternChars[DecimalSeparator] = value;
     }
 
     /**
@@ -392,7 +371,7 @@
      *            the digit character
      */
     public void setDigit(char value) {
-        digit = value;
+        patternChars[Digit] = value;
     }
 
     /**
@@ -402,7 +381,7 @@
      *            the grouping separator character
      */
     public void setGroupingSeparator(char value) {
-        groupingSeparator = value;
+        patternChars[GroupingSeparator] = value;
     }
 
     /**
@@ -422,7 +401,7 @@
      *            the minus sign character
      */
     public void setMinusSign(char value) {
-        minusSign = value;
+        patternChars[MinusSign] = value;
     }
 
     /**
@@ -433,7 +412,7 @@
      *            the monetary decimal separator character
      */
     public void setMonetaryDecimalSeparator(char value) {
-        monetarySeparator = value;
+        patternChars[MonetaryDecimalSeparator] = value;
     }
 
     /**
@@ -454,7 +433,7 @@
      *            the pattern separator character
      */
     public void setPatternSeparator(char value) {
-        patternSeparator = value;
+        patternChars[PatternSeparator] = value;
     }
 
     /**
@@ -464,7 +443,7 @@
      *            the percent character
      */
     public void setPercent(char value) {
-        percent = value;
+        patternChars[Percent] = value;
     }
 
     /**
@@ -474,7 +453,7 @@
      *            the mille percent character
      */
     public void setPerMill(char value) {
-        perMill = value;
+        patternChars[PerMill] = value;
     }
 
     /**
@@ -484,16 +463,56 @@
      *            the zero digit character
      */
     public void setZeroDigit(char value) {
-        zeroDigit = value;
+        patternChars[ZeroDigit] = value;
     }
 
     void setExponential(char value) {
-        exponential = value;
+        patternChars[Exponent] = value;
+    }
+
+    private static final ObjectStreamField[] serialPersistentFields = {
+            new ObjectStreamField("currencySymbol", String.class), //$NON-NLS-1$
+            new ObjectStreamField("decimalSeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("digit", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("exponential", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("groupingSeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("infinity", String.class), //$NON-NLS-1$
+            new ObjectStreamField("intlCurrencySymbol", String.class), //$NON-NLS-1$
+            new ObjectStreamField("minusSign", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("monetarySeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("NaN", String.class), //$NON-NLS-1$
+            new ObjectStreamField("patternSeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("percent", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("perMill", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("serialVersionOnStream", Integer.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("zeroDigit", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("locale", Locale.class), }; //$NON-NLS-1$
+
+    private void writeObject(ObjectOutputStream stream) throws IOException {
+        ObjectOutputStream.PutField fields = stream.putFields();
+        fields.put("currencySymbol", currencySymbol); //$NON-NLS-1$
+        fields.put("decimalSeparator", getDecimalSeparator()); //$NON-NLS-1$
+        fields.put("digit", getDigit()); //$NON-NLS-1$
+        fields.put("exponential", getExponential()); //$NON-NLS-1$
+        fields.put("groupingSeparator", getGroupingSeparator()); //$NON-NLS-1$
+        fields.put("infinity", infinity); //$NON-NLS-1$
+        fields.put("intlCurrencySymbol", intlCurrencySymbol); //$NON-NLS-1$
+        fields.put("minusSign", getMinusSign()); //$NON-NLS-1$
+        fields.put("monetarySeparator", getMonetaryDecimalSeparator()); //$NON-NLS-1$
+        fields.put("NaN", NaN); //$NON-NLS-1$
+        fields.put("patternSeparator", getPatternSeparator()); //$NON-NLS-1$
+        fields.put("percent", getPercent()); //$NON-NLS-1$
+        fields.put("perMill", getPerMill()); //$NON-NLS-1$
+        fields.put("serialVersionOnStream", 1); //$NON-NLS-1$
+        fields.put("zeroDigit", getZeroDigit()); //$NON-NLS-1$
+        fields.put("locale", locale); //$NON-NLS-1$
+        stream.writeFields();
     }
 
     private void readObject(ObjectInputStream stream) throws IOException,
             ClassNotFoundException {
         ObjectInputStream.GetField fields = stream.readFields();
+        patternChars = new char[10];
         currencySymbol = (String) fields.get("currencySymbol", ""); //$NON-NLS-1$ //$NON-NLS-2$
         setDecimalSeparator(fields.get("decimalSeparator", '.')); //$NON-NLS-1$
         setDigit(fields.get("digit", '#')); //$NON-NLS-1$
@@ -520,9 +539,5 @@
         } catch (IllegalArgumentException e) {
             currency = null;
         }
-    }
-    
-    Locale getLocale(){
-        return locale;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Format.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Format.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Format.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/Format.java Tue Nov 20 06:42:33 2007
@@ -20,6 +20,8 @@
 import java.io.Serializable;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.Locale;
+import java.util.ResourceBundle;
 
 import org.apache.harmony.text.internal.nls.Messages;
 
@@ -54,6 +56,17 @@
         }
     }
 
+    static ResourceBundle getBundle(final Locale locale) {
+        return AccessController
+                .doPrivileged(new PrivilegedAction<ResourceBundle>() {
+                    public ResourceBundle run() {
+                        return ResourceBundle
+                                .getBundle(
+                                        "org.apache.harmony.luni.internal.locale.Locale", locale); //$NON-NLS-1$
+                    }
+                });
+    }
+
     String convertPattern(String template, String fromChars, String toChars,
             boolean check) {
         if (!check && fromChars.equals(toChars)) {
@@ -176,32 +189,6 @@
      * @return the object resulting from the parse, or null if there is an error
      */
     public abstract Object parseObject(String string, ParsePosition position);
-
-    /*
-     * Gets private field value by reflection.
-     * 
-     * @param fieldName the field name to be set @param target the object which
-     * field to be gotten
-     */
-    static Object getInternalField(final String fieldName, final Object target) {
-        Object value = AccessController
-                .doPrivileged(new PrivilegedAction<Object>() {
-                    public Object run() {
-                        Object result = null;
-                        java.lang.reflect.Field field = null;
-                        try {
-                            field = target.getClass().getDeclaredField(
-                                    fieldName);
-                            field.setAccessible(true);
-                            result = field.get(target);
-                        } catch (Exception e1) {
-                            return null;
-                        }
-                        return result;
-                    }
-                });
-        return value;
-    }
 
     static boolean upTo(String string, ParsePosition position,
             StringBuffer buffer, char stop) {

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/NumberFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/NumberFormat.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/NumberFormat.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/NumberFormat.java Tue Nov 20 06:42:33 2007
@@ -24,6 +24,7 @@
 import java.io.ObjectStreamField;
 import java.util.Currency;
 import java.util.Locale;
+import java.util.ResourceBundle;
 
 import org.apache.harmony.text.internal.nls.Messages;
 
@@ -229,10 +230,7 @@
      * @return a NumberFormat
      */
     public static NumberFormat getCurrencyInstance(Locale locale) {
-        com.ibm.icu.text.DecimalFormat icuFormat = (com.ibm.icu.text.DecimalFormat) com.ibm.icu.text.NumberFormat
-                .getCurrencyInstance(locale);
-        String pattern = icuFormat.toPattern();
-        return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
+        return getInstance(locale, "Currency"); //$NON-NLS-1$
     }
 
     /**
@@ -254,13 +252,9 @@
      * @return a NumberFormat
      */
     public static NumberFormat getIntegerInstance(Locale locale) {
-        com.ibm.icu.text.DecimalFormat icuFormat = (com.ibm.icu.text.DecimalFormat) com.ibm.icu.text.NumberFormat
-                .getIntegerInstance(locale);
-        String pattern = icuFormat.toPattern();
-        DecimalFormat format = new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
+        NumberFormat format = getInstance(locale, "Integer"); //$NON-NLS-1$
         format.setParseIntegerOnly(true);
         return format;
-        
     }
 
     /**
@@ -285,6 +279,11 @@
         return getNumberInstance(locale);
     }
 
+    static NumberFormat getInstance(Locale locale, String type) {
+        return new DecimalFormat(getPattern(locale, type),
+                new DecimalFormatSymbols(locale));
+    }
+
     /**
      * Answers the maximum number of fraction digits that are printed when
      * formatting. If the maximum is less than the number of fraction digits,
@@ -346,10 +345,12 @@
      * @return a NumberFormat
      */
     public static NumberFormat getNumberInstance(Locale locale) {
-        com.ibm.icu.text.DecimalFormat icuFormat = (com.ibm.icu.text.DecimalFormat) com.ibm.icu.text.NumberFormat
-                .getNumberInstance(locale);
-        String pattern = icuFormat.toPattern();
-        return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
+        return getInstance(locale, "Number"); //$NON-NLS-1$
+    }
+
+    static String getPattern(Locale locale, String type) {
+        ResourceBundle bundle = getBundle(locale);
+        return bundle.getString(type);
     }
 
     /**
@@ -371,10 +372,7 @@
      * @return a NumberFormat
      */
     public static NumberFormat getPercentInstance(Locale locale) {
-        com.ibm.icu.text.DecimalFormat icuFormat = (com.ibm.icu.text.DecimalFormat) com.ibm.icu.text.NumberFormat
-                .getPercentInstance(locale);
-        String pattern = icuFormat.toPattern();
-        return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
+        return getInstance(locale, "Percent"); //$NON-NLS-1$
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/SimpleDateFormat.java Tue Nov 20 06:42:33 2007
@@ -25,6 +25,10 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+import java.util.Vector;
 
 import org.apache.harmony.text.internal.nls.Messages;
 
@@ -40,7 +44,7 @@
 
     private static final long serialVersionUID = 4774881970558875024L;
 
-    private static final String patternChars = "GyMdkHmsSEDFwWahKzYeugAZvcLQqV"; //$NON-NLS-1$
+    private static final String patternChars = "GyMdkHmsSEDFwWahKzZ"; //$NON-NLS-1$
 
     private String pattern;
 
@@ -50,16 +54,13 @@
 
     private Date defaultCenturyStart;
 
-    private transient com.ibm.icu.text.SimpleDateFormat icuFormat;
-
     /**
      * Constructs a new SimpleDateFormat for formatting and parsing dates and
      * times in the SHORT style for the default Locale.
      */
     public SimpleDateFormat() {
         this(Locale.getDefault());
-        icuFormat = new com.ibm.icu.text.SimpleDateFormat();
-        pattern = (String)getInternalField("pattern",icuFormat);
+        pattern = defaultPattern();
         formatData = new DateFormatSymbols(Locale.getDefault());
     }
 
@@ -80,86 +81,7 @@
     public SimpleDateFormat(String pattern) {
         this(pattern, Locale.getDefault());
     }
-    
-    /**
-     * Validate the format character.
-     * 
-     * @param format
-     *            the format character
-     * 
-     * @throws IllegalArgumentException
-     *             when the format character is invalid
-     */
-    private void validateFormat(char format) {
-        int index = patternChars.indexOf(format);
-        if (index == -1) {
-            // text.03=Unknown pattern character - '{0}'
-            throw new IllegalArgumentException(Messages.getString(
-                    "text.03", format)); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Validate the pattern.
-     * 
-     * @param template
-     *            the pattern to validate.
-     * 
-     * @throws NullPointerException
-     *             if the pattern is null
-     * @throws IllegalArgumentException
-     *             if the pattern is invalid
-     */
-    private void validatePattern(String template) {
-        boolean quote = false;
-        int next, last = -1, count = 0;
-
-        final int patternLength = template.length();
-        for (int i = 0; i < patternLength; i++) {
-            next = (template.charAt(i));
-            if (next == '\'') {
-                if (count > 0) {
-                    validateFormat((char) last);
-                    count = 0;
-                }
-                if (last == next) {
-                    last = -1;
-                } else {
-                    last = next;
-                }
-                quote = !quote;
-                continue;
-            }
-            if (!quote
-                    && (last == next || (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
-                if (last == next) {
-                    count++;
-                } else {
-                    if (count > 0) {
-                        validateFormat((char) last);
-                    }
-                    last = next;
-                    count = 1;
-                }
-            } else {
-                if (count > 0) {
-                    validateFormat((char) last);
-                    count = 0;
-                }
-                last = -1;
-            }
-        }
-        if (count > 0) {
-            validateFormat((char) last);
-        }
-
-        if (quote) {
-            // text.04=Unterminated quote {0}
-            throw new IllegalArgumentException(Messages.getString("text.04")); //$NON-NLS-1$
-        }
 
-    }
-    
     /**
      * Constructs a new SimpleDateFormat using the specified non-localized
      * pattern and DateFormatSymbols and the Calendar for the default Locale.
@@ -177,22 +99,10 @@
     public SimpleDateFormat(String template, DateFormatSymbols value) {
         this(Locale.getDefault());
         validatePattern(template);
-        icuFormat = new com.ibm.icu.text.SimpleDateFormat(template, Locale.getDefault());
         pattern = template;
         formatData = (DateFormatSymbols) value.clone();
     }
 
-    private void copySymbols(DateFormatSymbols value, com.ibm.icu.text.DateFormatSymbols icuSymbols) {
-        icuSymbols.setAmPmStrings(value.getAmPmStrings());
-        icuSymbols.setEras(value.getEras());
-        icuSymbols.setLocalPatternChars(value.getLocalPatternChars());
-        icuSymbols.setMonths(value.getMonths());
-        icuSymbols.setShortMonths(value.getShortMonths());
-        icuSymbols.setShortWeekdays(value.getShortWeekdays());
-        icuSymbols.setWeekdays(value.getWeekdays());
-        icuSymbols.setZoneStrings(value.getZoneStrings());
-    }
-    
     /**
      * Constructs a new SimpleDateFormat using the specified non-localized
      * pattern and the DateFormatSymbols and Calendar for the specified Locale.
@@ -210,18 +120,10 @@
     public SimpleDateFormat(String template, Locale locale) {
         this(locale);
         validatePattern(template);
-        icuFormat = new com.ibm.icu.text.SimpleDateFormat(template, locale);
         pattern = template;
         formatData = new DateFormatSymbols(locale);
     }
 
-    SimpleDateFormat(Locale locale, com.ibm.icu.text.SimpleDateFormat icuFormat){
-        this(locale);
-        this.icuFormat = icuFormat;
-        pattern = (String)Format.getInternalField("pattern", icuFormat);
-        formatData = new DateFormatSymbols(locale);
-    }
-    
     private SimpleDateFormat(Locale locale) {
         numberFormat = NumberFormat.getInstance(locale);
         numberFormat.setParseIntegerOnly(true);
@@ -232,6 +134,194 @@
         defaultCenturyStart = calendar.getTime();
     }
 
+    private void append(StringBuffer buffer, FieldPosition position,
+            Vector<FieldPosition> fields, char format, int count) {
+        int field = -1;
+        int index = patternChars.indexOf(format);
+        if (index == -1) {
+            // text.03=Unknown pattern character - '{0}'
+            throw new IllegalArgumentException(Messages.getString(
+                    "text.03", format)); //$NON-NLS-1$
+        }
+
+        int beginPosition = buffer.length();
+        Field dateFormatField = null;
+
+        switch (index) {
+            case ERA_FIELD:
+                dateFormatField = Field.ERA;
+                buffer.append(formatData.eras[calendar.get(Calendar.ERA)]);
+                break;
+            case YEAR_FIELD:
+                dateFormatField = Field.YEAR;
+                int year = calendar.get(Calendar.YEAR);
+                if (count < 4) {
+                    appendNumber(buffer, 2, year %= 100);
+                } else {
+                    appendNumber(buffer, count, year);
+                }
+                break;
+            case MONTH_FIELD:
+                dateFormatField = Field.MONTH;
+                int month = calendar.get(Calendar.MONTH);
+                if (count <= 2) {
+                    appendNumber(buffer, count, month + 1);
+                } else if (count == 3) {
+                    buffer.append(formatData.shortMonths[month]);
+                } else {
+                    buffer.append(formatData.months[month]);
+                }
+                break;
+            case DATE_FIELD:
+                dateFormatField = Field.DAY_OF_MONTH;
+                field = Calendar.DATE;
+                break;
+            case HOUR_OF_DAY1_FIELD: // k
+                dateFormatField = Field.HOUR_OF_DAY1;
+                int hour = calendar.get(Calendar.HOUR_OF_DAY);
+                appendNumber(buffer, count, hour == 0 ? 24 : hour);
+                break;
+            case HOUR_OF_DAY0_FIELD: // H
+                dateFormatField = Field.HOUR_OF_DAY0;
+                field = Calendar.HOUR_OF_DAY;
+                break;
+            case MINUTE_FIELD:
+                dateFormatField = Field.MINUTE;
+                field = Calendar.MINUTE;
+                break;
+            case SECOND_FIELD:
+                dateFormatField = Field.SECOND;
+                field = Calendar.SECOND;
+                break;
+            case MILLISECOND_FIELD:
+                dateFormatField = Field.MILLISECOND;
+                int value = calendar.get(Calendar.MILLISECOND);
+                appendNumber(buffer, count, value);
+                break;
+            case DAY_OF_WEEK_FIELD:
+                dateFormatField = Field.DAY_OF_WEEK;
+                int day = calendar.get(Calendar.DAY_OF_WEEK);
+                if (count < 4) {
+                    buffer.append(formatData.shortWeekdays[day]);
+                } else {
+                    buffer.append(formatData.weekdays[day]);
+                }
+                break;
+            case DAY_OF_YEAR_FIELD:
+                dateFormatField = Field.DAY_OF_YEAR;
+                field = Calendar.DAY_OF_YEAR;
+                break;
+            case DAY_OF_WEEK_IN_MONTH_FIELD:
+                dateFormatField = Field.DAY_OF_WEEK_IN_MONTH;
+                field = Calendar.DAY_OF_WEEK_IN_MONTH;
+                break;
+            case WEEK_OF_YEAR_FIELD:
+                dateFormatField = Field.WEEK_OF_YEAR;
+                field = Calendar.WEEK_OF_YEAR;
+                break;
+            case WEEK_OF_MONTH_FIELD:
+                dateFormatField = Field.WEEK_OF_MONTH;
+                field = Calendar.WEEK_OF_MONTH;
+                break;
+            case AM_PM_FIELD:
+                dateFormatField = Field.AM_PM;
+                buffer.append(formatData.ampms[calendar.get(Calendar.AM_PM)]);
+                break;
+            case HOUR1_FIELD: // h
+                dateFormatField = Field.HOUR1;
+                hour = calendar.get(Calendar.HOUR);
+                appendNumber(buffer, count, hour == 0 ? 12 : hour);
+                break;
+            case HOUR0_FIELD: // K
+                dateFormatField = Field.HOUR0;
+                field = Calendar.HOUR;
+                break;
+            case TIMEZONE_FIELD: // z
+                dateFormatField = Field.TIME_ZONE;
+                appendTimeZone(buffer, count, true);
+                break;
+            case (TIMEZONE_FIELD + 1): // Z
+                dateFormatField = Field.TIME_ZONE;
+                appendTimeZone(buffer, count, false);
+                break;
+        }
+        if (field != -1) {
+            appendNumber(buffer, count, calendar.get(field));
+        }
+
+        if (fields != null) {
+            position = new FieldPosition(dateFormatField);
+            position.setBeginIndex(beginPosition);
+            position.setEndIndex(buffer.length());
+            fields.add(position);
+        } else {
+            // Set to the first occurrence
+            if ((position.getFieldAttribute() == dateFormatField || (position
+                    .getFieldAttribute() == null && position.getField() == index))
+                    && position.getEndIndex() == 0) {
+                position.setBeginIndex(beginPosition);
+                position.setEndIndex(buffer.length());
+            }
+        }
+    }
+
+    private void appendTimeZone(StringBuffer buffer, int count,
+            boolean generalTimezone) {
+        // cannot call TimeZone.getDisplayName() because it would not use
+        // the DateFormatSymbols of this SimpleDateFormat
+
+        if (generalTimezone) {
+            String id = calendar.getTimeZone().getID();
+            String[][] zones = formatData.zoneStrings;
+            String[] zone = null;
+            for (String[] element : zones) {
+                if (id.equals(element[0])) {
+                    zone = element;
+                    break;
+                }
+            }
+            if (zone == null) {
+                int offset = calendar.get(Calendar.ZONE_OFFSET)
+                        + calendar.get(Calendar.DST_OFFSET);
+                char sign = '+';
+                if (offset < 0) {
+                    sign = '-';
+                    offset = -offset;
+                }
+                buffer.append("GMT"); //$NON-NLS-1$
+                buffer.append(sign);
+                appendNumber(buffer, 2, offset / 3600000);
+                buffer.append(':');
+                appendNumber(buffer, 2, (offset % 3600000) / 60000);
+            } else {
+                int daylight = calendar.get(Calendar.DST_OFFSET) == 0 ? 0 : 2;
+                if (count < 4) {
+                    buffer.append(zone[2 + daylight]);
+                } else {
+                    buffer.append(zone[1 + daylight]);
+                }
+            }
+        } else {
+            int offset = calendar.get(Calendar.ZONE_OFFSET)
+                    + calendar.get(Calendar.DST_OFFSET);
+            char sign = '+';
+            if (offset < 0) {
+                sign = '-';
+                offset = -offset;
+            }
+            buffer.append(sign);
+            appendNumber(buffer, 2, offset / 3600000);
+            appendNumber(buffer, 2, (offset % 3600000) / 60000);
+        }
+    }
+
+    private void appendNumber(StringBuffer buffer, int count, int value) {
+        int minimumIntegerDigits = numberFormat.getMinimumIntegerDigits();
+        numberFormat.setMinimumIntegerDigits(count);
+        numberFormat.format(new Integer(value), buffer, new FieldPosition(0));
+        numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
+    }
+
     /**
      * Changes the pattern of this SimpleDateFormat to the specified pattern
      * which uses localized pattern characters.
@@ -240,8 +330,8 @@
      *            the localized pattern
      */
     public void applyLocalizedPattern(String template) {
-        icuFormat.applyLocalizedPattern(template);
-        pattern = icuFormat.toPattern();
+        pattern = convertPattern(template, formatData.getLocalPatternChars(),
+                patternChars, true);
     }
 
     /**
@@ -258,7 +348,6 @@
      */
     public void applyPattern(String template) {
         validatePattern(template);
-        icuFormat.applyPattern(template);
         pattern = template;
     }
 
@@ -278,6 +367,13 @@
         return clone;
     }
 
+    private static String defaultPattern() {
+        ResourceBundle bundle = getBundle(Locale.getDefault());
+        String styleName = getStyleName(SHORT);
+        return bundle.getString("Date_" + styleName) + " " //$NON-NLS-1$ //$NON-NLS-2$
+                + bundle.getString("Time_" + styleName); //$NON-NLS-1$
+    }
+
     /**
      * Compares the specified object to this SimpleDateFormat and answer if they
      * are equal. The object must be an instance of SimpleDateFormat and have
@@ -304,6 +400,12 @@
                 && formatData.equals(simple.formatData);
     }
 
+    private Date error(ParsePosition position, int offset, TimeZone zone) {
+        position.setErrorIndex(offset);
+        calendar.setTimeZone(zone);
+        return null;
+    }
+
     /**
      * Formats the specified object using the rules of this SimpleDateFormat and
      * returns an AttributedCharacterIterator with the formatted Date and
@@ -321,7 +423,39 @@
      */
     @Override
     public AttributedCharacterIterator formatToCharacterIterator(Object object) {
-        return icuFormat.formatToCharacterIterator(object);
+        if (object == null) {
+            throw new NullPointerException();
+        }
+        if (object instanceof Date) {
+            return formatToCharacterIteratorImpl((Date) object);
+        }
+        if (object instanceof Number) {
+            return formatToCharacterIteratorImpl(new Date(((Number) object)
+                    .longValue()));
+        }
+        throw new IllegalArgumentException();
+    }
+
+    private AttributedCharacterIterator formatToCharacterIteratorImpl(Date date) {
+        StringBuffer buffer = new StringBuffer();
+        Vector<FieldPosition> fields = new Vector<FieldPosition>();
+
+        // format the date, and find fields
+        formatImpl(date, buffer, null, fields);
+
+        // create and AttributedString with the formatted buffer
+        AttributedString as = new AttributedString(buffer.toString());
+
+        // add DateFormat field attributes to the AttributedString
+        for (int i = 0; i < fields.size(); i++) {
+            FieldPosition pos = fields.elementAt(i);
+            Format.Field attribute = pos.getFieldAttribute();
+            as.addAttribute(attribute, attribute, pos.getBeginIndex(), pos
+                    .getEndIndex());
+        }
+
+        // return the CharacterIterator from AttributedString
+        return as.getIterator();
     }
 
     /**
@@ -344,11 +478,167 @@
     @Override
     public StringBuffer format(Date date, StringBuffer buffer,
             FieldPosition field) {
-        icuFormat.setTimeZone(com.ibm.icu.util.TimeZone.getTimeZone(calendar
-                .getTimeZone().getID()));
-        return icuFormat.format(date, buffer, field);
+        return formatImpl(date, buffer, field, null);
     }
 
+    /**
+     * Validate the format character.
+     * 
+     * @param format
+     *            the format character
+     * 
+     * @throws IllegalArgumentException
+     *             when the format character is invalid
+     */
+    private void validateFormat(char format) {
+        int index = patternChars.indexOf(format);
+        if (index == -1) {
+            // text.03=Unknown pattern character - '{0}'
+            throw new IllegalArgumentException(Messages.getString(
+                    "text.03", format)); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Validate the pattern.
+     * 
+     * @param template
+     *            the pattern to validate.
+     * 
+     * @throws NullPointerException
+     *             if the pattern is null
+     * @throws IllegalArgumentException
+     *             if the pattern is invalid
+     */
+    private void validatePattern(String template) {
+        boolean quote = false;
+        int next, last = -1, count = 0;
+
+        final int patternLength = template.length();
+        for (int i = 0; i < patternLength; i++) {
+            next = (template.charAt(i));
+            if (next == '\'') {
+                if (count > 0) {
+                    validateFormat((char) last);
+                    count = 0;
+                }
+                if (last == next) {
+                    last = -1;
+                } else {
+                    last = next;
+                }
+                quote = !quote;
+                continue;
+            }
+            if (!quote
+                    && (last == next || (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
+                if (last == next) {
+                    count++;
+                } else {
+                    if (count > 0) {
+                        validateFormat((char) last);
+                    }
+                    last = next;
+                    count = 1;
+                }
+            } else {
+                if (count > 0) {
+                    validateFormat((char) last);
+                    count = 0;
+                }
+                last = -1;
+            }
+        }
+        if (count > 0) {
+            validateFormat((char) last);
+        }
+
+        if (quote) {
+            // text.04=Unterminated quote {0}
+            throw new IllegalArgumentException(Messages.getString("text.04")); //$NON-NLS-1$
+        }
+
+    }
+
+    /**
+     * Formats the date.
+     * <p>
+     * If the FieldPosition <code>field</code> is not null, and the field
+     * specified by this FieldPosition is formatted, set the begin and end index
+     * of the formatted field in the FieldPosition.
+     * <p>
+     * If the Vector <code>fields</code> is not null, find fields of this
+     * date, set FieldPositions with these fields, and add them to the fields
+     * vector.
+     * 
+     * @param date
+     *            Date to Format
+     * @param buffer
+     *            StringBuffer to store the resulting formatted String
+     * @param field
+     *            FieldPosition to set begin and end index of the field
+     *            specified, if it is part of the format for this date
+     * @param fields
+     *            Vector used to store the FieldPositions for each field in this
+     *            date
+     * 
+     * @return the formatted Date
+     * 
+     * @exception IllegalArgumentException
+     *                when the object cannot be formatted by this Format
+     */
+    private StringBuffer formatImpl(Date date, StringBuffer buffer,
+            FieldPosition field, Vector<FieldPosition> fields) {
+
+        boolean quote = false;
+        int next, last = -1, count = 0;
+        calendar.setTime(date);
+        if (field != null) {
+            field.clear();
+        }
+
+        final int patternLength = pattern.length();
+        for (int i = 0; i < patternLength; i++) {
+            next = (pattern.charAt(i));
+            if (next == '\'') {
+                if (count > 0) {
+                    append(buffer, field, fields, (char) last, count);
+                    count = 0;
+                }
+                if (last == next) {
+                    buffer.append('\'');
+                    last = -1;
+                } else {
+                    last = next;
+                }
+                quote = !quote;
+                continue;
+            }
+            if (!quote
+                    && (last == next || (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
+                if (last == next) {
+                    count++;
+                } else {
+                    if (count > 0) {
+                        append(buffer, field, fields, (char) last, count);
+                    }
+                    last = next;
+                    count = 1;
+                }
+            } else {
+                if (count > 0) {
+                    append(buffer, field, fields, (char) last, count);
+                    count = 0;
+                }
+                last = -1;
+                buffer.append((char) next);
+            }
+        }
+        if (count > 0) {
+            append(buffer, field, fields, (char) last, count);
+        }
+        return buffer;
+    }
 
     /**
      * Answers the Date which is the start of the one hundred year period for
@@ -384,6 +674,131 @@
                 + creationYear;
     }
 
+    private int parse(String string, int offset, char format, int count) {
+        int index = patternChars.indexOf(format);
+        if (index == -1) {
+            // text.03=Unknown pattern character - '{0}'
+            throw new IllegalArgumentException(Messages.getString(
+                    "text.03", format)); //$NON-NLS-1$
+        }
+        int field = -1;
+        int absolute = 0;
+        if (count < 0) {
+            count = -count;
+            absolute = count;
+        }
+        switch (index) {
+            case ERA_FIELD:
+                return parseText(string, offset, formatData.eras, Calendar.ERA);
+            case YEAR_FIELD:
+                if (count >= 3) {
+                    field = Calendar.YEAR;
+                } else {
+                    ParsePosition position = new ParsePosition(offset);
+                    Number result = parseNumber(absolute, string, position);
+                    if (result == null) {
+                        return -position.getErrorIndex() - 1;
+                    }
+                    int year = result.intValue();
+                    // A two digit year must be exactly two digits, i.e. 01
+                    if ((position.getIndex() - offset) == 2 && year >= 0) {
+                        year += creationYear / 100 * 100;
+                        if (year < creationYear) {
+                            year += 100;
+                        }
+                    }
+                    calendar.set(Calendar.YEAR, year);
+                    return position.getIndex();
+                }
+                break;
+            case MONTH_FIELD:
+                if (count <= 2) {
+                    return parseNumber(absolute, string, offset,
+                            Calendar.MONTH, -1);
+                }
+                index = parseText(string, offset, formatData.months,
+                        Calendar.MONTH);
+                if (index < 0) {
+                    return parseText(string, offset, formatData.shortMonths,
+                            Calendar.MONTH);
+                }
+                return index;
+            case DATE_FIELD:
+                field = Calendar.DATE;
+                break;
+            case HOUR_OF_DAY1_FIELD:
+                ParsePosition position = new ParsePosition(offset);
+                Number result = parseNumber(absolute, string, position);
+                if (result == null) {
+                    return -position.getErrorIndex() - 1;
+                }
+                int hour = result.intValue();
+                if (hour == 24) {
+                    hour = 0;
+                }
+                calendar.set(Calendar.HOUR_OF_DAY, hour);
+                return position.getIndex();
+            case HOUR_OF_DAY0_FIELD:
+                field = Calendar.HOUR_OF_DAY;
+                break;
+            case MINUTE_FIELD:
+                field = Calendar.MINUTE;
+                break;
+            case SECOND_FIELD:
+                field = Calendar.SECOND;
+                break;
+            case MILLISECOND_FIELD:
+                field = Calendar.MILLISECOND;
+                break;
+            case DAY_OF_WEEK_FIELD:
+                index = parseText(string, offset, formatData.weekdays,
+                        Calendar.DAY_OF_WEEK);
+                if (index < 0) {
+                    return parseText(string, offset, formatData.shortWeekdays,
+                            Calendar.DAY_OF_WEEK);
+                }
+                return index;
+            case DAY_OF_YEAR_FIELD:
+                field = Calendar.DAY_OF_YEAR;
+                break;
+            case DAY_OF_WEEK_IN_MONTH_FIELD:
+                field = Calendar.DAY_OF_WEEK_IN_MONTH;
+                break;
+            case WEEK_OF_YEAR_FIELD:
+                field = Calendar.WEEK_OF_YEAR;
+                break;
+            case WEEK_OF_MONTH_FIELD:
+                field = Calendar.WEEK_OF_MONTH;
+                break;
+            case AM_PM_FIELD:
+                return parseText(string, offset, formatData.ampms,
+                        Calendar.AM_PM);
+            case HOUR1_FIELD:
+                position = new ParsePosition(offset);
+                result = parseNumber(absolute, string, position);
+                if (result == null) {
+                    return -position.getErrorIndex() - 1;
+                }
+                hour = result.intValue();
+                if (hour == 12) {
+                    hour = 0;
+                }
+                calendar.set(Calendar.HOUR, hour);
+                return position.getIndex();
+            case HOUR0_FIELD:
+                field = Calendar.HOUR;
+                break;
+            case TIMEZONE_FIELD:
+                return parseTimeZone(string, offset);
+            case (TIMEZONE_FIELD + 1):
+                return parseTimeZone(string, offset);
+        }
+        if (field != -1) {
+            return parseNumber(absolute, string, offset, field, 0);
+        }
+        return offset;
+    }
+
     /**
      * Parse a Date from the specified String starting at the index specified by
      * the ParsePosition. If the string is successfully parsed, the index of the
@@ -403,7 +818,192 @@
      */
     @Override
     public Date parse(String string, ParsePosition position) {
-        return icuFormat.parse(string,position);
+        boolean quote = false;
+        int next, last = -1, count = 0, offset = position.getIndex();
+        int length = string.length();
+        calendar.clear();
+        TimeZone zone = calendar.getTimeZone();
+        final int patternLength = pattern.length();
+        for (int i = 0; i < patternLength; i++) {
+            next = pattern.charAt(i);
+            if (next == '\'') {
+                if (count > 0) {
+                    if ((offset = parse(string, offset, (char) last, count)) < 0) {
+                        return error(position, -offset - 1, zone);
+                    }
+                    count = 0;
+                }
+                if (last == next) {
+                    if (offset >= length || string.charAt(offset) != '\'') {
+                        return error(position, offset, zone);
+                    }
+                    offset++;
+                    last = -1;
+                } else {
+                    last = next;
+                }
+                quote = !quote;
+                continue;
+            }
+            if (!quote
+                    && (last == next || (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
+                if (last == next) {
+                    count++;
+                } else {
+                    if (count > 0) {
+                        if ((offset = parse(string, offset, (char) last, -count)) < 0) {
+                            return error(position, -offset - 1, zone);
+                        }
+                    }
+                    last = next;
+                    count = 1;
+                }
+            } else {
+                if (count > 0) {
+                    if ((offset = parse(string, offset, (char) last, count)) < 0) {
+                        return error(position, -offset - 1, zone);
+                    }
+                    count = 0;
+                }
+                last = -1;
+                if (offset >= length || string.charAt(offset) != next) {
+                    return error(position, offset, zone);
+                }
+                offset++;
+            }
+        }
+        if (count > 0) {
+            if ((offset = parse(string, offset, (char) last, count)) < 0) {
+                return error(position, -offset - 1, zone);
+            }
+        }
+        Date date;
+        try {
+            date = calendar.getTime();
+        } catch (IllegalArgumentException e) {
+            return error(position, offset, zone);
+        }
+        position.setIndex(offset);
+        calendar.setTimeZone(zone);
+        return date;
+    }
+
+    private Number parseNumber(int max, String string, ParsePosition position) {
+        int digit, length = string.length(), result = 0;
+        int index = position.getIndex();
+        if (max > 0 && max < length - index) {
+            length = index + max;
+        }
+        while (index < length
+                && (string.charAt(index) == ' ' || string.charAt(index) == '\t')) {
+            index++;
+        }
+        if (max == 0) {
+            position.setIndex(index);
+            return numberFormat.parse(string, position);
+        }
+
+        while (index < length
+                && (digit = Character.digit(string.charAt(index), 10)) != -1) {
+            index++;
+            result = result * 10 + digit;
+        }
+        if (index == position.getIndex()) {
+            position.setErrorIndex(index);
+            return null;
+        }
+        position.setIndex(index);
+        return new Integer(result);
+    }
+
+    private int parseNumber(int max, String string, int offset, int field,
+            int skew) {
+        ParsePosition position = new ParsePosition(offset);
+        Number result = parseNumber(max, string, position);
+        if (result == null) {
+            return -position.getErrorIndex() - 1;
+        }
+        calendar.set(field, result.intValue() + skew);
+        return position.getIndex();
+    }
+
+    private int parseText(String string, int offset, String[] text, int field) {
+        int found = -1;
+        for (int i = 0; i < text.length; i++) {
+            if (text[i].length() == 0) {
+                continue;
+            }
+            if (string
+                    .regionMatches(true, offset, text[i], 0, text[i].length())) {
+                // Search for the longest match, in case some fields are subsets
+                if (found == -1 || text[i].length() > text[found].length()) {
+                    found = i;
+                }
+            }
+        }
+        if (found != -1) {
+            calendar.set(field, found);
+            return offset + text[found].length();
+        }
+        return -offset - 1;
+    }
+
+    private int parseTimeZone(String string, int offset) {
+        String[][] zones = formatData.zoneStrings;
+        boolean foundGMT = string.regionMatches(offset, "GMT", 0, 3); //$NON-NLS-1$
+        if (foundGMT) {
+            offset += 3;
+        }
+        char sign;
+        if (offset < string.length()
+                && ((sign = string.charAt(offset)) == '+' || sign == '-')) {
+            ParsePosition position = new ParsePosition(offset + 1);
+            Number result = numberFormat.parse(string, position);
+            if (result == null) {
+                return -position.getErrorIndex() - 1;
+            }
+            int hour = result.intValue();
+            int raw = hour * 3600000;
+            int index = position.getIndex();
+            if (index < string.length() && string.charAt(index) == ':') {
+                position.setIndex(index + 1);
+                result = numberFormat.parse(string, position);
+                if (result == null) {
+                    return -position.getErrorIndex() - 1;
+                }
+                int minute = result.intValue();
+                raw += minute * 60000;
+            } else if (hour >= 24) {
+                raw = (hour / 100 * 3600000) + (hour % 100 * 60000);
+            }
+            if (sign == '-') {
+                raw = -raw;
+            }
+            calendar.setTimeZone(new SimpleTimeZone(raw, "")); //$NON-NLS-1$
+            return position.getIndex();
+        }
+        if (foundGMT) {
+            calendar.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
+            return offset;
+        }
+        for (String[] element : zones) {
+            for (int j = 1; j < 5; j++) {
+                if (string.regionMatches(true, offset, element[j], 0,
+                        element[j].length())) {
+                    TimeZone zone = TimeZone.getTimeZone(element[0]);
+                    if (zone == null) {
+                        return -offset - 1;
+                    }
+                    int raw = zone.getRawOffset();
+                    if (j >= 3 && zone.useDaylightTime()) {
+                        raw += 3600000;
+                    }
+                    calendar.setTimeZone(new SimpleTimeZone(raw, "")); //$NON-NLS-1$
+                    return offset + element[j].length();
+                }
+            }
+        }
+        return -offset - 1;
     }
 
     /**
@@ -414,7 +1014,6 @@
      *            the Date
      */
     public void set2DigitYearStart(Date date) {
-        icuFormat.set2DigitYearStart(date);
         defaultCenturyStart = date;
         Calendar cal = new GregorianCalendar();
         cal.setTime(date);
@@ -428,9 +1027,6 @@
      *            the DateFormatSymbols
      */
     public void setDateFormatSymbols(DateFormatSymbols value) {
-        com.ibm.icu.text.DateFormatSymbols icuSymbols = new com.ibm.icu.text.DateFormatSymbols();
-        copySymbols(value, icuSymbols);
-        icuFormat.setDateFormatSymbols(icuSymbols);
         formatData = (DateFormatSymbols) value.clone();
     }
 
@@ -441,7 +1037,8 @@
      * @return the localized pattern
      */
     public String toLocalizedPattern() {
-        return icuFormat.toLocalizedPattern();
+        return convertPattern(pattern, patternChars, formatData
+                .getLocalPatternChars(), false);
     }
 
     /**



Mime
View raw message