001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.debugger.api;
021:
022: import java.beans.PropertyChangeListener;
023: import java.beans.PropertyChangeSupport;
024: import java.util.Properties;
025: import org.netbeans.api.debugger.DebuggerInfo;
026: import org.netbeans.api.debugger.DebuggerManager;
027: import org.netbeans.modules.bpel.debugger.api.breakpoints.LineBreakpoint;
028: import org.netbeans.spi.debugger.ContextProvider;
029:
030: /**
031: *
032: * @author Alexander Zgursky
033: */
034: public abstract class BpelDebugger {
035:
036: /** Name of property for state of debugger. */
037: public static final String PROP_STATE = "state"; // NOI18N
038:
039: /** Name of property for current process instance. */
040: public static final String PROP_CURRENT_PROCESS_INSTANCE = "currentProcessInstance"; //NOI18N
041:
042: /** Name of property for current process instance. */
043: public static final String PROP_CURRENT_PROCESS_INSTANCE_STATE = "currentProcessInstanceState"; //NOI18N
044:
045: /** Name of property for current position. */
046: public static final String PROP_CURRENT_POSITION = "currentPosition"; //NOI18N
047:
048: /** Debugger state constant. */
049: public static final int STATE_STARTING = 1;
050: /** Debugger state constant. */
051: public static final int STATE_RUNNING = 2;
052: /** Debugger state constant. */
053: public static final int STATE_DISCONNECTED = 4;
054:
055: private PropertyChangeSupport myPcs;
056: private ContextProvider myLookupProvider;
057: private Tracer mTracer;
058:
059: protected BpelDebugger(ContextProvider lookupProvider) {
060: myLookupProvider = lookupProvider;
061: myPcs = new PropertyChangeSupport(this );
062: }
063:
064: /**
065: * Returns tracer to be used for the current debug session.
066: *
067: * @return tracer to be used for the current debug session
068: */
069: public Tracer getTracer() {
070: if (mTracer == null) {
071: mTracer = TracerAccess.getTracer(getLookupProvider());
072: }
073: return mTracer;
074: }
075:
076: /**
077: * Starts BPEL debug session.
078: * @param props properties to be used to start a debug session
079: */
080: public static void start(Properties props) {
081: ProcessDICookie cookie = ProcessDICookie.create(props);
082:
083: DebuggerManager.getDebuggerManager().startDebugging(
084: DebuggerInfo.create(ProcessDICookie.ID,
085: new Object[] { cookie }));
086: }
087:
088: /**
089: * Stops the debugger and terminates the debugging session.
090: */
091: public abstract void finish();
092:
093: /**
094: * Causes current process instance to do a step into or does nothing if
095: * there's no current process instance or it's not in the suspended state.
096: */
097: public abstract void stepInto();
098:
099: /**
100: * Causes current process instance to do a step over or does nothing if
101: * there's no current process instance or it's not in the suspended state.
102: */
103: public abstract void stepOver();
104:
105: /**
106: * Causes current process instance to do a step out or does nothing if
107: * there's no current process instance or it's not in the suspended state.
108: */
109: public abstract void stepOut();
110:
111: /**
112: * Pauses the execution of the current process instance or does nothing if
113: * there's no current process instance or it's not in the suspended state.
114: */
115: public abstract void pause();
116:
117: /**
118: * Resumes the execution of the current process instance or does nothing if
119: * there's no current process instance or it's not in the suspended state.
120: */
121: public abstract void resume();
122:
123: /**
124: * Returns current state of BPEL debugger.
125: *
126: * @return current state of BPEL debugger
127: * @see #STATE_STARTING
128: * @see #STATE_RUNNING
129: * @see #STATE_DISCONNECTED
130: */
131: public abstract int getState();
132:
133: public abstract ProcessInstancesModel getProcessInstancesModel();
134:
135: /**
136: * Returns state of the current process instance.
137: *
138: * @return state of the the current process instance or
139: * {@link ProcessInstance#STATE_UNKNOWN} if there's no
140: * current instance
141: *
142: * @see ProcessInstance#STATE_UNKNOWN
143: * @see ProcessInstance#STATE_RUNNING
144: * @see ProcessInstance#STATE_SUSPENDED
145: * @see ProcessInstance#STATE_COMPLETED
146: * @see ProcessInstance#STATE_FAILED
147: * @see ProcessInstance#STATE_TERMINATED
148: */
149: public abstract int getCurrentProcessInstanceState();
150:
151: /**
152: * Returns current process instance.
153: *
154: * @return current process instance
155: * or null if there's no current process instance
156: */
157: public abstract ProcessInstance getCurrentProcessInstance();
158:
159: /**
160: * Sets the current process instance. Does nothing if given process instance
161: * doesn't exist in the model.
162: *
163: * @param processInstance process instance to set as current
164: */
165: public abstract void setCurrentProcessInstance(
166: ProcessInstance processInstance);
167:
168: /**
169: * Returns position at which current process instance has been suspended.
170: *
171: * @return current position at which current process instance has been
172: * suspended or <code>null</code> if there's no current process
173: * instance or it's not suspended
174: *
175: * @see #getCurrentProcessInstance()
176: * @see ProcessInstance#getState()
177: * @see ProcessInstance#getCurrentPosition
178: */
179: public abstract Position getCurrentPosition();
180:
181: /**
182: * Returns an exception that caused debugger to disconnect.
183: *
184: * @return an exception that caused debugger to disconnect or null if
185: * there was no exception
186: */
187: public abstract Exception getException();
188:
189: public abstract void runToCursor(LineBreakpoint breakpoint);
190:
191: /**
192: * Fires property change.
193: */
194: protected final void firePropertyChange(String name, Object o,
195: Object n) {
196: myPcs.firePropertyChange(name, o, n);
197: }
198:
199: /**
200: * Adds property change listener.
201: *
202: * @param l new listener.
203: */
204: public final void addPropertyChangeListener(PropertyChangeListener l) {
205: myPcs.addPropertyChangeListener(l);
206: }
207:
208: /**
209: * Removes property change listener.
210: *
211: * @param l removed listener.
212: */
213: public final void removePropertyChangeListener(
214: PropertyChangeListener l) {
215: myPcs.removePropertyChangeListener(l);
216: }
217:
218: /**
219: * Adds property change listener.
220: *
221: * @param propertyName property name to add listener for
222: * @param l new listener.
223: */
224: public final void addPropertyChangeListener(String propertyName,
225: PropertyChangeListener l) {
226: myPcs.addPropertyChangeListener(propertyName, l);
227: }
228:
229: /**
230: * Removes property change listener.
231: *
232: * @param propertyName property name to remove listener for
233: * @param l listener to remove
234: */
235: public final void removePropertyChangeListener(String propertyName,
236: PropertyChangeListener l) {
237: myPcs.removePropertyChangeListener(propertyName, l);
238: }
239:
240: /**
241: * Returns the context of the debugger.
242: *
243: * @return the context of the debugger
244: */
245: public final ContextProvider getLookupProvider() {
246: return myLookupProvider;
247: }
248: }
|