Source Code Cross Referenced for EmulatedFieldsForDumping.java in  » Apache-Harmony-Java-SE » java-package » java » io » 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 » Apache Harmony Java SE » java package » java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package java.io;
019:
020:        /**
021:         * An EmulatedFieldsForDumping is an object that represents a set of emulated
022:         * fields for an object being dumped. It is a concrete implementation for
023:         * ObjectOutputStream.PutField
024:         * 
025:         * 
026:         * @see ObjectOutputStream.PutField
027:         * @see EmulatedFieldsForLoading
028:         */
029:        class EmulatedFieldsForDumping extends ObjectOutputStream.PutField {
030:
031:            // The actual representation, with a more powerful API (set&get)
032:            private EmulatedFields emulatedFields;
033:
034:            /**
035:             * Constructs a new instance of EmulatedFieldsForDumping.
036:             * 
037:             * @param streamClass
038:             *            a ObjectStreamClass, which describe the fields to be emulated
039:             *            (names, types, etc).
040:             */
041:            EmulatedFieldsForDumping(ObjectStreamClass streamClass) {
042:                super ();
043:                emulatedFields = new EmulatedFields(streamClass.fields(),
044:                        (ObjectStreamField[]) null);
045:            }
046:
047:            /**
048:             * Return the actual EmulatedFields instance used by the receiver. We have
049:             * the actual work in a separate class so that the code can be shared. The
050:             * receiver has to be of a subclass of PutField.
051:             * 
052:             * @return array of ObjectSlot the receiver represents.
053:             */
054:            EmulatedFields emulatedFields() {
055:                return emulatedFields;
056:            }
057:
058:            /**
059:             * Find and set the byte value of a given field named <code>name</code> in
060:             * the receiver.
061:             * 
062:             * @param name
063:             *            A String, the name of the field to set
064:             * @param value
065:             *            New value for the field.
066:             */
067:            @Override
068:            public void put(String name, byte value) {
069:                emulatedFields.put(name, value);
070:            }
071:
072:            /**
073:             * Find and set the char value of a given field named <code>name</code> in
074:             * the receiver.
075:             * 
076:             * @param name
077:             *            A String, the name of the field to set
078:             * @param value
079:             *            New value for the field.
080:             */
081:            @Override
082:            public void put(String name, char value) {
083:                emulatedFields.put(name, value);
084:            }
085:
086:            /**
087:             * Find and set the double value of a given field named <code>name</code>
088:             * in the receiver.
089:             * 
090:             * @param name
091:             *            A String, the name of the field to set
092:             * @param value
093:             *            New value for the field.
094:             */
095:            @Override
096:            public void put(String name, double value) {
097:                emulatedFields.put(name, value);
098:            }
099:
100:            /**
101:             * Find and set the float value of a given field named <code>name</code>
102:             * in the receiver.
103:             * 
104:             * @param name
105:             *            A String, the name of the field to set
106:             * @param value
107:             *            New value for the field.
108:             */
109:            @Override
110:            public void put(String name, float value) {
111:                emulatedFields.put(name, value);
112:            }
113:
114:            /**
115:             * Find and set the int value of a given field named <code>name</code> in
116:             * the receiver.
117:             * 
118:             * @param name
119:             *            A String, the name of the field to set
120:             * @param value
121:             *            New value for the field.
122:             */
123:            @Override
124:            public void put(String name, int value) {
125:                emulatedFields.put(name, value);
126:            }
127:
128:            /**
129:             * Find and set the long value of a given field named <code>name</code> in
130:             * the receiver.
131:             * 
132:             * @param name
133:             *            A String, the name of the field to set
134:             * @param value
135:             *            New value for the field.
136:             */
137:            @Override
138:            public void put(String name, long value) {
139:                emulatedFields.put(name, value);
140:            }
141:
142:            /**
143:             * Find and set the Object value of a given field named <code>name</code>
144:             * in the receiver.
145:             * 
146:             * @param name
147:             *            A String, the name of the field to set
148:             * @param value
149:             *            New value for the field.
150:             */
151:            @Override
152:            public void put(String name, Object value) {
153:                emulatedFields.put(name, value);
154:            }
155:
156:            /**
157:             * Find and set the short value of a given field named <code>name</code>
158:             * in the receiver.
159:             * 
160:             * @param name
161:             *            A String, the name of the field to set
162:             * @param value
163:             *            New value for the field.
164:             */
165:            @Override
166:            public void put(String name, short value) {
167:                emulatedFields.put(name, value);
168:            }
169:
170:            /**
171:             * Find and set the boolean value of a given field named <code>name</code>
172:             * in the receiver.
173:             * 
174:             * @param name
175:             *            A String, the name of the field to set
176:             * @param value
177:             *            New value for the field.
178:             */
179:            @Override
180:            public void put(String name, boolean value) {
181:                emulatedFields.put(name, value);
182:            }
183:
184:            /**
185:             * Write the field values to the specified ObjectOutput.
186:             * 
187:             * @param output
188:             *            the ObjectOutput
189:             * 
190:             * @throws IOException
191:             *             If an IO exception happened when writing the field values.
192:             */
193:            @Override
194:            @Deprecated
195:            @SuppressWarnings("deprecation")
196:            public void write(ObjectOutput output) throws IOException {
197:                EmulatedFields.ObjectSlot[] slots = emulatedFields.slots();
198:                for (int i = 0; i < slots.length; i++) {
199:                    EmulatedFields.ObjectSlot slot = slots[i];
200:                    Object fieldValue = slot.getFieldValue();
201:                    Class<?> type = slot.getField().getType();
202:                    // WARNING - default values exist for each primitive type
203:                    if (type == Integer.TYPE) {
204:                        output
205:                                .writeInt(fieldValue != null ? ((Integer) fieldValue)
206:                                        .intValue()
207:                                        : 0);
208:                    } else if (type == Byte.TYPE) {
209:                        output
210:                                .writeByte(fieldValue != null ? ((Byte) fieldValue)
211:                                        .byteValue()
212:                                        : (byte) 0);
213:                    } else if (type == Character.TYPE) {
214:                        output
215:                                .writeChar(fieldValue != null ? ((Character) fieldValue)
216:                                        .charValue()
217:                                        : (char) 0);
218:                    } else if (type == Short.TYPE) {
219:                        output
220:                                .writeShort(fieldValue != null ? ((Short) fieldValue)
221:                                        .shortValue()
222:                                        : (short) 0);
223:                    } else if (type == Boolean.TYPE) {
224:                        output
225:                                .writeBoolean(fieldValue != null ? ((Boolean) fieldValue)
226:                                        .booleanValue()
227:                                        : false);
228:                    } else if (type == Long.TYPE) {
229:                        output
230:                                .writeLong(fieldValue != null ? ((Long) fieldValue)
231:                                        .longValue()
232:                                        : (long) 0);
233:                    } else if (type == Float.TYPE) {
234:                        output
235:                                .writeFloat(fieldValue != null ? ((Float) fieldValue)
236:                                        .floatValue()
237:                                        : (float) 0);
238:                    } else if (type == Double.TYPE) {
239:                        output
240:                                .writeDouble(fieldValue != null ? ((Double) fieldValue)
241:                                        .doubleValue()
242:                                        : (double) 0);
243:                    } else {
244:                        // Either array or Object
245:                        output.writeObject(fieldValue);
246:                    }
247:                }
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.