Source Code Cross Referenced for JDKTimeZone.java in  » Internationalization-Localization » icu4j » com » ibm » icu » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         **********************************************************************
003:         * Copyright (c) 2003-2006, International Business Machines
004:         * Corporation and others.  All Rights Reserved.
005:         **********************************************************************
006:         * Author: Alan Liu
007:         * Created: October 2 2003
008:         * Since: ICU 2.8
009:         **********************************************************************
010:         */
011:        package com.ibm.icu.impl;
012:
013:        import com.ibm.icu.util.TimeZone;
014:        import com.ibm.icu.util.SimpleTimeZone;
015:        import java.util.Date;
016:        import java.io.IOException;
017:
018:        /**
019:         * Wrapper around OlsonTimeZone object. Due to serialziation constraints
020:         * SimpleTimeZone cannot be a subclass of OlsonTimeZone.
021:         * 
022:         * The complement of this is TimeZoneAdapter, which makes a
023:         * com.ibm.icu.util.TimeZone look like a java.util.TimeZone.
024:         *
025:         * @see com.ibm.icu.impl.JDKTimeZone
026:         * @author Alan Liu
027:         * @since ICU 2.8
028:         */
029:        public class JDKTimeZone extends TimeZone {
030:
031:            private static final long serialVersionUID = -3724907649889455280L;
032:
033:            /**
034:             * The java.util.TimeZone wrapped by this object.  Must not be null.
035:             */
036:            // give access to SimpleTimeZone
037:            protected transient OlsonTimeZone zone;
038:
039:            /**
040:             * Given a java.util.TimeZone, wrap it in the appropriate adapter
041:             * subclass of com.ibm.icu.util.TimeZone and return the adapter.
042:             */
043:            public static TimeZone wrap(java.util.TimeZone tz) {
044:                if (tz instanceof  TimeZoneAdapter) {
045:                    return ((TimeZoneAdapter) tz).unwrap();
046:                }
047:                if (tz instanceof  java.util.SimpleTimeZone) {
048:                    return new SimpleTimeZone((java.util.SimpleTimeZone) tz, tz
049:                            .getID());
050:                }
051:                return new JDKTimeZone(tz);
052:            }
053:
054:            /**
055:             * Constructs a JDKTimeZone given a java.util.TimeZone reference
056:             * which must not be null.
057:             * @param tz the time zone to wrap
058:             * 
059:             * @internal 
060:             * @deprecated This API is ICU internal only.
061:             */
062:            public JDKTimeZone(java.util.TimeZone tz) {
063:                String id = tz.getID();
064:                try {
065:                    zone = new OlsonTimeZone(id);
066:                } catch (Exception ex) {
067:                    // throw away exception
068:                }
069:                super .setID(id);
070:            }
071:
072:            protected JDKTimeZone(OlsonTimeZone tz) {
073:                zone = tz;
074:                super .setID(zone.getID());
075:            }
076:
077:            /**
078:             * Default constructor
079:             */
080:            protected JDKTimeZone() {
081:            }
082:
083:            /**
084:             * Sets the time zone ID. This does not change any other data in
085:             * the time zone object.
086:             * @param ID the new time zone ID.
087:             */
088:            public void setID(String ID) {
089:                super .setID(ID);
090:                if (zone != null) {
091:                    zone.setID(ID);
092:                }
093:            }
094:
095:            /**
096:             * TimeZone API; calls through to wrapped time zone.
097:             */
098:            public int getOffset(int era, int year, int month, int day,
099:                    int dayOfWeek, int milliseconds) {
100:
101:                if (zone != null) {
102:                    return zone.getOffset(era, year, month, day, dayOfWeek,
103:                            milliseconds);
104:                }
105:                // should never occur except 
106:                // when old object of older version of JDKTimeZone are de-serialized.
107:                // these objects may contain ids that OlsonTimeZone may not understand 
108:                // in such cases zone will be null
109:                return 0;
110:            }
111:
112:            public void getOffset(long date, boolean local, int[] offsets) {
113:
114:                if (zone != null) {
115:                    zone.getOffset(date, local, offsets);
116:                } else {
117:                    super .getOffset(date, local, offsets);
118:                }
119:            }
120:
121:            /**
122:             * TimeZone API; calls through to wrapped time zone.
123:             */
124:            public void setRawOffset(int offsetMillis) {
125:                if (zone != null) {
126:                    zone.setRawOffset(offsetMillis);
127:                }
128:            }
129:
130:            /**
131:             * TimeZone API; calls through to wrapped time zone.
132:             */
133:            public int getRawOffset() {
134:                if (zone != null) {
135:                    return zone.getRawOffset();
136:                }
137:                // should never occur except 
138:                // when old object of older version of JDKTimeZone are de-serialized.
139:                // these objects may contain ids that OlsonTimeZone may not understand 
140:                // in such cases zone will be null
141:                return 0;
142:            }
143:
144:            /**
145:             * TimeZone API; calls through to wrapped time zone.
146:             */
147:            public boolean useDaylightTime() {
148:                if (zone != null) {
149:                    return zone.useDaylightTime();
150:                }
151:                // should never occur except 
152:                // when old object of older version of JDKTimeZone are de-serialized.
153:                // these objects may contain ids that OlsonTimeZone may not understand 
154:                // in such cases zone will be null
155:                return false;
156:            }
157:
158:            /**
159:             * TimeZone API; calls through to wrapped time zone.
160:             */
161:            public boolean inDaylightTime(Date date) {
162:                if (zone != null) {
163:                    return zone.inDaylightTime(date);
164:                }
165:                // should never occur except 
166:                // when old object of older version of JDKTimeZone are de-serialized.
167:                // these objects may contain ids that OlsonTimeZone may not understand 
168:                // in such cases zone will be null
169:                return false;
170:            }
171:
172:            /**
173:             * TimeZone API.
174:             */
175:            public boolean hasSameRules(TimeZone other) {
176:                if (other == null) {
177:                    return false;
178:                }
179:                if (other instanceof  JDKTimeZone) {
180:                    if (zone != null) {
181:                        return zone.hasSameRules(((JDKTimeZone) other).zone);
182:                    }
183:                }
184:                return super .hasSameRules(other);
185:            }
186:
187:            /**
188:             * Boilerplate API; calls through to wrapped object.
189:             */
190:            public Object clone() {
191:                JDKTimeZone clone = new JDKTimeZone();
192:                if (zone != null) {
193:                    clone.zone = (OlsonTimeZone) zone.clone();
194:                }
195:                return clone;
196:            }
197:
198:            /**
199:             * Boilerplate API; calls through to wrapped object.
200:             */
201:            public synchronized int hashCode() {
202:                if (zone != null) {
203:                    return zone.hashCode();
204:                }
205:                return super .hashCode();
206:            }
207:
208:            /**
209:             * Returns the amount of time in ms that the clock is advanced during DST.
210:             * @return the number of milliseconds the time is
211:             * advanced with respect to standard time when the daylight savings rules
212:             * are in effect. A positive number, typically one hour (3600000).
213:             * @stable ICU 2.0
214:             */
215:            public int getDSTSavings() {
216:                if (useDaylightTime()) {
217:                    if (zone != null) {
218:                        return zone.getDSTSavings();
219:                    }
220:                    return 3600000;
221:                }
222:                return 0;
223:            }
224:
225:            /**
226:             * Boilerplate API; calls through to wrapped object.
227:             */
228:            public boolean equals(Object obj) {
229:                try {
230:                    if (obj != null) {
231:                        TimeZone tz1 = zone;
232:                        TimeZone tz2 = ((JDKTimeZone) obj).zone;
233:                        boolean equal = true;
234:                        if (tz1 != null && tz2 != null) {
235:                            equal = tz1.equals(tz2);
236:                        }
237:                        return equal;
238:                    }
239:                    return false;
240:                } catch (ClassCastException e) {
241:                    return false;
242:                }
243:            }
244:
245:            /**
246:             * Returns a string representation of this object.
247:             * @return  a string representation of this object.
248:             */
249:            public String toString() {
250:                return "JDKTimeZone: " + zone.toString();
251:            }
252:
253:            private void writeObject(java.io.ObjectOutputStream out)
254:                    throws IOException {
255:                if (zone != null) {
256:                    out.writeObject(zone.getID());
257:                } else {
258:                    out.writeObject(getID());
259:                }
260:            }
261:
262:            private void readObject(java.io.ObjectInputStream in)
263:                    throws IOException, ClassNotFoundException {
264:                String id = (String) in.readObject();
265:
266:                // create the TimeZone object if reading the old version of object
267:                try {
268:                    zone = new OlsonTimeZone(id);
269:                } catch (Exception ex) {
270:                    //throw away exception
271:                }
272:                setID(id);
273:            }
274:        }
275:
276:        //eof
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.