Source Code Cross Referenced for TakeCompilerWizard.java in  » Rule-Engine » take » nz » ac » massey » take » takeep » actionsSets » wizards » 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 » Rule Engine » take » nz.ac.massey.take.takeep.actionsSets.wizards 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package nz.ac.massey.take.takeep.actionsSets.wizards;
002:
003:        import java.io.File;
004:        import java.io.FileOutputStream;
005:        import java.io.FileReader;
006:        import java.io.FileWriter;
007:        import java.io.InputStream;
008:        import java.io.OutputStream;
009:        import java.io.Reader;
010:        import java.io.StringReader;
011:        import java.net.URL;
012:
013:        import javax.script.ScriptException;
014:
015:        import nz.ac.massey.take.takeep.Activator;
016:        import nz.ac.massey.take.takeep.actionsSets.panels.TakeCompileWizardPanel;
017:        import nz.ac.massey.take.takeep.editor.TakeEditor;
018:        import nz.org.take.TakeException;
019:        import nz.org.take.compiler.CompilerException;
020:        import nz.org.take.compiler.NameGenerator;
021:        import nz.org.take.compiler.reference.DefaultCompiler;
022:        import nz.org.take.compiler.util.DefaultLocation;
023:        import nz.org.take.compiler.util.DefaultNameGenerator;
024:        import nz.org.take.compiler.util.jalopy.JalopyCodeFormatter;
025:        import nz.org.take.nscript.ScriptKnowledgeSource;
026:
027:        import org.apache.log4j.Appender;
028:        import org.apache.log4j.BasicConfigurator;
029:        import org.apache.log4j.Layout;
030:        import org.apache.log4j.spi.ErrorHandler;
031:        import org.apache.log4j.spi.Filter;
032:        import org.apache.log4j.spi.LoggingEvent;
033:        import org.eclipse.core.resources.IFolder;
034:        import org.eclipse.core.resources.IProject;
035:        import org.eclipse.core.resources.IResource;
036:        import org.eclipse.core.runtime.CoreException;
037:        import org.eclipse.core.runtime.IProgressMonitor;
038:        import org.eclipse.core.runtime.IStatus;
039:        import org.eclipse.core.runtime.NullProgressMonitor;
040:        import org.eclipse.core.runtime.Status;
041:        import org.eclipse.core.runtime.jobs.Job;
042:        import org.eclipse.jdt.core.JavaCore;
043:        import org.eclipse.jface.text.IDocument;
044:        import org.eclipse.jface.wizard.Wizard;
045:        import org.eclipse.ui.IEditorInput;
046:        import org.eclipse.ui.IWorkbenchPage;
047:        import org.eclipse.ui.console.ConsolePlugin;
048:        import org.eclipse.ui.console.IConsole;
049:        import org.eclipse.ui.console.IConsoleManager;
050:        import org.eclipse.ui.console.MessageConsole;
051:        import org.eclipse.ui.console.MessageConsoleStream;
052:        import org.eclipse.ui.part.FileEditorInput;
053:
054:        public class TakeCompilerWizard extends Wizard {
055:
056:            private static final String TAKE_RT_1_5_JAR = "take-rt-1.5.jar";
057:
058:            private TakeCompileWizardPanel wp;
059:
060:            private boolean interfaces = false;
061:
062:            public TakeCompilerWizard() {
063:                super ();
064:                this .setWindowTitle("Take Compiler Wizard");
065:                this .setNeedsProgressMonitor(false);
066:                this .wp = createWizardPage();
067:                this .addPage(this .wp);
068:            }
069:
070:            public TakeCompilerWizard(boolean interfaces) {
071:                this ();
072:                this .interfaces = interfaces;
073:            }
074:
075:            private TakeCompileWizardPanel createWizardPage() {
076:                TakeCompileWizardPanel wp = new TakeCompileWizardPanel(
077:                        "TakeWizard");
078:                wp.setPageComplete(true);
079:                return wp;
080:            }
081:
082:            @Override
083:            public boolean performFinish() {
084:
085:                IWorkbenchPage workbench = TakeCompileWizardPanel
086:                        .getWorkbench();
087:                final IProject project = TakeCompileWizardPanel
088:                        .getProjectFromWorkbench(workbench);
089:
090:                ClassLoader cl = TakeEditor.getProjectClassLoader(JavaCore
091:                        .create(project));
092:
093:                DefaultLocation location = new DefaultLocation();
094:
095:                NameGenerator nameGenerator = new DefaultNameGenerator();
096:                final nz.org.take.compiler.Compiler compiler = new DefaultCompiler();
097:
098:                if (this .wp.isSourceTransform()) {
099:                    compiler.add(new JalopyCodeFormatter());
100:                }
101:                compiler.setAutoAnnotate(this .wp.isAutoAnotate());
102:
103:                compiler.setNameGenerator(nameGenerator);
104:                final IEditorInput editorInput = workbench.getActiveEditor()
105:                        .getEditorInput();
106:                IDocument document = ((TakeEditor) workbench.getActiveEditor())
107:                        .getDocumentProvider().getDocument(editorInput);
108:                final MessageConsole mc = findConsole(editorInput.getName());
109:
110:                final MessageConsoleStream out = mc.newMessageStream();
111:
112:                Reader script;
113:
114:                script = new StringReader(document.get());
115:
116:                final ScriptKnowledgeSource ksource = new ScriptKnowledgeSource(
117:                        script);
118:                ksource.setClassLoader(cl);
119:                compiler.setLocation(location);
120:
121:                location.setSrcFolder(((FileEditorInput) editorInput).getFile()
122:                        .getProject().getFolder(
123:                                this .wp.getSourceOutputLocation())
124:                        .getLocation().toString());
125:
126:                compiler.setLocation(location);
127:                compiler
128:                        .setImportStatements(this .wp.getImportStatements()
129:                                .toArray(
130:                                        new String[this .wp
131:                                                .getImportStatements().size()]));
132:                compiler.setInterfaceNames(this .wp.getAdditionalInterfaces()
133:                        .toArray(
134:                                new String[this .wp.getAdditionalInterfaces()
135:                                        .size()]));
136:
137:                compiler.setPackageName(this .wp.getPackageName());
138:                compiler.setClassName(this .wp.getClassName());
139:
140:                Job compileJob = new Job("Take Compile "
141:                        + editorInput.getName()) {
142:
143:                    @Override
144:                    protected IStatus run(IProgressMonitor monitor) {
145:                        try {
146:                            if (!interfaces) {
147:                                compiler.compile(ksource.getKnowledgeBase());
148:                            } else {
149:                                compiler.compileInterface(ksource
150:                                        .getKnowledgeBase());
151:                            }
152:                            if (wp.isIncludeTakeLibrary()) {
153:                                URL url = Activator.getDefault().getBundle()
154:                                        .getEntry(TAKE_RT_1_5_JAR);
155:                                IFolder folder = ((FileEditorInput) editorInput)
156:                                        .getFile()
157:                                        .getProject()
158:                                        .getFolder(
159:                                                wp
160:                                                        .getIncludeTakeLibraryLocation());
161:                                if (!folder.exists())
162:                                    folder.create(false, true,
163:                                            new NullProgressMonitor());
164:                                File newLib = new File((folder.getLocation()
165:                                        .toString()), TAKE_RT_1_5_JAR);
166:                                newLib.createNewFile();
167:
168:                                InputStream in = url.openStream();
169:                                OutputStream out = new FileOutputStream(newLib);
170:
171:                                byte[] buf = new byte[1024];
172:                                int len;
173:                                while ((len = in.read(buf)) > 0) {
174:                                    out.write(buf, 0, len);
175:                                }
176:
177:                                in.close();
178:                                out.close();
179:
180:                            }
181:                            out.println("Successfully compiled "
182:                                    + editorInput.getName() + " to "
183:                                    + wp.getSourceOutputLocation() + "/"
184:                                    + wp.getPackageName());
185:                            mc.activate();
186:                            project.refreshLocal(IResource.DEPTH_INFINITE,
187:                                    new NullProgressMonitor());
188:                            return Status.OK_STATUS;
189:
190:                        } catch (Exception e) {
191:                            out.println("Failed Compiling");
192:                            out.println(e.getMessage());
193:                            mc.activate();
194:                            e.printStackTrace();
195:                            return Status.CANCEL_STATUS;
196:                        }
197:                    }
198:
199:                };
200:                compileJob.schedule();
201:
202:                return true;
203:            }
204:
205:            public static MessageConsole findConsole(String name) {
206:
207:                ConsolePlugin plugin = ConsolePlugin.getDefault();
208:                IConsoleManager conMan = plugin.getConsoleManager();
209:                IConsole[] existing = conMan.getConsoles();
210:                for (int i = 0; i < existing.length; i++) {
211:                    System.out.println(name);
212:                    if (name.equals(existing[i].getName())) {
213:                        return (MessageConsole) existing[i];
214:                    }
215:                }
216:                //no console found, so create a new one
217:                MessageConsole myConsole = new MessageConsole(name, null);
218:                conMan.addConsoles(new IConsole[] { myConsole });
219:                return myConsole;
220:            }
221:
222:            public TakeCompileWizardPanel getWp() {
223:                return this.wp;
224:            }
225:
226:        }
w__w___w___.j___a_v___a__2__s.__c___om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.