KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > gui > Environment


1 /*
2  * @(#)Environment.java 1.12 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.gui;
36
37 import java.io.*;
38 import java.util.*;
39
40 import com.sun.jdi.*;
41 import com.sun.tools.example.debug.bdi.*;
42
43 public class Environment {
44
45     private SourceManager sourceManager;
46     private ClassManager classManager;
47     private ContextManager contextManager;
48     private MonitorListModel monitorListModel;
49     private ExecutionManager runtime;
50
51     private PrintWriter typeScript;
52
53     private boolean verbose;
54
55     public Environment() {
56     this.classManager = new ClassManager(this);
57     //### Order of the next three lines is important! (FIX THIS)
58
this.runtime = new ExecutionManager();
59     this.sourceManager = new SourceManager(this);
60     this.contextManager = new ContextManager(this);
61     this.monitorListModel = new MonitorListModel(this);
62     }
63
64     // Services used by debugging tools.
65

66     public SourceManager getSourceManager() {
67     return sourceManager;
68     }
69
70     public ClassManager getClassManager() {
71     return classManager;
72     }
73
74     public ContextManager getContextManager() {
75     return contextManager;
76     }
77
78     public MonitorListModel getMonitorListModel() {
79     return monitorListModel;
80     }
81
82     public ExecutionManager getExecutionManager() {
83     return runtime;
84     }
85
86     //### TODO:
87
//### Tools should attach/detach from environment
88
//### via a property, which should call an 'addTool'
89
//### method when set to maintain a registry of
90
//### tools for exit-time cleanup, etc. Tool
91
//### class constructors should be argument-free, so
92
//### that they may be instantiated by bean builders.
93
//### Will also need 'removeTool' in case property
94
//### value is changed.
95
//
96
// public void addTool(Tool t);
97
// public void removeTool(Tool t);
98

99      public void terminate() {
100      System.exit(0);
101      }
102
103     // public void refresh(); // notify all tools to refresh their views
104

105
106     // public void addStatusListener(StatusListener l);
107
// public void removeStatusListener(StatusListener l);
108

109     // public void addOutputListener(OutputListener l);
110
// public void removeOutputListener(OutputListener l);
111

112     public void setTypeScript(PrintWriter writer) {
113     typeScript = writer;
114     }
115
116     public void error(String JavaDoc message) {
117     if (typeScript != null) {
118         typeScript.println(message);
119     } else {
120         System.out.println(message);
121     }
122     }
123     
124     public void failure(String JavaDoc message) {
125     if (typeScript != null) {
126         typeScript.println(message);
127     } else {
128         System.out.println(message);
129     }
130     }
131
132     public void notice(String JavaDoc message) {
133     if (typeScript != null) {
134         typeScript.println(message);
135     } else {
136         System.out.println(message);
137     }
138     }
139
140     public OutputSink getOutputSink() {
141     return new OutputSink(typeScript);
142     }
143
144     public void viewSource(String JavaDoc fileName) {
145     //### HACK ###
146
//### Should use listener here.
147
com.sun.tools.example.debug.gui.GUI.srcTool.showSourceFile(fileName);
148     }
149
150     public void viewLocation(Location locn) {
151     //### HACK ###
152
//### Should use listener here.
153
//### Should we use sourceForLocation here?
154
com.sun.tools.example.debug.gui.GUI.srcTool.showSourceForLocation(locn);
155     }
156
157     //### Also in 'ContextManager'. Do we need both?
158

159     public boolean getVerboseFlag() {
160     return verbose;
161     }
162
163     public void setVerboseFlag(boolean verbose) {
164     this.verbose = verbose;
165     }
166
167 }
168
Popular Tags