Source Code Cross Referenced for FormatableArrayHolder.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » iapi » services » 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 » Database DBMS » db derby 10.2 » org.apache.derby.iapi.services.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.iapi.services.io.FormatableArrayHolder
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.iapi.services.io;
023:
024:        import org.apache.derby.iapi.services.io.ArrayInputStream;
025:
026:        import org.apache.derby.iapi.services.io.StoredFormatIds;
027:        import org.apache.derby.iapi.services.io.FormatIdUtil;
028:        import org.apache.derby.iapi.services.io.ArrayUtil;
029:        import org.apache.derby.iapi.services.io.Formatable;
030:
031:        import org.apache.derby.iapi.services.sanity.SanityManager;
032:
033:        import java.io.ObjectOutput;
034:        import java.io.ObjectInput;
035:        import java.io.IOException;
036:
037:        import java.lang.reflect.Array;
038:
039:        /**
040:         * A formatable holder for an array of formatables.
041:         * Used to avoid serializing arrays.
042:         */
043:        public class FormatableArrayHolder implements  Formatable {
044:            /********************************************************
045:             **
046:             **	This class implements Formatable. That means that it
047:             **	can write itself to and from a formatted stream. If
048:             **	you add more fields to this class, make sure that you
049:             **	also write/read them with the writeExternal()/readExternal()
050:             **	methods.
051:             **
052:             **	If, inbetween releases, you add more fields to this class,
053:             **	then you should bump the version number emitted by the getTypeFormatId()
054:             **	method.
055:             **
056:             ********************************************************/
057:
058:            // the array
059:            private Object[] array;
060:
061:            /**
062:             * Niladic constructor for formatable
063:             */
064:            public FormatableArrayHolder() {
065:            }
066:
067:            /**
068:             * Construct a FormatableArrayHolder using the input
069:             * array.
070:             *
071:             * @param array the array to hold
072:             */
073:            public FormatableArrayHolder(Object[] array) {
074:                if (SanityManager.DEBUG) {
075:                    SanityManager
076:                            .ASSERT(array != null,
077:                                    "array input to constructor is null, code can't handle this.");
078:                }
079:
080:                this .array = array;
081:            }
082:
083:            /**
084:             * Set the held array to the input array.
085:             *
086:             * @param array the array to hold
087:             */
088:            public void setArray(Object[] array) {
089:                if (SanityManager.DEBUG) {
090:                    SanityManager
091:                            .ASSERT(array != null,
092:                                    "array input to setArray() is null, code can't handle this.");
093:                }
094:
095:                this .array = array;
096:            }
097:
098:            /**
099:             * Get the held array of formatables, and return
100:             * it in an array of type inputClass.
101:             *
102:             * @param inputClass	the class to use for the returned array
103:             *
104:             * @return an array of formatables
105:             */
106:            public Object[] getArray(Class inputClass) {
107:                Object[] outArray = (Object[]) Array.newInstance(inputClass,
108:                        array.length);
109:
110:                /*
111:                 ** HACK: on as400 the following arraycopy() throws an
112:                 ** ArrayStoreException because the output array isn't
113:                 ** assignment compatible with the input array.  This
114:                 ** is a bug on as400, but to get around it we are
115:                 ** going to do an element by element copy.
116:                 */
117:                //System.arraycopy(array, 0, outArray, 0, outArray.length);
118:                for (int i = 0; i < outArray.length; i++) {
119:                    outArray[i] = array[i];
120:                }
121:
122:                return outArray;
123:            }
124:
125:            //////////////////////////////////////////////
126:            //
127:            // FORMATABLE
128:            //
129:            //////////////////////////////////////////////
130:            /**
131:             * Write this array out
132:             *
133:             * @param out write bytes here
134:             *
135:             * @exception IOException thrown on error
136:             */
137:            public void writeExternal(ObjectOutput out) throws IOException {
138:                if (SanityManager.DEBUG) {
139:                    SanityManager.ASSERT(array != null,
140:                            "Array is null, which isn't expected");
141:                }
142:
143:                ArrayUtil.writeArrayLength(out, array);
144:                ArrayUtil.writeArrayItems(out, array);
145:            }
146:
147:            /**
148:             * Read this array from a stream of stored objects.
149:             *
150:             * @param in read this.
151:             *
152:             * @exception IOException					thrown on error
153:             * @exception ClassNotFoundException		thrown on error
154:             */
155:            public void readExternal(ObjectInput in) throws IOException,
156:                    ClassNotFoundException {
157:                array = new Object[ArrayUtil.readArrayLength(in)];
158:                ArrayUtil.readArrayItems(in, array);
159:            }
160:
161:            public void readExternal(ArrayInputStream in) throws IOException,
162:                    ClassNotFoundException {
163:                array = new Formatable[ArrayUtil.readArrayLength(in)];
164:                ArrayUtil.readArrayItems(in, array);
165:            }
166:
167:            /**
168:             * Get the formatID which corresponds to this class.
169:             *
170:             *	@return	the formatID of this class
171:             */
172:            public int getTypeFormatId() {
173:                return StoredFormatIds.FORMATABLE_ARRAY_HOLDER_V01_ID;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.