mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-4874 fix serialization problems
X-SVN-Rev: 18722
This commit is contained in:
parent
96c4ce20a7
commit
75f97b11d7
7 changed files with 299 additions and 189 deletions
|
@ -146,11 +146,9 @@
|
|||
<!-- build everything but dist-related stuff -->
|
||||
<target name="all" depends="core,tests,tools,richedit,demos,jar,docs" description="build all primary targets"/>
|
||||
|
||||
<target name="resources" depends="init" description="builds all the resources">
|
||||
<target name="resources" depends="init, testdata" description="builds all the resources">
|
||||
<unjar src="${src.dir}/com/ibm/icu/impl/data/icudata.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/${icu4j.data.path}/res_index.res"/>
|
||||
<unjar src="${src.dir}/com/ibm/icu/dev/data/testdata.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/${icu4j.testdata.path}/root.res"/>
|
||||
</target>
|
||||
|
||||
<target name="icudata" depends="init" if="icu4j.resources">
|
||||
|
@ -159,12 +157,6 @@
|
|||
<touch file="${build.dir}/${icu4j.data.path}/res_index.res"/>
|
||||
</target>
|
||||
|
||||
<target name="testdata" depends="init" if="icu4j.testdata.resources">
|
||||
<!-- use this target to force resources to be rebuilt -->
|
||||
<unjar src="${src.dir}/com/ibm/icu/dev/data/testdata.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/${icu4j.testdata.path}/root.res"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
use this target to conditionally build resources only if icu4j.resources is set
|
||||
<target name="icu" depends="init" if="icu4j.resources">
|
||||
|
@ -186,7 +178,7 @@
|
|||
encoding="ascii"/>
|
||||
</target>
|
||||
|
||||
<target name="tests" depends="core,testData" description="build tests">
|
||||
<target name="tests" depends="core,testdata" description="build tests">
|
||||
<javac includes="com/ibm/icu/dev/test/calendar/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
|
@ -227,6 +219,14 @@
|
|||
source="${icu4j.javac.source}"
|
||||
target="${icu4j.javac.target}"
|
||||
debug="on" deprecation="off"/>
|
||||
<javac includes="com/ibm/icu/dev/test/serializable/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
classpathref="build.classpath"
|
||||
source="${icu4j.javac.source}"
|
||||
target="${icu4j.javac.target}"
|
||||
debug="on" deprecation="off"/>
|
||||
<javac includes="com/ibm/icu/dev/test/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
|
@ -237,7 +237,7 @@
|
|||
debug="on" deprecation="off"/>
|
||||
</target>
|
||||
|
||||
<target name="demos" depends="core,testData" description="build demos">
|
||||
<target name="demos" depends="core,testdata" description="build demos">
|
||||
<javac includes="com/ibm/icu/dev/demo/**/*.java"
|
||||
excludes="**/CVS/**/*"
|
||||
srcdir="${src.dir}"
|
||||
|
@ -353,7 +353,7 @@
|
|||
</copy>
|
||||
</target>
|
||||
|
||||
<target name ="testData" depends="init">
|
||||
<target name ="testdata" depends="init">
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/data/rbbi/english.dict"
|
||||
todir="${build.dir}/com/ibm/icu/dev/data/rbbi"/>
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/test/rbbi/rbbitst.txt"
|
||||
|
@ -387,11 +387,13 @@
|
|||
</copy>
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/test/format/NumberFormatTestCases.txt"
|
||||
todir="${build.dir}/com/ibm/icu/dev/test/format"/>
|
||||
<unjar src="${src.dir}/com/ibm/icu/dev/data/testdata.jar" dest="${build.dir}"/>
|
||||
<copy todir="${build.dir}/com/ibm/icu/dev/data/resources/">
|
||||
<copy todir="${build.dir}/com/ibm/icu/dev/data/resources/">
|
||||
<fileset dir="${src.dir}/com/ibm/icu/dev/data/resources/"
|
||||
includes="*.properties"/>
|
||||
</copy>
|
||||
<!-- use this target to force resources to be rebuilt -->
|
||||
<unjar src="${src.dir}/com/ibm/icu/dev/data/testdata.jar" dest="${build.dir}"/>
|
||||
<touch file="${build.dir}/${icu4j.testdata.path}/root.res"/>
|
||||
</target>
|
||||
|
||||
<!-- builds richedit and richedit tests -->
|
||||
|
@ -420,7 +422,7 @@
|
|||
manifest="${icu4j.manifest}"/>
|
||||
</target>
|
||||
|
||||
<target name="testJar" depends="tests,jar" description="build runtime 'icu4jtests.jar' jar file">
|
||||
<target name="jarTests" depends="tests,jar" description="build runtime 'icu4jtests.jar' jar file">
|
||||
<jar jarfile="${testjar.file}" compress="true" manifest="${icu4j.tests.manifest}">
|
||||
<fileset dir="${build.dir}" includes="com/ibm/icu/dev/test/**/*"/>
|
||||
<fileset dir="${build.dir}" includes="com/ibm/icu/dev/data/**/*"/>
|
||||
|
@ -572,7 +574,9 @@
|
|||
</java>
|
||||
</target>
|
||||
|
||||
<target name="secureCheck" depends="testJar" description="run secure (applet-like) icu4j test suite">
|
||||
<target name="secure" depends="jarTests" description="builds icu4j.jar and icu4jtests.jar"/>
|
||||
|
||||
<target name="secureCheck" depends="secure" description="run secure (applet-like) icu4j test suite">
|
||||
<java classname="com.ibm.icu.dev.test.TestAll" fork="yes" failonerror="true">
|
||||
<!-- jvmarg value="-verbose"/ -->
|
||||
<!-- (use for debugging, LOTS of output) <jvmarg value="-Djava.security.debug=access:trace"/ -->
|
||||
|
@ -589,7 +593,8 @@
|
|||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
<target name="deleteData" depends="init" >
|
||||
|
||||
<target name="noData" depends="core, tests" description="builds ICU4J without any data">
|
||||
<delete failonerror="no">
|
||||
<fileset dir="${build.dir}/${icu4j.data.path}/../" includes="Holiday*.class"/>
|
||||
<fileset dir="${build.dir}/${icu4j.data.path}/../" includes="BreakIterator*.class"/>
|
||||
|
@ -597,8 +602,8 @@
|
|||
<fileset dir="${build.dir}/${icu4j.testdata.path}"/>
|
||||
<fileset dir="${build.dir}/${icu4j.testdata.path}../"/>
|
||||
</delete>
|
||||
</target>
|
||||
<target name="noDataCheck" depends="core, tests, deleteData" description="runs the tests when no data is present">
|
||||
</target>
|
||||
<target name="noDataCheck" depends="noData" description="runs the tests when no data is present">
|
||||
<java classname="com.ibm.icu.dev.test.TestAll" fork="yes" failonerror="true">
|
||||
<arg value="-nothrow"/>
|
||||
<arg value="-nodata"/>
|
||||
|
|
|
@ -17,11 +17,9 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A wrapper around a java.util.TimeZone object. This is a concrete
|
||||
* instance of TimeZone. All TimeZones that wrap a java.util.TimeZone
|
||||
* should inherit from this class. TimeZones that do not wrap a
|
||||
* java.util.TimeZone inherit directly from TimeZone.
|
||||
*
|
||||
* Wrapper around OlsonTimeZone object. Due to serialziation constraints
|
||||
* SimpleTimeZone cannot be a subclass of OlsonTimeZone.
|
||||
*
|
||||
* The complement of this is TimeZoneAdapter, which makes a
|
||||
* com.ibm.icu.util.TimeZone look like a java.util.TimeZone.
|
||||
*
|
||||
|
@ -32,13 +30,12 @@ import java.io.IOException;
|
|||
public class JDKTimeZone extends TimeZone {
|
||||
|
||||
private static final long serialVersionUID = -3724907649889455280L;
|
||||
|
||||
|
||||
/**
|
||||
* The java.util.TimeZone wrapped by this object. Must not be null.
|
||||
*/
|
||||
// give access to SimpleTimeZone
|
||||
protected transient java.util.TimeZone zone;
|
||||
|
||||
protected transient OlsonTimeZone zone;
|
||||
/**
|
||||
* Given a java.util.TimeZone, wrap it in the appropriate adapter
|
||||
* subclass of com.ibm.icu.util.TimeZone and return the adapter.
|
||||
|
@ -53,12 +50,6 @@ public class JDKTimeZone extends TimeZone {
|
|||
return new JDKTimeZone(tz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the java.util.TimeZone wrapped by this object.
|
||||
*/
|
||||
public java.util.TimeZone unwrap() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a JDKTimeZone given a java.util.TimeZone reference
|
||||
|
@ -69,10 +60,23 @@ public class JDKTimeZone extends TimeZone {
|
|||
* @deprecated This is an internal API and should not be used by client code.
|
||||
*/
|
||||
public JDKTimeZone(java.util.TimeZone tz) {
|
||||
String id = tz.getID();
|
||||
try{
|
||||
zone = new OlsonTimeZone(id);
|
||||
}catch(Exception ex){
|
||||
// throw away exception
|
||||
}
|
||||
super.setID(id);
|
||||
}
|
||||
protected JDKTimeZone(OlsonTimeZone tz) {
|
||||
zone = tz;
|
||||
super.setID(zone.getID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
protected JDKTimeZone() {
|
||||
}
|
||||
/**
|
||||
* Sets the time zone ID. This does not change any other data in
|
||||
* the time zone object.
|
||||
|
@ -80,7 +84,9 @@ public class JDKTimeZone extends TimeZone {
|
|||
*/
|
||||
public void setID(String ID) {
|
||||
super.setID(ID);
|
||||
zone.setID(ID);
|
||||
if(zone!=null){
|
||||
zone.setID(ID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,68 +95,61 @@ public class JDKTimeZone extends TimeZone {
|
|||
public int getOffset(int era, int year, int month, int day,
|
||||
int dayOfWeek, int milliseconds) {
|
||||
|
||||
return unwrap().getOffset(era, year, month, day,
|
||||
dayOfWeek, milliseconds);
|
||||
if(zone!=null){
|
||||
return zone.getOffset(era, year, month, day,
|
||||
dayOfWeek, milliseconds);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override TimeZone to handle wrapped ZoneInfo.
|
||||
*/
|
||||
|
||||
public void getOffset(long date, boolean local, int[] offsets) {
|
||||
// The following code works only on 1.4 or later. We no longer support JDK 1.3.
|
||||
// assume if we're running under a security manager, then we don't have access to
|
||||
// sun classes
|
||||
if (System.getSecurityManager() == null) {
|
||||
try {
|
||||
if (zone instanceof sun.util.calendar.ZoneInfo) {
|
||||
((sun.util.calendar.ZoneInfo) zone).getOffsets(date, offsets);
|
||||
if (local) {
|
||||
date -= offsets[0] + offsets[1];
|
||||
((sun.util.calendar.ZoneInfo) zone).getOffsets(date, offsets);
|
||||
}
|
||||
// System.err.println("offsets: " + offsets[0] + ", " + offsets[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (SecurityException ex) {
|
||||
// ok; fall through, we're running in a protected context
|
||||
}
|
||||
catch (Throwable th) {
|
||||
// System.out.println("caught: " + th);
|
||||
}
|
||||
}
|
||||
|
||||
super.getOffset(date, local, offsets);
|
||||
// System.err.println("default offsets: " + offsets[0] + ", " + offsets[1]);
|
||||
|
||||
if(zone!=null){
|
||||
zone.getOffset(date, local, offsets);
|
||||
}else{
|
||||
super.getOffset(date, local, offsets);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public void setRawOffset(int offsetMillis) {
|
||||
unwrap().setRawOffset(offsetMillis);
|
||||
if(zone!=null){
|
||||
zone.setRawOffset(offsetMillis);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public int getRawOffset() {
|
||||
return unwrap().getRawOffset();
|
||||
if(zone!=null){
|
||||
return zone.getRawOffset();
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public boolean useDaylightTime() {
|
||||
return unwrap().useDaylightTime();
|
||||
if(zone!=null){
|
||||
return zone.useDaylightTime();
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
public boolean inDaylightTime(Date date) {
|
||||
return unwrap().inDaylightTime(date);
|
||||
if(zone!=null){
|
||||
return zone.inDaylightTime(date);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +160,9 @@ public class JDKTimeZone extends TimeZone {
|
|||
return false;
|
||||
}
|
||||
if (other instanceof JDKTimeZone) {
|
||||
return zone.hasSameRules(((JDKTimeZone) other).zone);
|
||||
if(zone!=null){
|
||||
return zone.hasSameRules(((JDKTimeZone) other).zone);
|
||||
}
|
||||
}
|
||||
return super.hasSameRules(other);
|
||||
}
|
||||
|
@ -170,14 +171,21 @@ public class JDKTimeZone extends TimeZone {
|
|||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
public Object clone() {
|
||||
return wrap((java.util.TimeZone)zone.clone());
|
||||
JDKTimeZone clone = new JDKTimeZone();
|
||||
if(zone!=null){
|
||||
clone.zone = (OlsonTimeZone)zone.clone();
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
public synchronized int hashCode() {
|
||||
return unwrap().hashCode();
|
||||
if(zone!=null){
|
||||
return zone.hashCode();
|
||||
}
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,38 +197,11 @@ public class JDKTimeZone extends TimeZone {
|
|||
*/
|
||||
public int getDSTSavings() {
|
||||
if (useDaylightTime()) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// assume if we have a security manager, we'll fail
|
||||
try {
|
||||
// This is only to make a 1.3 compiler happy. JDKTimeZone
|
||||
// is only used in JDK 1.4, where TimeZone has the getDSTSavings
|
||||
// API on it, so a straight call to getDSTSavings would actually
|
||||
// work if we could compile it. Since on 1.4 the time zone is
|
||||
// not a SimpleTimeZone, we can't downcast in order to make
|
||||
// the direct call that a 1.3 compiler would like, because at
|
||||
// runtime the downcast would fail.
|
||||
// todo: remove when we no longer support compiling under 1.3
|
||||
|
||||
// The following works if getDSTSavings is declared in
|
||||
// TimeZone (JDK 1.4) or SimpleTimeZone (JDK 1.3).
|
||||
final Object[] args = new Object[0];
|
||||
final Class[] argtypes = new Class[0];
|
||||
Method m = zone.getClass().getMethod("getDSTSavings", argtypes);
|
||||
int result = ((Integer) m.invoke(zone, args)).intValue();
|
||||
// System.err.println("JDKTZ got " + (result/3600000f) + " hour daylight saving time");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
// if zone is in the sun.foo class hierarchy and we
|
||||
// are in a protection domain, we'll get a security
|
||||
// exception. And if we claim to support DST, but
|
||||
// return a value of 0, later java.util.SimpleTimeZone will
|
||||
// throw an illegalargument exception. so... fake
|
||||
// the dstoffset;
|
||||
}
|
||||
}
|
||||
// System.err.println("JDKTZ assume 1 hour daylight saving time");
|
||||
return 3600000;
|
||||
}
|
||||
if(zone!=null){
|
||||
return zone.getDSTSavings();
|
||||
}
|
||||
return 3600000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -229,8 +210,16 @@ public class JDKTimeZone extends TimeZone {
|
|||
*/
|
||||
public boolean equals(Object obj) {
|
||||
try {
|
||||
return obj != null &&
|
||||
unwrap().equals(((JDKTimeZone) obj).unwrap());
|
||||
if(obj !=null){
|
||||
TimeZone tz1 = zone;
|
||||
TimeZone tz2 = ((JDKTimeZone) obj).zone;
|
||||
boolean equal = true;
|
||||
if(tz1!=null && tz2!=null){
|
||||
equal = tz1.equals(tz2);
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
return false;
|
||||
} catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -241,16 +230,26 @@ public class JDKTimeZone extends TimeZone {
|
|||
* @return a string representation of this object.
|
||||
*/
|
||||
public String toString() {
|
||||
return "JDKTimeZone: " + unwrap().toString();
|
||||
return "JDKTimeZone: " + zone.toString();
|
||||
}
|
||||
|
||||
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
|
||||
out.writeObject(zone.getID());
|
||||
if(zone!=null){
|
||||
out.writeObject(zone.getID());
|
||||
}
|
||||
out.writeObject(getID());
|
||||
}
|
||||
|
||||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
String id = (String)in.readObject();
|
||||
zone = java.util.TimeZone.getTimeZone(id);
|
||||
|
||||
// create the TimeZone object if reading the old version of object
|
||||
try{
|
||||
zone = new OlsonTimeZone(id);
|
||||
}catch(Exception ex){
|
||||
//throw away exception
|
||||
}
|
||||
setID(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@ public class OlsonTimeZone extends TimeZone {
|
|||
public Object clone() {
|
||||
OlsonTimeZone other = (OlsonTimeZone) super.clone();
|
||||
if(finalZone!=null){
|
||||
finalZone.setID(getID());
|
||||
other.finalZone = (SimpleTimeZone)finalZone.clone();
|
||||
}
|
||||
other.transitionTimes = (int[])transitionTimes.clone();
|
||||
|
@ -431,9 +432,18 @@ public class OlsonTimeZone extends TimeZone {
|
|||
}
|
||||
}
|
||||
public OlsonTimeZone(String id){
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.createBundle(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle res = ZoneMeta.openOlsonResource(id);
|
||||
construct(top, res);
|
||||
if(finalZone!=null){
|
||||
finalZone.setID(id);
|
||||
}
|
||||
super.setID(id);
|
||||
}
|
||||
public void setID(String id){
|
||||
if(finalZone!= null){
|
||||
finalZone.setID(id);
|
||||
}
|
||||
super.setID(id);
|
||||
}
|
||||
private static final int UNSIGNED_BYTE_MASK =0xFF;
|
||||
|
|
|
@ -46,9 +46,6 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
|||
* subclass of com.ibm.icu.util.TimeZone and return the adapter.
|
||||
*/
|
||||
public static java.util.TimeZone wrap(com.ibm.icu.util.TimeZone tz) {
|
||||
if (tz instanceof JDKTimeZone) {
|
||||
return ((JDKTimeZone) tz).unwrap();
|
||||
}
|
||||
return new TimeZoneAdapter(tz);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.MissingResourceException;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
|
@ -60,7 +61,7 @@ public final class ZoneMeta {
|
|||
return EMPTY;
|
||||
}
|
||||
try{
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.createBundle(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle regions = top.get(kREGIONS);
|
||||
ICUResourceBundle names = top.get(kNAMES); // dereference Zones section
|
||||
ICUResourceBundle temp = regions.get(country);
|
||||
|
@ -77,6 +78,50 @@ public final class ZoneMeta {
|
|||
}
|
||||
return EMPTY;
|
||||
}
|
||||
public static synchronized String[] getAvailableIDs() {
|
||||
if(!getOlsonMeta()){
|
||||
return EMPTY;
|
||||
}
|
||||
try{
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle names = top.get(kNAMES); // dereference Zones section
|
||||
return names.getStringArray();
|
||||
}catch(MissingResourceException ex){
|
||||
//throw away the exception
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
public static synchronized String[] getAvailableIDs(int offset){
|
||||
Vector vector = new Vector();
|
||||
for (int i=0; i<OLSON_ZONE_COUNT; ++i) {
|
||||
String unistr;
|
||||
if ((unistr=getID(i))!=null) {
|
||||
// This is VERY inefficient.
|
||||
TimeZone z = TimeZone.getTimeZone(unistr);
|
||||
// Make sure we get back the ID we wanted (if the ID is
|
||||
// invalid we get back GMT).
|
||||
if (z != null && z.getID().equals(unistr) &&
|
||||
z.getRawOffset() == offset) {
|
||||
vector.add(unistr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!vector.isEmpty()){
|
||||
String[] strings = new String[vector.size()];
|
||||
return (String[])vector.toArray(strings);
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
private static String getID(int i) {
|
||||
try{
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle names = top.get(kNAMES); // dereference Zones section
|
||||
return names.getString(i);
|
||||
}catch(MissingResourceException ex){
|
||||
//throw away the exception
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Returns the number of IDs in the equivalency group that
|
||||
* includes the given ID. An equivalency group contains zones
|
||||
|
@ -134,7 +179,7 @@ public final class ZoneMeta {
|
|||
}
|
||||
}
|
||||
if (zone >= 0) {
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.createBundle(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle ares = top.get(kNAMES); // dereference Zones section
|
||||
result = ares.getString(zone);
|
||||
|
||||
|
@ -345,7 +390,7 @@ public final class ZoneMeta {
|
|||
if(!getOlsonMeta()){
|
||||
return null;
|
||||
}
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.createBundle(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle res = getZoneByName(top, id);
|
||||
// Dereference if this is an alias. Docs say result should be 1
|
||||
// but it is 0 in 2.8 (?).
|
||||
|
@ -447,7 +492,7 @@ public final class ZoneMeta {
|
|||
* Load up the Olson meta-data. Return true if successful.
|
||||
*/
|
||||
private static boolean getOlsonMeta() {
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.createBundle(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
if(OLSON_ZONE_START < 0) {
|
||||
getOlsonMeta(top);
|
||||
}
|
||||
|
@ -460,7 +505,7 @@ public final class ZoneMeta {
|
|||
*/
|
||||
public static TimeZone getSystemTimeZone(String id) {
|
||||
try{
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.createBundle(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
ICUResourceBundle res = openOlsonResource(id);
|
||||
TimeZone z = new OlsonTimeZone(top, res);
|
||||
z.setID(id);
|
||||
|
|
|
@ -45,12 +45,13 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
* @stable ICU 2.0
|
||||
*/
|
||||
public SimpleTimeZone(int rawOffset, String ID) {
|
||||
this(new java.util.SimpleTimeZone(rawOffset, ID), ID);
|
||||
//this(new java.util.SimpleTimeZone(rawOffset, ID), ID);
|
||||
construct(rawOffset, 0, 0, 0,
|
||||
0, WALL_TIME,
|
||||
0, 0, 0,
|
||||
0, WALL_TIME,
|
||||
MILLIS_PER_HOUR);
|
||||
super.setID(ID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,18 +115,19 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
public SimpleTimeZone(int rawOffset, String ID,
|
||||
int startMonth, int startDay, int startDayOfWeek, int startTime,
|
||||
int endMonth, int endDay, int endDayOfWeek, int endTime) {
|
||||
this(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
/* this(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
startDayOfWeek, startTime, endMonth,
|
||||
endDay, endDayOfWeek, endTime), ID);
|
||||
STZInfo xinfo = getSTZInfo();
|
||||
xinfo.setStart(startMonth, startDay, startDayOfWeek, startTime, -1, false);
|
||||
xinfo.setEnd(endMonth, endDay, endDayOfWeek, endTime, -1, false);
|
||||
endDay, endDayOfWeek, endTime), ID);*/
|
||||
// STZInfo xinfo = getSTZInfo();
|
||||
// xinfo.setStart(startMonth, startDay, startDayOfWeek, startTime, -1, false);
|
||||
// xinfo.setEnd(endMonth, endDay, endDayOfWeek, endTime, -1, false);
|
||||
construct(rawOffset,
|
||||
startMonth, startDay, startDayOfWeek,
|
||||
startTime, WALL_TIME,
|
||||
endMonth, endDay, endDayOfWeek,
|
||||
endTime, WALL_TIME,
|
||||
MILLIS_PER_HOUR);
|
||||
super.setID(ID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,22 +142,24 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
int startMonth, int startDay, int startDayOfWeek, int startTime,
|
||||
int endMonth, int endDay, int endDayOfWeek, int endTime,
|
||||
int dstSavings) {
|
||||
this(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
/*this(new java.util.SimpleTimeZone(rawOffset, ID, startMonth, startDay,
|
||||
startDayOfWeek, startTime, endMonth,
|
||||
endDay, endDayOfWeek, endTime, dstSavings), ID);
|
||||
|
||||
endDay, endDayOfWeek, endTime, dstSavings), ID);*/
|
||||
this.raw = rawOffset;
|
||||
this.dst = dstSavings;
|
||||
|
||||
/*
|
||||
STZInfo xinfo = getSTZInfo();
|
||||
xinfo.setStart(startMonth, startDay, startDayOfWeek, startTime, -1, false);
|
||||
xinfo.setEnd(endMonth, endDay, endDayOfWeek, endTime, -1, false);
|
||||
*/
|
||||
|
||||
construct(rawOffset,
|
||||
startMonth, startDay, startDayOfWeek,
|
||||
startTime, WALL_TIME,
|
||||
endMonth, endDay, endDayOfWeek,
|
||||
endTime, WALL_TIME,
|
||||
dstSavings);
|
||||
dstSavings);
|
||||
super.setID(ID);
|
||||
}
|
||||
|
||||
|
||||
|
@ -445,11 +449,14 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
* java.util.SimpleTimeZone. Do not call; use the TimeZone
|
||||
* API.
|
||||
* @internal
|
||||
* @deprecated
|
||||
* @obsolete
|
||||
*/
|
||||
public SimpleTimeZone(java.util.SimpleTimeZone tz, String ID) {
|
||||
super(tz);
|
||||
super.setID(ID);
|
||||
raw = tz.getRawOffset();
|
||||
dst = tz.getDSTSavings();
|
||||
raw = tz.getRawOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -462,11 +469,12 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
// on JDK 1.4 and later, can't deserialize a SimpleTimeZone as a SimpleTimeZone...
|
||||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
|
||||
if (!(zone instanceof java.util.SimpleTimeZone && zone.getID().equals(getID()))) {
|
||||
String id = getID();
|
||||
/*
|
||||
if (id!=null && !(zone instanceof java.util.SimpleTimeZone && zone.getID().equals(id))) {
|
||||
// System.out.println("*** readjust " + zone.getClass().getName() + " " + zone.getID() + " ***");
|
||||
java.util.SimpleTimeZone stz =
|
||||
new java.util.SimpleTimeZone(raw, getID());
|
||||
new java.util.SimpleTimeZone(raw, id);
|
||||
if (dst != 0) {
|
||||
stz.setDSTSavings(dst);
|
||||
// if it is 0, then there shouldn't be start/end rules and the default
|
||||
|
@ -476,8 +484,9 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
if (xinfo != null) {
|
||||
xinfo.applyTo(stz);
|
||||
}
|
||||
zone = stz;
|
||||
zoneJDK = stz;
|
||||
}
|
||||
*/
|
||||
/* set all instance variables in this object
|
||||
* to the values in zone
|
||||
*/
|
||||
|
@ -486,7 +495,13 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @return a string representation of this object.
|
||||
*/
|
||||
public String toString() {
|
||||
return "SimpleTimeZone: " + getID();
|
||||
}
|
||||
private STZInfo getSTZInfo() {
|
||||
if (xinfo == null) {
|
||||
xinfo = new STZInfo();
|
||||
|
@ -497,7 +512,11 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
// since we don't handle leap years. Could handle assuming always
|
||||
// Gregorian, since we know they didn't have daylight time when
|
||||
// Gregorian calendar started.
|
||||
private static final int[] STATICMONTHLENGTH = new int[]{31,29,31,30,31,30,31,31,30,31,30,31};
|
||||
// private static final int[] STATICMONTHLENGTH = new int[]{31,29,31,30,31,30,31,31,30,31,30,31};
|
||||
private final byte monthLength[] = staticMonthLength;
|
||||
private final static byte staticMonthLength[] = {31,29,31,30,31,30,31,31,30,31,30,31};
|
||||
private final static byte staticLeapMonthLength[] = {31,29,31,30,31,30,31,31,30,31,30,31};
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
public int getOffset(int era, int year, int month, int day,
|
||||
|
@ -514,7 +533,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
return getOffset(era, year, month, day, dayOfWeek, millis, STATICMONTHLENGTH[month]);
|
||||
return getOffset(era, year, month, day, dayOfWeek, millis, staticMonthLength[month]);
|
||||
}
|
||||
|
||||
public int getOffset(int era, int year, int month, int day,
|
||||
|
@ -532,7 +551,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
}
|
||||
|
||||
// TODO FIX We don't handle leap years yet!
|
||||
int prevMonthLength = (month >= 1) ? STATICMONTHLENGTH[month - 1] : 31;
|
||||
int prevMonthLength = (month >= 1) ? staticMonthLength[month - 1] : 31;
|
||||
|
||||
return getOffset(era, year, month, day, dayOfWeek, millis,
|
||||
monthLength, prevMonthLength);
|
||||
|
@ -542,7 +561,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
int dayOfWeek, int millis,
|
||||
int monthLength, int prevMonthLength ){
|
||||
|
||||
if (false) {
|
||||
if (true) {
|
||||
/* Use this parameter checking code for normal operation. Only one
|
||||
* of these two blocks should actually get compiled into the class
|
||||
* file. */
|
||||
|
@ -574,7 +593,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
}
|
||||
if (day < 1
|
||||
|| day > monthLength) {
|
||||
throw new IllegalArgumentException("Illegal day " + day);
|
||||
throw new IllegalArgumentException("Illegal day " + day+" max month len: "+monthLength);
|
||||
}
|
||||
if (dayOfWeek < Calendar.SUNDAY
|
||||
|| dayOfWeek > Calendar.SATURDAY) {
|
||||
|
@ -770,23 +789,22 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
return gc.inDaylightTime();
|
||||
}
|
||||
|
||||
public SimpleTimeZone( int rawOffsetGMT, String ID,
|
||||
int savingsStartMonth, int savingsStartDay,
|
||||
int savingsStartDayOfWeek, int savingsStartTime,
|
||||
int savingsStartTimeMode,
|
||||
int savingsEndMonth, int savingsEndDay,
|
||||
int savingsEndDayOfWeek, int savingsEndTime,
|
||||
int savingsEndTimeMode,int savingsDST){
|
||||
this(new java.util.SimpleTimeZone(rawOffsetGMT, ID, savingsStartMonth, savingsStartDay,
|
||||
public SimpleTimeZone( int raw, String ID,
|
||||
int startMonth, int startDay,
|
||||
int startDayOfWeek, int startTime,
|
||||
int startTimeMode,
|
||||
int endMonth, int endDay,
|
||||
int endDayOfWeek, int endTime,
|
||||
int endTimeMode,int dst){
|
||||
/*this(new java.util.SimpleTimeZone(rawOffsetGMT, ID, savingsStartMonth, savingsStartDay,
|
||||
savingsStartDayOfWeek, savingsStartTime, savingsEndMonth,
|
||||
savingsEndDay, savingsEndDayOfWeek, savingsEndTime, savingsDST), ID);
|
||||
|
||||
construct(rawOffsetGMT,
|
||||
savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
|
||||
savingsStartTime, savingsStartTimeMode,
|
||||
savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
|
||||
savingsEndTime, savingsEndTimeMode,
|
||||
savingsDST);
|
||||
savingsEndDay, savingsEndDayOfWeek, savingsEndTime, savingsDST), ID);*/
|
||||
construct(raw,
|
||||
startMonth, startDay, startDayOfWeek,
|
||||
startTime, startTimeMode,
|
||||
endMonth, endDay, endDayOfWeek,
|
||||
endTime, endTimeMode,
|
||||
dst);
|
||||
}
|
||||
// -------------------------------------
|
||||
/*
|
||||
|
@ -824,37 +842,37 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
/**
|
||||
* Internal construction method.
|
||||
*/
|
||||
private void construct(int rawOffsetGMT,
|
||||
int savingsStartMonth,
|
||||
int savingsStartDay,
|
||||
int savingsStartDayOfWeek,
|
||||
int savingsStartTime,
|
||||
int savingsStartTimeMode,
|
||||
int savingsEndMonth,
|
||||
int savingsEndDay,
|
||||
int savingsEndDayOfWeek,
|
||||
int savingsEndTime,
|
||||
int savingsEndTimeMode,
|
||||
int savingsDST) {
|
||||
this.raw = rawOffsetGMT;
|
||||
this.startMonth = savingsStartMonth;
|
||||
this.startDay = savingsStartDay;
|
||||
this.startDayOfWeek = savingsStartDayOfWeek;
|
||||
this.startTime = savingsStartTime;
|
||||
this.startTimeMode = savingsStartTimeMode;
|
||||
this.endMonth = savingsEndMonth;
|
||||
this.endDay = savingsEndDay;
|
||||
this.endDayOfWeek = savingsEndDayOfWeek;
|
||||
this.endTime = savingsEndTime;
|
||||
this.endTimeMode = savingsEndTimeMode;
|
||||
this.dst = savingsDST;
|
||||
private void construct(int raw,
|
||||
int startMonth,
|
||||
int startDay,
|
||||
int startDayOfWeek,
|
||||
int startTime,
|
||||
int startTimeMode,
|
||||
int endMonth,
|
||||
int endDay,
|
||||
int endDayOfWeek,
|
||||
int endTime,
|
||||
int endTimeMode,
|
||||
int dst) {
|
||||
this.raw = raw;
|
||||
this.startMonth = startMonth;
|
||||
this.startDay = startDay;
|
||||
this.startDayOfWeek = startDayOfWeek;
|
||||
this.startTime = startTime;
|
||||
this.startTimeMode = startTimeMode;
|
||||
this.endMonth = endMonth;
|
||||
this.endDay = endDay;
|
||||
this.endDayOfWeek = endDayOfWeek;
|
||||
this.endTime = endTime;
|
||||
this.endTimeMode = endTimeMode;
|
||||
this.dst = dst;
|
||||
this.startYear = 0;
|
||||
this.startMode = DOM_MODE;
|
||||
this.endMode = DOM_MODE;
|
||||
|
||||
decodeRules();
|
||||
|
||||
if (savingsDST <= 0) {
|
||||
if (dst <= 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
@ -889,7 +907,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
*/
|
||||
private void decodeStartRule() {
|
||||
|
||||
useDaylight = (boolean)((startDay != 0) && (endDay != 0) ? false : true);
|
||||
useDaylight = (boolean)((startDay != 0) && (endDay != 0) ? true : false );
|
||||
if (useDaylight && dst == 0) {
|
||||
dst = TimeZone.MILLIS_PER_DAY;
|
||||
}
|
||||
|
@ -923,7 +941,7 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
if (startDay < -5 || startDay > 5) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else if (startDay > STATICMONTHLENGTH[startMonth]) {
|
||||
} else if (startDay < 1 || startDay > staticMonthLength[startMonth]) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
@ -970,19 +988,22 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
if (endDay < -5 || endDay > 5) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else if (endDay > STATICMONTHLENGTH[endMonth]) {
|
||||
} else if (endDay<1 || endDay > staticMonthLength[endMonth]) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object obj){
|
||||
if (!super.equals(obj)) return false; // super does class check
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
SimpleTimeZone that = (SimpleTimeZone) obj;
|
||||
return raw == that.raw &&
|
||||
useDaylight == that.useDaylight &&
|
||||
idEquals(getID(),that.getID()) &&
|
||||
(!useDaylight
|
||||
// Only check rules if using DST
|
||||
|| (dst == that.dst &&
|
||||
|| (dst == that.dst &&
|
||||
startMode == that.startMode &&
|
||||
startMonth == that.startMonth &&
|
||||
startDay == that.startDay &&
|
||||
|
@ -995,9 +1016,18 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
endDayOfWeek == that.endDayOfWeek &&
|
||||
endTime == that.endTime &&
|
||||
endTimeMode == that.endTimeMode &&
|
||||
startYear == that.startYear));
|
||||
startYear == that.startYear ));
|
||||
|
||||
}
|
||||
private boolean idEquals(String id1, String id2){
|
||||
if(id1==null && id2==null){
|
||||
return true;
|
||||
}
|
||||
if(id1!=null && id2!=null){
|
||||
return id1.equals(id2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public int hashCode(){
|
||||
int ret = (int)( super.hashCode() +
|
||||
raw ^ (raw>>>8) +
|
||||
|
@ -1020,6 +1050,26 @@ public class SimpleTimeZone extends JDKTimeZone {
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
SimpleTimeZone clone = new SimpleTimeZone( raw, getID());
|
||||
clone.startMonth = startMonth;
|
||||
clone.startDay = startDay;
|
||||
clone.startDayOfWeek = startDayOfWeek;
|
||||
clone.startTime = startTime;
|
||||
clone.startTimeMode = startTimeMode;
|
||||
clone.endMonth = endMonth;
|
||||
clone.endDay = endDay;
|
||||
clone.endDayOfWeek = endDayOfWeek;
|
||||
clone.endTime = endTime;
|
||||
clone.endTimeMode = endTimeMode;
|
||||
clone.dst = dst;
|
||||
clone.startYear = startYear;
|
||||
clone.startMode = startMode;
|
||||
clone.endMode = endMode;
|
||||
clone.useDaylight = useDaylight;
|
||||
return clone;
|
||||
}
|
||||
public boolean hasSameRules(TimeZone othr) {
|
||||
if(!(othr instanceof SimpleTimeZone)){
|
||||
return false;
|
||||
|
|
|
@ -565,6 +565,9 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
* We cannot return NULL, because that would break compatibility
|
||||
* with the JDK.
|
||||
*/
|
||||
if(ID==null){
|
||||
throw new NullPointerException();
|
||||
}
|
||||
TimeZone result = ZoneMeta.getSystemTimeZone(ID);
|
||||
|
||||
if (result == null) {
|
||||
|
@ -587,7 +590,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
* @stable ICU 2.0
|
||||
*/
|
||||
public static String[] getAvailableIDs(int rawOffset) {
|
||||
return java.util.TimeZone.getAvailableIDs(rawOffset);
|
||||
return ZoneMeta.getAvailableIDs(rawOffset);
|
||||
|
||||
}
|
||||
|
||||
|
@ -616,7 +619,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
* @stable ICU 2.0
|
||||
*/
|
||||
public static String[] getAvailableIDs() {
|
||||
return java.util.TimeZone.getAvailableIDs();
|
||||
return ZoneMeta.getAvailableIDs();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -684,6 +687,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
* @stable ICU 2.0
|
||||
*/
|
||||
public static synchronized void setDefault(TimeZone tz) {
|
||||
|
||||
defaultZone = tz;
|
||||
// Keep java.util.TimeZone default in sync so java.util.Date
|
||||
// can interoperate with com.ibm.icu.util classes.
|
||||
|
|
Loading…
Add table
Reference in a new issue