Source Code Cross Referenced for SourceCodeMerger.java in  » Database-ORM » ebean » com » avaje » util » codegen » 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 ORM » ebean » com.avaje.util.codegen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.avaje.util.codegen;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.util.Iterator;
006:
007:        import com.avaje.lib.util.Dnode;
008:
009:        public class SourceCodeMerger {
010:
011:            boolean renameSourceCode;
012:            boolean mergeSourceCode;
013:
014:            public SourceCodeMerger(GenerateConfiguration config) {
015:                String rename = config.getProperty("codegen.source.filerename",
016:                        "true");
017:                renameSourceCode = !rename.equalsIgnoreCase("false");
018:
019:                String merge = config.getProperty("codegen.source.merge",
020:                        "true");
021:                mergeSourceCode = !merge.equalsIgnoreCase("false");
022:
023:            }
024:
025:            public void mergeSource(GenerateInfo info) throws IOException {
026:                SourceCode beanSource = getBeanSource(info);
027:                if (beanSource != null && mergeSourceCode) {
028:                    info.setBeanSource(beanSource);
029:                    addAdditional(info, beanSource);
030:                }
031:            }
032:
033:            private SourceCode getBeanSource(GenerateInfo info)
034:                    throws IOException {
035:
036:                String beanFn = info.getFullFileName();
037:
038:                SourceCode beanSource = null;
039:                File beanSourceFile = new File(beanFn);
040:                if (beanSourceFile.exists()) {
041:
042:                    SourceCodeParser p = new SourceCodeParser();
043:                    beanSource = p.parse(beanSourceFile);
044:
045:                    if (renameSourceCode) {
046:                        String renameTo = beanFn + "." + info.getNowString()
047:                                + ".old";
048:                        File renameFile = new File(renameTo);
049:                        beanSourceFile.renameTo(renameFile);
050:                    }
051:                    beanSourceFile = new File(beanFn);
052:                }
053:
054:                return beanSource;
055:            }
056:
057:            private void addAdditional(GenerateInfo info, SourceCode beanSource) {
058:
059:                if (beanSource != null) {
060:                    // set information from the source so that it is kept
061:                    Dnode beanTree = info.getBeanTree();
062:                    //context.put("beansource", beanSource);
063:
064:                    // set package declaration comments
065:                    if (beanSource.getPackageComment() != null) {
066:                        beanTree.setAttribute("packagecomment", beanSource
067:                                .getPackageComment());
068:                    }
069:
070:                    // set class declaration from the source code
071:                    beanTree.setAttribute("classdeclaration", beanSource
072:                            .getClassDeclaration());
073:
074:                    if (beanSource.getClassComment() != null) {
075:                        beanTree.setAttribute("classcomment", beanSource
076:                                .getClassComment());
077:                    }
078:
079:                    // set additional properties
080:                    String addProps = getAdditionalProperties(info);
081:                    beanTree.setAttribute("additionalproperties", addProps);
082:
083:                    // set additional methods
084:                    String addMethods = getAdditionalMethods(info);
085:                    beanTree.setAttribute("additionalmethods", addMethods);
086:
087:                    // set any inner classes...
088:                    beanTree.setAttribute("innerclasscode", beanSource
089:                            .innerClassCode());
090:                }
091:            }
092:
093:            private String getAdditionalProperties(GenerateInfo info) {
094:
095:                SourceCode beanSource = info.getBeanSource();
096:                Dnode beanTree = info.getBeanTree();
097:
098:                // find additional properties..
099:                StringBuffer sb = new StringBuffer();
100:                int addPropCount = 0;
101:                Iterator sourcePropNameIt = beanSource.propertyNames();
102:                while (sourcePropNameIt.hasNext()) {
103:                    String propName = (String) sourcePropNameIt.next();
104:                    Dnode deployProp = beanTree.find("property", "name",
105:                            propName);
106:                    if (deployProp == null && !info.isDeleteProperty(propName)) {
107:                        //not deployed and not in the delete list...
108:                        String propCode = beanSource.getPropertyCode(propName);
109:                        if (addPropCount > 0) {
110:                            sb.append("\r\n");
111:                        }
112:                        sb.append(propCode);
113:                        addPropCount++;
114:                    }
115:                }
116:                if (addPropCount == 0) {
117:                    return null;
118:                }
119:                return sb.toString();
120:            }
121:
122:            private String getAdditionalMethods(GenerateInfo info) {
123:
124:                SourceCode beanSource = info.getBeanSource();
125:
126:                // find additional properties..
127:                StringBuffer sb = new StringBuffer();
128:                int addCount = 0;
129:
130:                Iterator methodNameIt = beanSource.methodNames();
131:
132:                while (methodNameIt.hasNext()) {
133:                    String methodName = (String) methodNameIt.next();
134:                    if (!info.isDeployedMethod(methodName)) {
135:                        // it is not a known getter or setter
136:
137:                        if (!info.isDeleteMethod(methodName)) {
138:                            // it is not in known delete list..
139:                            String methodCode = beanSource
140:                                    .getMethod(methodName);
141:                            if (addCount > 0) {
142:                                sb.append("\r\n");
143:                            }
144:                            sb.append(methodCode);
145:                            addCount++;
146:                        }
147:                    }
148:                }
149:                if (addCount == 0) {
150:                    return null;
151:                }
152:                return sb.toString();
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.