KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > Ajde


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25
26 package org.aspectj.ajde;
27
28 import java.io.PrintStream JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.aspectj.ajde.internal.*;
34 import org.aspectj.ajde.ui.*;
35 import org.aspectj.asm.StructureModelManager;
36 import org.aspectj.compiler.Version;
37
38 /**
39  * Singleton class responsible for AJDE initialization, and the main point of access to
40  * Ajde functionality.
41  *
42  * @author Mik Kersten
43  */

44 public class Ajde {
45
46     private static final Ajde INSTANCE = new Ajde();
47     private static final String JavaDoc NOT_INITIALIZED_MESSAGE = "Ajde is not initialized.";
48     private static boolean isInitialized = false;
49     private BuildManager buildManager;
50     private EditorManager editorManager;
51     private StructureViewManager structureViewManager;
52     private StructureSearchManager structureSearchManager;
53     private BuildConfigManager configurationManager ;
54     private ProjectPropertiesAdapter projectProperties;
55     private TaskListManager taskListManager;
56     private IdeUIAdapter ideUIAdapter;
57     private ErrorHandler errorHandler;
58     private PrintStream JavaDoc logPrintStream = null;
59     
60     /**
61      * This class can only be constructured by itself (as a singleton) or by sub-classes.
62      */

63     protected Ajde() {
64         configurationManager = new LstBuildConfigManager();
65     }
66
67     /**
68      * This method must be called before using Ajde. A <CODE>RuntimeException</CODE> will
69      * be thrown if use is attempted before initialization.
70      */

71     public static void init(
72             EditorAdapter editorAdapter,
73             TaskListManager taskListManager,
74             BuildProgressMonitor compileProgressMonitor,
75             ProjectPropertiesAdapter projectProperties,
76             BuildOptionsAdapter buildOptionsAdapter,
77             StructureViewNodeFactory structureViewNodeFactory,
78             IdeUIAdapter ideUIAdapter,
79             ErrorHandler errorHandler) {
80         try {
81             INSTANCE.projectProperties = projectProperties;
82             INSTANCE.errorHandler = errorHandler;
83             INSTANCE.taskListManager = taskListManager;
84             INSTANCE.editorManager = new EditorManager(editorAdapter);
85             INSTANCE.buildManager = new AspectJBuildManager(
86                 taskListManager,
87                 compileProgressMonitor,
88                 buildOptionsAdapter);
89  
90             INSTANCE.buildManager.addListener(INSTANCE.BUILD_STATUS_LISTENER);
91             INSTANCE.configurationManager.addListener(INSTANCE.STRUCTURE_UPDATE_CONFIG_LISTENER);
92             INSTANCE.ideUIAdapter = ideUIAdapter;
93             
94             INSTANCE.structureSearchManager = new StructureSearchManager();
95             INSTANCE.structureViewManager = new StructureViewManager(structureViewNodeFactory);
96             
97             isInitialized = true;
98         } catch (Throwable JavaDoc t) {
99             System.err.println("AJDE ERROR: could not initialize Ajde.");
100             t.printStackTrace();
101         }
102     }
103
104     /**
105      * @return the default singleton instance of <CODE>Ajde</CODE>
106      */

107     public static Ajde getDefault() {
108         if (!isInitialized) throw new RuntimeException JavaDoc(NOT_INITIALIZED_MESSAGE);
109         return INSTANCE;
110     }
111
112     /**
113      * Set a <CODE>ConfigurationManager</CODE> to use instead of the default one.
114      */

115     public void setConfigurationManager(BuildConfigManager configurationManager) {
116         this.configurationManager = configurationManager;
117     }
118
119     public BuildManager getBuildManager() {
120         return buildManager;
121     }
122     
123     public EditorManager getEditorManager() {
124         return editorManager;
125     }
126     
127     public StructureViewManager getStructureViewManager() {
128         return structureViewManager;
129     }
130
131     public StructureSearchManager getStructureSearchManager() {
132         return structureSearchManager;
133     }
134     
135     public BuildConfigManager getConfigurationManager() {
136         return configurationManager;
137     }
138     
139     public ProjectPropertiesAdapter getProjectProperties() {
140         return projectProperties;
141     }
142     
143     public TaskListManager getTaskListManager() {
144         return taskListManager;
145     }
146
147     public IdeUIAdapter getIdeUIAdapter() {
148         return ideUIAdapter;
149     }
150
151     public void setIdeUIAdapter(IdeUIAdapter ideUIAdapter) {
152         this.ideUIAdapter = ideUIAdapter;
153     }
154     
155     public ErrorHandler getErrorHandler() {
156         return errorHandler;
157     }
158     
159     public String JavaDoc getVersion() {
160         return Version.text;
161     }
162
163     public void enableLogging(PrintStream JavaDoc logPrintStream) {
164         this.logPrintStream = logPrintStream;
165     }
166     
167     public void disableLogging() {
168         this.logPrintStream = null;
169     }
170     
171     /**
172      * The structure manager is not a part of the public API and its
173      * use should be avoided. Used <CODE>getStructureViewManager()</CODE>
174      * instead.
175      */

176     public StructureModelManager getStructureModelManager() {
177         return StructureModelManager.INSTANCE;
178     }
179     
180     public void logEvent(String JavaDoc message) {
181         if (logPrintStream != null) {
182             logPrintStream.println("<AJDE> " + message);
183         }
184     }
185
186     private final BuildConfigListener STRUCTURE_UPDATE_CONFIG_LISTENER = new BuildConfigListener() {
187         public void currConfigChanged(String JavaDoc configFilePath) {
188             if (configFilePath != null) Ajde.getDefault().getStructureModelManager().readStructureModel(configFilePath);
189         }
190         
191         public void configsListUpdated(List JavaDoc configsList) { }
192     };
193     
194     private final BuildListener BUILD_STATUS_LISTENER = new BuildListener() {
195         
196         /**
197          * Writes the default configuration file if it has been selected for compilation
198          */

199         public void compileStarted(String JavaDoc buildConfig) {
200             String JavaDoc configFilePath = projectProperties.getDefaultBuildConfigFile();
201             if (buildConfig.equals(configFilePath)) {
202                 configurationManager.writePaths(configFilePath, projectProperties.getProjectSourceFiles());
203                 logEvent("wrote default build config: " + configFilePath);
204             }
205         }
206         
207         /**
208          * The strucutre model is annotated with error messages after an unsuccessful compile.
209          */

210         public void compileFinished(String JavaDoc buildConfig, int buildTime, boolean succeeded, boolean warnings) {
211             String JavaDoc configFilePath = projectProperties.getDefaultBuildConfigFile();
212             if (!succeeded) {
213                 StructureModelManager.INSTANCE.fireModelUpdated();
214             }
215         }
216         
217         /**
218          * Ignored.
219          */

220         public void compileAborted(String JavaDoc buildConfigFile, String JavaDoc message) { }
221     };
222 }
223
224
225
Popular Tags