Source Code Cross Referenced for EclipseJavaCompiler.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » rmi » common » 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 » Apache Harmony Java SE » org package » org.apache.harmony.rmi.common 
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:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author  Vasily Zakharov
021:         * @version $Revision: 1.1.2.2 $
022:         */package org.apache.harmony.rmi.common;
023:
024:        import java.lang.reflect.InvocationTargetException;
025:
026:        /**
027:         * This class represents an Eclipse Java Compiler
028:         * executed with a simple Java call.
029:         *
030:         * @author  Vasily Zakharov
031:         * @version $Revision: 1.1.2.2 $
032:         */
033:        public class EclipseJavaCompiler extends MethodJavaCompiler {
034:
035:            /**
036:             * Eclipse Compiler class name.
037:             */
038:            public static final String ECLIPSE_COMPILER_CLASS_NAME = "org.eclipse.jdt.internal.compiler.batch.Main"; //$NON-NLS-1$
039:
040:            /**
041:             * Eclipse Compiler method name.
042:             */
043:            protected final static String ECLIPSE_COMPILER_METHOD_NAME = "compile"; //$NON-NLS-1$
044:
045:            /**
046:             * Eclipse Compiler method signature.
047:             */
048:            protected static final Class[] ECLIPSE_COMPILER_METHOD_SIGNATURE = new Class[] { String.class };
049:
050:            /**
051:             * Name of the environment variable specifying the Eclipse location.
052:             */
053:            public static final String ECLIPSE_HOME_VARIABLE = "ECLIPSE_HOME"; //$NON-NLS-1$
054:
055:            /**
056:             * Path from {@link #ECLIPSE_HOME_VARIABLE ECLIPSE_HOME}
057:             * to {@linkplain #ECLIPSE_JAR_PATTERN Eclipse Compiler JAR}.
058:             */
059:            public static final String ECLIPSE_JAR_PATH = "plugins"; //$NON-NLS-1$
060:
061:            /**
062:             * File name pattern describing Eclipse Compiler JAR file name.
063:             */
064:            public static final String ECLIPSE_JAR_PATTERN = "^org.eclipse.jdt.core_.+\\.jar$"; //$NON-NLS-1$
065:
066:            /**
067:             * Creates instance of this class, equivalent to
068:             * {@link #EclipseJavaCompiler(ClassLoader) EclipseJavaCompiler(null)}.
069:             *
070:             * @throws  JavaCompilerException
071:             *          If error occurs while finding or loading
072:             *          the Eclipse Compiler class or method.
073:             */
074:            public EclipseJavaCompiler() throws JavaCompilerException {
075:                this (null);
076:            }
077:
078:            /**
079:             * Creates instance of this class by trying to load the
080:             * {@linkplain #ECLIPSE_COMPILER_CLASS_NAME Eclipse Compiler class}
081:             * with the specified class loader.
082:             *
083:             * If the specified class loader is <code>null</code>, tries to load
084:             * with the default class loader, and if failed, tries to load
085:             * from {@link #ECLIPSE_HOME_VARIABLE ECLIPSE_HOME} location.
086:             *
087:             * @param   classLoader
088:             *          Class loader to use to load the compiler class.
089:             *          Can be <code>null</code>.
090:             *
091:             * @throws  JavaCompilerException
092:             *          If error occurs while finding or loading
093:             *          the Eclipse Compiler class or method.
094:             */
095:            public EclipseJavaCompiler(ClassLoader classLoader)
096:                    throws JavaCompilerException {
097:                Class compilerClass = null;
098:
099:                try {
100:                    compilerClass = getClass(ECLIPSE_COMPILER_CLASS_NAME,
101:                            classLoader);
102:                } catch (JavaCompilerException e) {
103:                    if (classLoader != null) {
104:                        throw e;
105:                    }
106:                }
107:
108:                if (compilerClass == null) {
109:                    compilerClass = getClass(
110:                            ECLIPSE_COMPILER_CLASS_NAME,
111:                            getClassLoaderFromJarFile(getFileFromVariable(
112:                                    ECLIPSE_HOME_VARIABLE, ECLIPSE_JAR_PATH,
113:                                    ECLIPSE_JAR_PATTERN, "Eclipse Compiler JAR"))); //$NON-NLS-1$
114:                }
115:
116:                compilerMethod = getMethod(compilerClass,
117:                        ECLIPSE_COMPILER_METHOD_NAME,
118:                        ECLIPSE_COMPILER_METHOD_SIGNATURE);
119:            }
120:
121:            /**
122:             * {@inheritDoc}
123:             */
124:            public int compile(String commandString)
125:                    throws JavaCompilerException {
126:                try {
127:                    Object ret = compilerMethod.invoke(null,
128:                            new Object[] { commandString });
129:                    return (((Boolean) ret).booleanValue() ? 0 : -1);
130:                } catch (IllegalAccessException e) {
131:                    throw new JavaCompilerException(e);
132:                } catch (InvocationTargetException e) {
133:                    throw new JavaCompilerException(e.getCause());
134:                }
135:            }
136:
137:            /**
138:             * {@inheritDoc}
139:             */
140:            protected int run(String[] args) throws JavaCompilerException {
141:                StringBuffer buffer = new StringBuffer();
142:
143:                for (int i = 0; i < args.length; i++) {
144:                    if (i > 0) {
145:                        buffer.append(' ');
146:                    }
147:                    buffer.append(args[i]);
148:                }
149:                return compile(buffer.toString());
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.