Source Code Cross Referenced for ZoneRec.java in  » 6.0-JDK-Modules » j2me » sun » tools » javazic » 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 » 6.0 JDK Modules » j2me » sun.tools.javazic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)ZoneRec.java	1.6 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation. 
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt). 
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA 
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions. 
025:         */
026:
027:        package sun.tools.javazic;
028:
029:        import java.io.BufferedReader;
030:        import java.io.FileReader;
031:        import java.io.FileNotFoundException;
032:        import java.io.IOException;
033:        import java.util.ArrayList;
034:        import java.util.HashMap;
035:        import java.util.HashSet;
036:        import java.util.StringTokenizer;
037:
038:        /**
039:         * ZoneRec hold information of time zone corresponding to each text
040:         * line of the "Zone" part.
041:         *
042:         * @since 1.4
043:         */
044:        class ZoneRec {
045:            private int gmtOffset;
046:            private String ruleName;
047:            private int directSave;
048:            private Rule ruleRef;
049:            private String format;
050:            private boolean hasUntil;
051:            private int untilYear;
052:            private int untilMonth;
053:            private RuleDay untilDay;
054:            private Time untilTime;
055:            private long untilInMillis;
056:            private String line;
057:
058:            /**
059:             * @return the "UNTIL" value in milliseconds
060:             */
061:            Time getUntilTime() {
062:                return untilTime;
063:            }
064:
065:            /**
066:             * @return the GMT offset value in milliseconds
067:             */
068:            int getGmtOffset() {
069:                return gmtOffset;
070:            }
071:
072:            /**
073:             * @return the rule name to which this zone record refers
074:             */
075:            String getRuleName() {
076:                return ruleName;
077:            }
078:
079:            /**
080:             * @return the amount of saving time directly defined in the
081:             * "RULES/SAVE" field.
082:             */
083:            int getDirectSave() {
084:                return directSave;
085:            }
086:
087:            /**
088:             * @return true if this zone record has a reference to a rule
089:             */
090:            boolean hasRuleReference() {
091:                return ruleRef != null;
092:            }
093:
094:            /**
095:             * Returns the "FORMAT" field string of this zone record. This 
096:             * @return the "FORMAT" field
097:             */
098:            String getFormat() {
099:                return format;
100:            }
101:
102:            /**
103:             * @return the year in the "UNTIL" field
104:             */
105:            int getUntilYear() {
106:                return untilYear;
107:            }
108:
109:            /**
110:             * Returns the "UNTIL" field value in milliseconds from Janurary
111:             * 1, 1970 0:00 GMT.
112:             * @param currentSave the amount of daylight saving in
113:             * milliseconds that is used to adjust wall-clock time.
114:             * @return the milliseconds value of the "UNTIL" field
115:             */
116:            long getUntilTime(int currentSave) {
117:                if (untilTime.isWall()) {
118:                    return untilInMillis - currentSave;
119:                }
120:                return untilInMillis;
121:            }
122:
123:            /**
124:             * Returns the "UNTIL" time in milliseconds without adjusting GMT
125:             * offsets or daylight saving.
126:             * @return local "UNTIL" time in milliseconds
127:             */
128:            long getLocalUntilTime() {
129:                return Time.getLocalTime(untilYear, untilMonth, untilDay,
130:                        untilTime.getTime());
131:            }
132:
133:            /**
134:             * Returns the "UNTIL" time in milliseconds with adjusting GMT offsets and daylight saving.
135:             * @return the "UNTIL" time after the adjustment
136:             */
137:            long getLocalUntilTime(int save, int gmtOffset) {
138:                return Time.getLocalTime(untilYear, untilMonth, untilDay, save,
139:                        gmtOffset, untilTime);
140:            }
141:
142:            /**
143:             * @return the text line of this zone record
144:             */
145:            String getLine() {
146:                return line;
147:            }
148:
149:            /**
150:             * Sets the specified text line to this zone record
151:             */
152:            void setLine(String line) {
153:                this .line = line;
154:            }
155:
156:            /**
157:             * @return true if this zone record has the "UNTIL" field
158:             */
159:            boolean hasUntil() {
160:                return this .hasUntil;
161:            }
162:
163:            /**
164:             * Adjusts the "UNTIL" time to GMT offset if this zone record has
165:             * it.  <code>untilTime</code> is not adjusted to daylight saving
166:             * in this method.
167:             */
168:            void adjustTime() {
169:                if (!hasUntil()) {
170:                    return;
171:                }
172:                if (untilTime.isSTD() || untilTime.isWall()) {
173:                    // adjust to gmt offset only here.  adjust to real
174:                    // wall-clock time when tracking rules
175:                    untilInMillis -= gmtOffset;
176:                }
177:            }
178:
179:            /**
180:             * @return the reference to the Rule object
181:             */
182:            Rule getRuleRef() {
183:                return ruleRef;
184:            }
185:
186:            /**
187:             * Resolves the reference to a Rule and adjusts its "UNTIL" time
188:             * to GMT offset.
189:             */
190:            void resolve(Zoneinfo zi) {
191:                if (ruleName != null && (!"-".equals(ruleName))) {
192:                    ruleRef = zi.getRule(ruleName);
193:                }
194:                adjustTime();
195:            }
196:
197:            /**
198:             * Parses a Zone text line that is described by a StringTokenizer.
199:             * @param tokens represents tokens of a Zone text line
200:             * @return the zone record produced by parsing the text
201:             */
202:            static ZoneRec parse(StringTokenizer tokens) {
203:                ZoneRec rec = new ZoneRec();
204:                try {
205:                    rec.gmtOffset = (int) Time.parse(tokens.nextToken())
206:                            .getTime();
207:                    String token = tokens.nextToken();
208:                    char c = token.charAt(0);
209:                    if (c >= '0' && c <= '9') {
210:                        rec.directSave = (int) Time.parse(token).getTime();
211:                    } else {
212:                        rec.ruleName = token;
213:                    }
214:                    rec.format = tokens.nextToken();
215:                    if (tokens.hasMoreTokens()) {
216:                        rec.hasUntil = true;
217:                        rec.untilYear = Integer.parseInt(tokens.nextToken());
218:                        if (tokens.hasMoreTokens()) {
219:                            rec.untilMonth = Month.parse(tokens.nextToken());
220:                        } else {
221:                            rec.untilMonth = Month.parse("Jan");
222:                        }
223:                        if (tokens.hasMoreTokens()) {
224:                            rec.untilDay = RuleDay.parse(tokens.nextToken());
225:                        } else {
226:                            rec.untilDay = new RuleDay(1);
227:                        }
228:                        if (tokens.hasMoreTokens()) {
229:                            rec.untilTime = Time.parse(tokens.nextToken());
230:                        } else {
231:                            rec.untilTime = Time.parse("0:00");
232:                        }
233:                        rec.untilInMillis = rec.getLocalUntilTime();
234:                    }
235:                } catch (Exception e) {
236:                    // TODO: error reporting
237:                    e.printStackTrace();
238:                }
239:                return rec;
240:            }
241:
242:            private static void panic(String msg) {
243:                Main.panic(msg);
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.