Source Code Cross Referenced for JavaFile.java in  » XML-UI » JAXX » jaxx » compiler » 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 » XML UI » JAXX » jaxx.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Ethan Nicholas. All rights reserved.
003:         * Use is subject to license terms.
004:         */
005:        package jaxx.compiler;
006:
007:        import java.lang.reflect.*;
008:        import java.util.*;
009:
010:        /** A Java source file being generated for output.  Once the class is completely initialized, use the 
011:         * {@link #toString} method to generate source code for it.
012:         */
013:        public class JavaFile {
014:            private int modifiers;
015:            private String className;
016:            private List/*<String>*/imports = new ArrayList/*<String>*/();
017:            private List/*<JavaField>*/fields = new ArrayList/*<JavaField>*/();
018:            private List/*<JavaMethod>*/methods = new ArrayList/*<JavaMethod>*/();
019:            private List/*<JavaFile>*/innerClasses = new ArrayList/*<JavaFile>*/();
020:            private String super Class;
021:            private String[] interfaces;
022:            private StringBuffer rawBodyCode = new StringBuffer();
023:
024:            public JavaFile() {
025:            }
026:
027:            public JavaFile(int modifiers, String className, String super Class) {
028:                this (modifiers, className, super Class, null);
029:            }
030:
031:            public JavaFile(int modifiers, String className, String super Class,
032:                    String[] interfaces) {
033:                this .modifiers = modifiers;
034:                this .className = className;
035:                this .super Class = super Class;
036:                this .interfaces = interfaces;
037:            }
038:
039:            public void addImport(String importString) {
040:                imports.add(importString);
041:            }
042:
043:            public String[] getImports() {
044:                return (String[]) imports.toArray(new String[imports.size()]);
045:            }
046:
047:            public int getModifiers() {
048:                return modifiers;
049:            }
050:
051:            public void setModifiers(int modifiers) {
052:                this .modifiers = modifiers;
053:            }
054:
055:            public String getClassName() {
056:                return className;
057:            }
058:
059:            public void setClassName(String className) {
060:                this .className = className;
061:            }
062:
063:            public String getSuperClass() {
064:                return super Class;
065:            }
066:
067:            public void setSuperClass(String super Class) {
068:                this .super Class = super Class;
069:            }
070:
071:            public String[] getInterfaces() {
072:                return interfaces;
073:            }
074:
075:            public void setInterfaces(String[] interfaces) {
076:                this .interfaces = interfaces;
077:            }
078:
079:            public void addMethod(JavaMethod method) {
080:                methods.add(method);
081:            }
082:
083:            public JavaMethod[] getMethods() {
084:                return (JavaMethod[]) methods.toArray(new JavaMethod[methods
085:                        .size()]);
086:            }
087:
088:            public void addField(JavaField field) {
089:                fields.add(field);
090:            }
091:
092:            public JavaField[] getFields() {
093:                return (JavaField[]) fields
094:                        .toArray(new JavaField[fields.size()]);
095:            }
096:
097:            public static String addIndentation(String source, int indentation) {
098:                return indent(source, indentation, false);
099:            }
100:
101:            public static String setIndentation(String source, int indentation) {
102:                return indent(source, indentation, true);
103:            }
104:
105:            public static String indent(String source, int indentation,
106:                    boolean trim) {
107:                if (trim)
108:                    source = source.trim();
109:                char[] spaces = new char[indentation];
110:                Arrays.fill(spaces, ' ');
111:                StringBuffer result = new StringBuffer();
112:                String[] lines = source.split(System
113:                        .getProperty("line.separator")
114:                        + "|\n");
115:                for (int i = 0; i < lines.length; i++) {
116:                    if (i > 0)
117:                        result.append(JAXXCompiler.getLineSeparator());
118:                    result.append(spaces);
119:                    result.append(trim ? lines[i].trim() : lines[i]);
120:                }
121:                return result.toString();
122:            }
123:
124:            public void addBodyCode(String bodyCode) {
125:                rawBodyCode.append(bodyCode);
126:            }
127:
128:            public String getClassBody() {
129:                StringBuffer result = new StringBuffer();
130:                if (fields.size() > 0) {
131:                    Iterator/*<JavaField>*/fieldIterator = fields.iterator();
132:                    while (fieldIterator.hasNext()) {
133:                        result.append(addIndentation(fieldIterator.next()
134:                                .toString(), 4));
135:                        result.append(JAXXCompiler.getLineSeparator());
136:                    }
137:
138:                    result.append(JAXXCompiler.getLineSeparator());
139:                }
140:
141:                if (rawBodyCode.length() > 0) {
142:                    result.append("    /* begin raw body code */");
143:                    result.append(rawBodyCode);
144:                    result.append("    /* end raw body code */");
145:                }
146:
147:                Iterator/*<JavaFile>*/innerClassIterator = innerClasses
148:                        .iterator();
149:                while (innerClassIterator.hasNext()) {
150:                    result.append(addIndentation(innerClassIterator.next()
151:                            .toString(), 4));
152:                    result.append(JAXXCompiler.getLineSeparator());
153:                    result.append(JAXXCompiler.getLineSeparator());
154:                }
155:
156:                Iterator/*<JavaMethod>*/methodIterator = methods.iterator();
157:                while (methodIterator.hasNext()) {
158:                    result.append(addIndentation(methodIterator.next()
159:                            .toString(), 4));
160:                    result.append(JAXXCompiler.getLineSeparator());
161:                    result.append(JAXXCompiler.getLineSeparator());
162:                }
163:
164:                return result.toString();
165:            }
166:
167:            public String getClassDefinition() {
168:                StringBuffer result = new StringBuffer();
169:                result.append(getModifiersText(modifiers));
170:                result.append("class ");
171:                result.append(className
172:                        .substring(className.lastIndexOf(".") + 1));
173:                result.append(" extends ");
174:                result.append(super Class);
175:                if (interfaces != null && interfaces.length > 0) {
176:                    result.append(" implements ");
177:                    for (int i = 0; i < interfaces.length; i++) {
178:                        if (i > 0)
179:                            result.append(", ");
180:                        result.append(interfaces[i]);
181:                    }
182:                }
183:                result.append(" {");
184:                result.append(JAXXCompiler.getLineSeparator());
185:                result.append(getClassBody());
186:                result.append("}");
187:                return result.toString();
188:            }
189:
190:            public static String getModifiersText(int modifiers) {
191:                if (modifiers == 0)
192:                    return "";
193:                else
194:                    return Modifier.toString(modifiers) + ' ';
195:            }
196:
197:            /** Returns the Java source code for this class. 
198:             *
199:             *@return a complete Java file for this class
200:             */
201:            public String toString() {
202:                StringBuffer result = new StringBuffer();
203:                if (className.indexOf(".") != -1) {
204:                    result.append("package "
205:                            + className
206:                                    .substring(0, className.lastIndexOf("."))
207:                            + ";");
208:                    result.append(JAXXCompiler.getLineSeparator());
209:                    result.append(JAXXCompiler.getLineSeparator());
210:                }
211:
212:                if (imports.size() > 0) {
213:                    Iterator/*<String>*/importIterator = imports.iterator();
214:                    while (importIterator.hasNext()) {
215:                        result.append("import ");
216:                        result.append(importIterator.next());
217:                        result.append(';');
218:                        result.append(JAXXCompiler.getLineSeparator());
219:                    }
220:                    result.append(JAXXCompiler.getLineSeparator());
221:                }
222:
223:                result.append(getClassDefinition());
224:                return result.toString();
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.