Source Code Cross Referenced for Jsr199JavaCompiler.java in  » Library » apache-common-JCI » org » apache » commons » jci » compilers » 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 » Library » apache common JCI » org.apache.commons.jci.compilers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.jci.compilers;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.OutputStream;
022:        import java.io.Reader;
023:        import java.io.Writer;
024:        import java.net.URI;
025:        import java.util.ArrayList;
026:        import java.util.Collection;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Set;
030:
031:        import javax.tools.Diagnostic;
032:        import javax.tools.DiagnosticCollector;
033:        import javax.tools.FileObject;
034:        import javax.tools.JavaCompilerTool;
035:        import javax.tools.JavaFileManager;
036:        import javax.tools.JavaFileObject;
037:        import javax.tools.SimpleJavaFileObject;
038:        import javax.tools.ToolProvider;
039:        import javax.tools.JavaFileObject.Kind;
040:
041:        import org.apache.commons.jci.problems.CompilationProblem;
042:        import org.apache.commons.jci.readers.ResourceReader;
043:        import org.apache.commons.jci.stores.ResourceStore;
044:        import org.apache.commons.lang.ArrayUtils;
045:        import org.apache.commons.logging.Log;
046:        import org.apache.commons.logging.LogFactory;
047:
048:        public final class Jsr199JavaCompiler extends AbstractJavaCompiler {
049:
050:            private final Log log = LogFactory.getLog(Jsr199JavaCompiler.class);
051:
052:            private class CompilationUnit extends SimpleJavaFileObject {
053:                final private ResourceReader reader;
054:                final private String name;
055:
056:                public CompilationUnit(final String pName,
057:                        final ResourceReader pReader) {
058:                    super (URI.create("reader:///" + pName), Kind.SOURCE);
059:                    reader = pReader;
060:                    name = pName;
061:                }
062:
063:                public boolean delete() {
064:                    log.debug("delete");
065:                    return super .delete();
066:                }
067:
068:                public CharSequence getCharContent(boolean arg0)
069:                        throws IOException {
070:                    log.debug("getCharContent of " + name);
071:                    byte[] content = reader.getBytes(name);
072:                    return new String(content);
073:                }
074:
075:                public Kind getKind() {
076:                    log.debug("getKind" + super .getKind());
077:                    return super .getKind();
078:                }
079:
080:                public long getLastModified() {
081:                    log.debug("getLastModified");
082:                    return super .getLastModified();
083:                }
084:
085:                public String getName() {
086:                    log.debug("getName " + super .getName());
087:                    return super .getName();
088:                }
089:
090:                public boolean isNameCompatible(String arg0, Kind arg1) {
091:                    log.debug("isNameCompatible " + arg0);
092:                    return super .isNameCompatible(arg0, arg1);
093:                }
094:
095:                public InputStream openInputStream() throws IOException {
096:                    log.debug("openInputStream");
097:                    return super .openInputStream();
098:                }
099:
100:                public OutputStream openOutputStream() throws IOException {
101:                    log.debug("openOutputStream");
102:                    return super .openOutputStream();
103:                }
104:
105:                public Reader openReader(boolean arg0) throws IOException {
106:                    log.debug("openReader");
107:                    return super .openReader(arg0);
108:                }
109:
110:                public Writer openWriter() throws IOException {
111:                    log.debug("openWriter");
112:                    return super .openWriter();
113:                }
114:
115:                public URI toUri() {
116:                    log.debug("toUri " + super .toUri());
117:                    return super .toUri();
118:                }
119:
120:            }
121:
122:            private class JciJavaFileManager implements  JavaFileManager {
123:                private final ResourceStore store;
124:                final Collection<JavaFileObject> units;
125:
126:                public JciJavaFileManager(
127:                        final Collection<JavaFileObject> pUnits,
128:                        final ResourceStore pStore) {
129:                    store = pStore;
130:                    units = pUnits;
131:                }
132:
133:                public void close() {
134:                    log.debug("close");
135:                }
136:
137:                public void flush() {
138:                    log.debug("flush");
139:                }
140:
141:                public ClassLoader getClassLoader(
142:                        JavaFileManager.Location location) {
143:                    log.debug("getClassLoader");
144:                    return null;
145:                }
146:
147:                public FileObject getFileForInput(
148:                        JavaFileManager.Location location, String packageName,
149:                        String relativeName) {
150:                    log.debug("getFileForInput");
151:                    return null;
152:                }
153:
154:                public FileObject getFileForOutput(
155:                        JavaFileManager.Location location, String packageName,
156:                        String relativeName, FileObject sibling) {
157:                    log.debug("getFileForOutput");
158:                    return null;
159:                }
160:
161:                public JavaFileObject getJavaFileForInput(
162:                        JavaFileManager.Location location, String className,
163:                        JavaFileObject.Kind kind) {
164:                    log.debug("getJavaFileForInput");
165:                    return null;
166:                }
167:
168:                public JavaFileObject getJavaFileForOutput(
169:                        JavaFileManager.Location location, String className,
170:                        JavaFileObject.Kind kind, FileObject sibling) {
171:                    log.debug("getJavaFileForOutput");
172:                    return null;
173:                }
174:
175:                public int isSupportedOption(String option) {
176:                    log.debug("isSupportedOption");
177:                    return 0;
178:                }
179:
180:                public boolean handleOption(String current,
181:                        Iterator<String> remaining) {
182:                    log.debug("handleOption");
183:                    return false;
184:                }
185:
186:                public boolean hasLocation(JavaFileManager.Location location) {
187:                    log.debug("hasLocation");
188:                    return false;
189:                }
190:
191:                public String inferBinaryName(
192:                        JavaFileManager.Location location, JavaFileObject file) {
193:                    log.debug("inferBinaryName " + file.getName());
194:                    return file.getName().replaceFirst(".java", ".class");
195:                }
196:
197:                public Iterable<JavaFileObject> list(
198:                        JavaFileManager.Location location, String packageName,
199:                        Set<JavaFileObject.Kind> kinds, boolean recurse) {
200:                    log.debug("list " + location + packageName + kinds
201:                            + recurse);
202:                    return units;
203:                }
204:            }
205:
206:            public CompilationResult compile(final String[] pResourcePaths,
207:                    final ResourceReader pReader, final ResourceStore pStore,
208:                    final ClassLoader classLoader) {
209:
210:                final Collection<JavaFileObject> units = new ArrayList<JavaFileObject>();
211:                for (int i = 0; i < pResourcePaths.length; i++) {
212:                    final String sourcePath = pResourcePaths[i];
213:                    log.debug("compiling " + sourcePath);
214:                    units.add(new CompilationUnit(sourcePath, pReader));
215:                }
216:
217:                final JavaCompilerTool compiler = ToolProvider
218:                        .getSystemJavaCompilerTool();
219:                //        final JavaFileManager fileManager = compiler.getStandardFileManager(diagnostics);
220:                final JavaFileManager fileManager = new JciJavaFileManager(
221:                        units, pStore);
222:                final DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
223:
224:                compiler.getTask(null, fileManager, diagnostics, null, null,
225:                        units).run();
226:
227:                try {
228:                    fileManager.close();
229:                } catch (IOException e) {
230:                    // TODO Auto-generated catch block
231:                    e.printStackTrace();
232:                }
233:
234:                final List<Diagnostic<? extends JavaFileObject>> jsrProblems = diagnostics
235:                        .getDiagnostics();
236:                final CompilationProblem[] problems = new CompilationProblem[jsrProblems
237:                        .size()];
238:                int i = 0;
239:                for (final Diagnostic<? extends JavaFileObject> jsrProblem : jsrProblems) {
240:                    problems[i++] = new Jsr199CompilationProblem(jsrProblem);
241:                }
242:
243:                return new CompilationResult(problems);
244:            }
245:
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.