Source Code Cross Referenced for IndirectingSerializableExtension.java in  » Database-JDBC-Connection-Pool » c3p0 » com » mchange » v2 » codegen » bean » 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 JDBC Connection Pool » c3p0 » com.mchange.v2.codegen.bean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Distributed as part of c3p0 v.0.9.1.2
003:         *
004:         * Copyright (C) 2005 Machinery For Change, Inc.
005:         *
006:         * Author: Steve Waldman <swaldman@mchange.com>
007:         *
008:         * This library is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU Lesser General Public License version 2.1, as 
010:         * published by the Free Software Foundation.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public License
018:         * along with this software; see the file LICENSE.  If not, write to the
019:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         */
022:
023:        package com.mchange.v2.codegen.bean;
024:
025:        import java.util.*;
026:        import java.io.Serializable;
027:        import java.io.IOException;
028:        import com.mchange.v2.codegen.IndentedWriter;
029:        import com.mchange.v2.ser.IndirectPolicy;
030:
031:        public class IndirectingSerializableExtension extends
032:                SerializableExtension {
033:            protected String findIndirectorExpr;
034:            protected String indirectorClassName;
035:
036:            /**
037:             * We expect this indirector to be a public class with a public no_arg ctor;
038:             * If you need the indirector initialized somehow, you'll have to extend
039:             * the class.
040:             *
041:             * @see #writeInitializeIndirector
042:             * @see #writeExtraDeclarations
043:             */
044:            public IndirectingSerializableExtension(String indirectorClassName) {
045:                this .indirectorClassName = indirectorClassName;
046:                this .findIndirectorExpr = "new " + indirectorClassName + "()";
047:            }
048:
049:            protected IndirectingSerializableExtension() {
050:            }
051:
052:            public Collection extraSpecificImports() {
053:                Collection col = super .extraSpecificImports();
054:                col.add(indirectorClassName);
055:                col.add("com.mchange.v2.ser.IndirectlySerialized");
056:                col.add("com.mchange.v2.ser.Indirector");
057:                col.add("com.mchange.v2.ser.SerializableUtils");
058:                col.add("java.io.NotSerializableException");
059:                return col;
060:            }
061:
062:            protected IndirectPolicy indirectingPolicy(Property prop,
063:                    Class propType) {
064:                if (Serializable.class.isAssignableFrom(propType))
065:                    return IndirectPolicy.DEFINITELY_DIRECT;
066:                else
067:                    return IndirectPolicy.INDIRECT_ON_EXCEPTION;
068:            }
069:
070:            /**
071:             * hook method... does nothing by default... override at will.
072:             * The indirector will be called, uh, "indirector".
073:             * You are in the middle of a method when you define this.
074:             */
075:            protected void writeInitializeIndirector(Property prop,
076:                    Class propType, IndentedWriter iw) throws IOException {
077:            }
078:
079:            protected void writeExtraDeclarations(ClassInfo info,
080:                    Class super classType, Property[] props, Class[] propTypes,
081:                    IndentedWriter iw) throws IOException {
082:            }
083:
084:            public void generate(ClassInfo info, Class super classType,
085:                    Property[] props, Class[] propTypes, IndentedWriter iw)
086:                    throws IOException {
087:                super .generate(info, super classType, props, propTypes, iw);
088:                writeExtraDeclarations(info, super classType, props, propTypes,
089:                        iw);
090:            }
091:
092:            protected void writeStoreObject(Property prop, Class propType,
093:                    IndentedWriter iw) throws IOException {
094:                IndirectPolicy policy = indirectingPolicy(prop, propType);
095:                if (policy == IndirectPolicy.DEFINITELY_INDIRECT)
096:                    writeIndirectStoreObject(prop, propType, iw);
097:                else if (policy == IndirectPolicy.INDIRECT_ON_EXCEPTION) {
098:                    iw.println("try");
099:                    iw.println("{");
100:                    iw.upIndent();
101:                    iw.println("//test serialize");
102:                    iw.println("SerializableUtils.toByteArray("
103:                            + prop.getName() + ");");
104:                    super .writeStoreObject(prop, propType, iw);
105:                    iw.downIndent();
106:                    iw.println("}");
107:                    iw.println("catch (NotSerializableException nse)");
108:                    iw.println("{");
109:                    iw.upIndent();
110:                    writeIndirectStoreObject(prop, propType, iw);
111:                    iw.downIndent();
112:                    iw.println("}");
113:                } else if (policy == IndirectPolicy.DEFINITELY_DIRECT)
114:                    super .writeStoreObject(prop, propType, iw);
115:                else
116:                    throw new InternalError(
117:                            "indirectingPolicy() overridden to return unknown policy: "
118:                                    + policy);
119:            }
120:
121:            protected void writeIndirectStoreObject(Property prop,
122:                    Class propType, IndentedWriter iw) throws IOException {
123:                iw.println("try");
124:                iw.println("{");
125:                iw.upIndent();
126:
127:                iw.println("Indirector indirector = " + findIndirectorExpr
128:                        + ';');
129:                writeInitializeIndirector(prop, propType, iw);
130:                iw.println("oos.writeObject( indirector.indirectForm( "
131:                        + prop.getName() + " ) );");
132:
133:                iw.downIndent();
134:                iw.println("}");
135:                iw.println("catch (IOException indirectionIOException)");
136:                iw.println("{ throw indirectionIOException; }");
137:                iw.println("catch (Exception indirectionOtherException)");
138:                iw
139:                        .println("{ throw new IOException(\"Problem indirectly serializing "
140:                                + prop.getName()
141:                                + ": \" + indirectionOtherException.toString() ); }");
142:            }
143:
144:            protected void writeUnstoreObject(Property prop, Class propType,
145:                    IndentedWriter iw) throws IOException {
146:                IndirectPolicy policy = indirectingPolicy(prop, propType);
147:                if (policy == IndirectPolicy.DEFINITELY_INDIRECT
148:                        || policy == IndirectPolicy.INDIRECT_ON_EXCEPTION) {
149:                    iw.println("Object o = ois.readObject();");
150:                    iw
151:                            .println("if (o instanceof IndirectlySerialized) o = ((IndirectlySerialized) o).getObject();");
152:                    iw.println("this." + prop.getName() + " = ("
153:                            + prop.getSimpleTypeName() + ") o;");
154:                } else if (policy == IndirectPolicy.DEFINITELY_DIRECT)
155:                    super .writeUnstoreObject(prop, propType, iw);
156:                else
157:                    throw new InternalError(
158:                            "indirectingPolicy() overridden to return unknown policy: "
159:                                    + policy);
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.