Source Code Cross Referenced for Provider.java in  » Ajax » MyGWT » net » mygwt » ui » client » state » 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 » Ajax » MyGWT » net.mygwt.ui.client.state 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MyGWT Widget Library
003:         * Copyright(c) 2007, MyGWT.
004:         * licensing@mygwt.net
005:         * 
006:         * http://mygwt.net/license
007:         */
008:        package net.mygwt.ui.client.state;
009:
010:        import java.util.Date;
011:
012:        import net.mygwt.ui.client.Events;
013:        import net.mygwt.ui.client.event.BaseEvent;
014:        import net.mygwt.ui.client.util.Observable;
015:
016:        /**
017:         * Abstract base class for state provider implementations. This class provides
018:         * methods for encoding and decoding objects.
019:         */
020:        public abstract class Provider extends Observable {
021:
022:            /**
023:             * Clears a value.
024:             * 
025:             * @param name the key name
026:             */
027:            public void clear(String name) {
028:                clearKey(name);
029:                BaseEvent be = new BaseEvent();
030:                be.name = name;
031:                fireEvent(Events.StateChange, be);
032:            }
033:
034:            /**
035:             * Returns the current value for a key.
036:             * 
037:             * @param name the key name
038:             * @return the value
039:             */
040:            public Object get(String name) {
041:                String val = getValue(name);
042:                if (val == null)
043:                    return null;
044:                Object obj = decodeValue(val);
045:                return obj;
046:            }
047:
048:            /**
049:             * Returns the current value for a key.
050:             * 
051:             * @param name the key name
052:             * @return the value
053:             */
054:            public String getString(String name) {
055:                String val = getValue(name);
056:                if (val == null)
057:                    return null;
058:                String obj = (String) decodeValue(val);
059:                return obj;
060:            }
061:
062:            /**
063:             * Returns the current value for a key.
064:             * 
065:             * @param name the key name
066:             * @return the value
067:             */
068:            public boolean getBoolean(String name) {
069:                String val = getValue(name);
070:                if (val == null)
071:                    return false;
072:                Boolean bVal = (Boolean) decodeValue(val);
073:                return bVal.booleanValue();
074:            }
075:
076:            /**
077:             * Returns the current value for a key.
078:             * 
079:             * @param name the key name
080:             * @return the value
081:             */
082:            public Date getDate(String name) {
083:                String val = getValue(name);
084:                if (val == null)
085:                    return null;
086:                Date date = (Date) decodeValue(val);
087:                return date;
088:            }
089:
090:            /**
091:             * Returns the current value for a key.
092:             * 
093:             * @param name the key name
094:             * @return the value or -1
095:             */
096:            public int getInteger(String name) {
097:                String val = getValue(name);
098:                Integer iVal = (Integer) decodeValue(val);
099:                if (iVal == null) {
100:                    return -1;
101:                }
102:                return iVal.intValue();
103:            }
104:
105:            /**
106:             * Sets a key.
107:             * 
108:             * @param name the key name
109:             * @param value the value
110:             */
111:            public void set(String name, Object value) {
112:                String val = encodeValue(value);
113:                setValue(name, val);
114:                BaseEvent be = new BaseEvent();
115:                be.name = name;
116:                be.value = value;
117:                fireEvent(Events.StateChange, be);
118:            }
119:
120:            protected abstract void clearKey(String name);
121:
122:            protected Object decodeValue(String value) {
123:                if (value == null)
124:                    return null;
125:                String type = value.substring(0, 2);
126:                String val = value.substring(2);
127:                if (type.equals("i:")) {
128:                    return Integer.decode(val);
129:                } else if (type.equals("d:")) {
130:                    long time = Long.parseLong(val);
131:                    return new Date(time);
132:                } else if (type.equals("b:")) {
133:                    return new Boolean(val);
134:                }
135:                return val;
136:            }
137:
138:            protected String encodeValue(Object value) {
139:                if (value instanceof  Date) {
140:                    return "d:" + ((Date) value).getTime();
141:                } else if (value instanceof  Integer) {
142:                    return "i:" + value;
143:                } else if (value instanceof  Float) {
144:                    return "i:" + value;
145:                } else if (value instanceof  Boolean) {
146:                    return "b:" + value;
147:                }
148:                return "s:" + value.toString();
149:            }
150:
151:            protected abstract String getValue(String name);
152:
153:            protected abstract void setValue(String name, String value);
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.