Source Code Cross Referenced for AbstractSerializationStreamWriter.java in  » Ajax » GWT » com » google » gwt » user » client » rpc » 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 » Ajax » GWT » com.google.gwt.user.client.rpc.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.user.client.rpc.impl;
017:
018:        import com.google.gwt.user.client.rpc.SerializationException;
019:        import com.google.gwt.user.client.rpc.SerializationStreamWriter;
020:
021:        /**
022:         * Base class for the client and server serialization streams. This class
023:         * handles the basic serialization and deserialization formatting for primitive
024:         * types since these are common between the client and the server.
025:         */
026:        public abstract class AbstractSerializationStreamWriter extends
027:                AbstractSerializationStream implements 
028:                SerializationStreamWriter {
029:
030:            @Override
031:            public abstract String toString();
032:
033:            public void writeBoolean(boolean fieldValue) {
034:                append(fieldValue ? "1" : "0");
035:            }
036:
037:            public void writeByte(byte fieldValue) {
038:                append(String.valueOf(fieldValue));
039:            }
040:
041:            public void writeChar(char ch) {
042:                // just use an int, it's more foolproof
043:                append(String.valueOf((int) ch));
044:            }
045:
046:            public void writeDouble(double fieldValue) {
047:                append(String.valueOf(fieldValue));
048:            }
049:
050:            public void writeFloat(float fieldValue) {
051:                append(String.valueOf(fieldValue));
052:            }
053:
054:            public void writeInt(int fieldValue) {
055:                append(String.valueOf(fieldValue));
056:            }
057:
058:            public void writeLong(long fieldValue) {
059:                append(String.valueOf(fieldValue));
060:            }
061:
062:            public void writeObject(Object instance)
063:                    throws SerializationException {
064:                if (instance == null) {
065:                    // write a null string
066:                    writeString(null);
067:                    return;
068:                }
069:
070:                int objIndex = getIndexForObject(instance);
071:                if (objIndex >= 0) {
072:                    // We've already encoded this object, make a backref
073:                    // Transform 0-based to negative 1-based
074:                    writeInt(-(objIndex + 1));
075:                    return;
076:                }
077:
078:                saveIndexForObject(instance);
079:
080:                // Serialize the type signature
081:                String typeSignature = getObjectTypeSignature(instance);
082:                writeString(typeSignature);
083:                // Now serialize the rest of the object
084:                serialize(instance, typeSignature);
085:            }
086:
087:            public void writeShort(short value) {
088:                append(String.valueOf(value));
089:            }
090:
091:            public void writeString(String value) {
092:                writeInt(addString(value));
093:            }
094:
095:            /**
096:             * Add a string to the string table and return its index.
097:             * 
098:             * @param string the string to add
099:             * @return the index to the string
100:             */
101:            protected abstract int addString(String string);
102:
103:            /**
104:             * Append a token to the underlying output buffer.
105:             * 
106:             * @param token the token to append
107:             */
108:            protected abstract void append(String token);
109:
110:            /**
111:             * Get the index for an object that may have previously been saved via
112:             * {@link #saveIndexForObject(Object)}.
113:             * 
114:             * @param instance the object to save
115:             * @return the index associated with this object, or -1 if this object hasn't
116:             *         been seen before
117:             */
118:            protected abstract int getIndexForObject(Object instance);
119:
120:            /**
121:             * Compute and return the type signature for an object.
122:             * 
123:             * @param instance the instance to inspect
124:             * @return the type signature of the instance
125:             */
126:            protected abstract String getObjectTypeSignature(Object instance);
127:
128:            /**
129:             * Remember this object as having been seen before.
130:             * 
131:             * @param instance the object to remember
132:             */
133:            protected abstract void saveIndexForObject(Object instance);
134:
135:            /**
136:             * Serialize an object into the stream.
137:             * 
138:             * @param instance the object to serialize
139:             * @param typeSignature the type signature of the object
140:             * @throws SerializationException
141:             */
142:            protected abstract void serialize(Object instance,
143:                    String typeSignature) throws SerializationException;
144:
145:        }
w__w__w___.j_a___v__a_2_s._c__o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.