Source Code Cross Referenced for BeanGenerator.java in  » Database-DBMS » myoodb-2.2.1 » org » myoodb » tools » generator » 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 » myoodb 2.2.1 » org.myoodb.tools.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        ///////////////////////////////////////////////////////////////////////////////
002:        //
003:        //   Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004:        //
005:        //                          All Rights Reserved
006:        //
007:        //   This program is free software; you can redistribute it and/or modify
008:        //   it under the terms of the GNU General Public License and GNU Library
009:        //   General Public License as published by the Free Software Foundation;
010:        //   either version 2, or (at your option) any later version.
011:        //
012:        //   This program 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 General Public License and GNU Library General Public License
016:        //   for more details.
017:        //
018:        //   You should have received a copy of the GNU General Public License
019:        //   and GNU Library General Public License along with this program; if
020:        //   not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021:        //   MA 02139, USA.
022:        //
023:        ///////////////////////////////////////////////////////////////////////////////
024:        package org.myoodb.tools.generator;
025:
026:        import java.io.*;
027:        import java.util.*;
028:        import java.lang.reflect.*;
029:
030:        import org.myoodb.*;
031:        import org.myoodb.core.*;
032:
033:        public class BeanGenerator extends AbstractCodeGeneratorImpl implements 
034:                AbstractCodeGenerator {
035:            public final static String IMPL_NAME_SUFFIX = "@implExtension@";
036:            public final static String BEAN_NAME_SUFFIX = "@beanExtension@";
037:
038:            private String m_file;
039:            private PrintWriter m_out;
040:            private Class m_myoodbImplClass;
041:            private Method[] m_sortedMethods;
042:
043:            public BeanGenerator() {
044:                m_out = null;
045:                m_file = null;
046:                m_sortedMethods = null;
047:                m_myoodbImplClass = null;
048:            }
049:
050:            private void makeConstructor(String beanClassName) {
051:                beanClassName += BEAN_NAME_SUFFIX;
052:
053:                m_out.print("    public "
054:                        + Helper.simpleClassName(beanClassName) + "()\n");
055:                m_out.print("    {\n");
056:                m_out.print("    }\n");
057:                m_out.print("    public "
058:                        + Helper.simpleClassName(beanClassName)
059:                        + "(org.myoodb.core.Identifier id)\n");
060:                m_out.print("    {\n");
061:                m_out.print("        super(id);\n");
062:                m_out.print("    }\n");
063:            }
064:
065:            private void makePackage(String implementationClass) {
066:                m_out
067:                        .print("// JavaBean class generated by MyOODB-@version@ (DO NOT EDIT!)\n");
068:                m_out.print("\n");
069:                if (Helper.packageName(implementationClass).equals("") == false) {
070:                    m_out.print("package "
071:                            + Helper.packageName(implementationClass) + ";\n");
072:                    m_out.print("\n");
073:                }
074:            }
075:
076:            private void makeInhertance(String beanClassName) {
077:                beanClassName += BEAN_NAME_SUFFIX;
078:
079:                m_out.print("public class "
080:                        + Helper.simpleClassName(beanClassName)
081:                        + " extends org.myoodb.MyOodbBean\n");
082:                m_out.print("{\n");
083:            }
084:
085:            private void makeJavaBeanSetGetProperty(String name,
086:                    Method setMethod, Method getMethod) {
087:                AbstractCodeGenerator.Parameter parameters[] = getParameters(setMethod
088:                        .getParameterTypes());
089:                Class returnType = getMethod.getReturnType();
090:
091:                //
092:                // Set Method
093:                //
094:
095:                m_out.print("    private volatile " + parameters[0].getType()
096:                        + " " + name + ";\n");
097:                StringBuilder signaturBuf = new StringBuilder();
098:                signaturBuf.append("    public void set" + name + "(");
099:                signaturBuf.append(parameters[0].getType() + " "
100:                        + parameters[0].getName());
101:                signaturBuf.append(")\n");
102:                m_out.print(signaturBuf.toString());
103:                m_out.print("    {\n");
104:                m_out.print("        this." + name + " = "
105:                        + parameters[0].getName() + ";\n");
106:                m_out.print("    }\n");
107:
108:                //
109:                // Get Method
110:                //
111:
112:                signaturBuf = new StringBuilder();
113:                signaturBuf.append("    public " + getTypecode(returnType)
114:                        + " get" + name + "()\n");
115:                m_out.print(signaturBuf.toString());
116:                m_out.print("    {\n");
117:                m_out.print("        return this." + name + ";\n");
118:                m_out.print("    }\n");
119:            }
120:
121:            private void makeJavaBeanAddRemoveGetsProperty(String name,
122:                    Method addMethod) {
123:                AbstractCodeGenerator.Parameter parameters[] = getParameters(addMethod
124:                        .getParameterTypes());
125:
126:                //
127:                // Add Method
128:                //
129:
130:                m_out.print("    private volatile java.util.ArrayList<"
131:                        + parameters[0].getType() + "> " + name
132:                        + "List = new java.util.ArrayList<"
133:                        + parameters[0].getType() + ">();\n");
134:                StringBuilder signaturBuf = new StringBuilder();
135:                signaturBuf.append("    public void add" + name + "(");
136:                signaturBuf.append(parameters[0].getType() + " "
137:                        + parameters[0].getName());
138:                signaturBuf.append(")\n");
139:                m_out.print(signaturBuf.toString());
140:                m_out.print("    {\n");
141:                m_out.print("        this." + name + "List.add("
142:                        + parameters[0].getName() + ");\n");
143:                m_out.print("    }\n");
144:
145:                //
146:                // Remove Method
147:                //
148:
149:                signaturBuf = new StringBuilder();
150:                signaturBuf.append("    public boolean remove" + name + "(");
151:                signaturBuf.append(parameters[0].getType() + " "
152:                        + parameters[0].getName());
153:                signaturBuf.append(")\n");
154:                m_out.print(signaturBuf.toString());
155:                m_out.print("    {\n");
156:                m_out.print("        return this." + name + "List.remove("
157:                        + parameters[0].getName() + ");\n");
158:                m_out.print("    }\n");
159:
160:                //
161:                // Gets Method
162:                //
163:
164:                signaturBuf = new StringBuilder();
165:                signaturBuf.append("    public java.util.ArrayList<"
166:                        + parameters[0].getType() + "> get" + name + "s()\n");
167:                m_out.print(signaturBuf.toString());
168:                m_out.print("    {\n");
169:                m_out.print("        return this." + name + "List;\n");
170:                m_out.print("    }\n");
171:            }
172:
173:            public void beginClass(String sourcePath, String className)
174:                    throws GeneratorException {
175:                m_file = Helper.classToFileName(className) + BEAN_NAME_SUFFIX
176:                        + ".java";
177:                System.out.println("   BEGIN - Generating bean for: " + m_file);
178:
179:                try {
180:                    String fileName = sourcePath + "/" + m_file;
181:                    m_out = new PrintWriter(fileName);
182:                } catch (IOException e) {
183:                    throw new GeneratorException(e);
184:                }
185:
186:                try {
187:                    Class interfaceType = Class.forName(className);
188:                    m_myoodbImplClass = Class.forName(className
189:                            + IMPL_NAME_SUFFIX);
190:                    m_sortedMethods = MethodHelper.getMethods(
191:                            m_myoodbImplClass, interfaceType);
192:                } catch (ClassNotFoundException e) {
193:                    throw new GeneratorException(e);
194:                }
195:
196:                makePackage(className);
197:                makeInhertance(className);
198:                makeConstructor(className);
199:            }
200:
201:            public void makeMethod(String name, int accessLevel)
202:                    throws GeneratorException {
203:                for (int methodIndex = 0; methodIndex < m_sortedMethods.length; methodIndex++) {
204:                    Method method = m_sortedMethods[methodIndex];
205:
206:                    if (method.getName().equals(name) == false) {
207:                        continue;
208:                    }
209:
210:                    Method getMethod = MethodHelper.getAssociatedBeanGetMethod(
211:                            method, m_sortedMethods);
212:
213:                    if (getMethod != null) {
214:                        makeJavaBeanSetGetProperty(name.substring(3), method,
215:                                getMethod);
216:                        continue;
217:                    }
218:
219:                    Method getsMethod = MethodHelper
220:                            .getAssociatedBeanGetsMethod(method,
221:                                    m_sortedMethods);
222:                    Method removeMethod = MethodHelper
223:                            .getAssociatedBeanRemoveMethod(method,
224:                                    m_sortedMethods);
225:
226:                    if ((getsMethod != null) && (removeMethod != null)) {
227:                        makeJavaBeanAddRemoveGetsProperty(name.substring(3),
228:                                method);
229:                    }
230:                }
231:            }
232:
233:            public void endClass() throws GeneratorException {
234:                m_out.print("}\n");
235:                m_out.close();
236:
237:                System.out.println("   END - Generating bean for: " + m_file);
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.