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.bdiclient.impl;
021:
022: import org.netbeans.modules.bpel.debugger.api.DebugException;
023: import org.netbeans.modules.bpel.debuggerbdi.rmi.api.BPELDebugger;
024: import org.netbeans.modules.bpel.debuggerbdi.rmi.api.BPELProcessInstanceRef;
025: import org.netbeans.modules.bpel.debuggerbdi.rmi.api.BPELProcessRef;
026: import org.netbeans.modules.bpel.debuggerbdi.rmi.api.DebugFrame;
027: import org.netbeans.modules.bpel.debugger.BpelDebuggerImpl;
028: import org.netbeans.modules.bpel.debuggerbdi.rmi.api.VirtualBPELEngine;
029:
030: /**
031: * This is a remote object, the BPEL service engine makes callbacks
032: * into this. The methods called are defined in the BPELDebugger interface.
033: * We receive enterFrame events for each thread entered.
034: *
035: * <p>
036: * <b>Note:</b> Javadocs for this class are adapted from the (somewhat) cryptic
037: * javadocs of the interface, thus may get evetually outdated.
038: *
039: * @author Alexander Zgursky
040: */
041: public class BDIDebugger implements BPELDebugger {
042:
043: private BpelDebuggerImpl myDebugger;
044: private VirtualBPELEngine myVirtualBpelEngine;
045:
046: /** Creates a new instance of BDIDebugger */
047: public BDIDebugger(final BpelDebuggerImpl debugger) {
048: myDebugger = debugger;
049: }
050:
051: /**
052: * BPEL Debugger Server MUST implement this method to pass the information
053: * of parent debug frame: Id, BPEL file name and target URI the
054: * <code>DebuggableEngine</code> belongs and returns its local
055: * <code>DebugFrame</code> that encapsulates the remote
056: * <code>DebugFrame</code> that will be used to inform the remote debugger
057: * client on runtime activities.
058: *
059: * <p>
060: * This method is invoked from debugger server to debugger client.
061: *
062: * @param id Id of the <code>DebugFrame</code>
063: * @param parentFrameId Id of parent debug frame
064: * @param bpelFile The name of bpel file
065: * @param uri The targetNameSpace uri
066: *
067: * @return DOCUMENT ME!
068: */
069: public DebugFrame enterFrame(final String frameId,
070: final String processInstanceId, final String parentFrameId,
071: final String bpelFile, final String uri) {
072: System.out.println("- enterFrame(" + frameId + ", "
073: + processInstanceId + ", " + parentFrameId + ", "
074: + bpelFile + ", " + uri + ")");
075:
076: return getProcessInstancesModel().frameCreated(frameId,
077: processInstanceId, parentFrameId, bpelFile, uri);
078: }
079:
080: /**
081: * Called when detached from the other end of self-initiated, both can be
082: * intentional or accidental.
083: *
084: * <p>
085: * The implementation should account for both situations, the result
086: * should be the debugger client and server are both disconnected cleanly.
087: *
088: * @return <code>true</code> if detach succeeds.
089: */
090: public boolean detach() {
091: System.out.println("- detach()");
092:
093: //TODO:change to NLS
094: myDebugger.setException(new DebugException(
095: "Target disconnected"));
096: return true;
097: }
098:
099: /**
100: * Invoked when a BPEL process is added to the BPEL engine.
101: *
102: * @param process The BPEL process reference.
103: */
104: public void processAdded(final BPELProcessRef process) {
105: System.out.println("- processAdded(" + process + ")");
106:
107: // Does nothing
108: }
109:
110: /**
111: * Invoked when a BPEL process is removed from the BPEL engine.
112: *
113: * @param process The BPEL process reference.
114: */
115: public void processRemoved(final BPELProcessRef process) {
116: System.out.println("- processRemoved(" + process + ")");
117:
118: getProcessInstancesModel().processUndeployed(process.uri());
119: }
120:
121: /**
122: * Invoked when a BPEL process instance is created.
123: *
124: * @param instance The process instance reference.
125: */
126: public void processInstanceStarted(
127: final BPELProcessInstanceRef instance) {
128: System.out
129: .println("- processInstanceStarted(" + instance + ")");
130:
131: getProcessInstancesModel().processInstanceStarted(instance);
132: }
133:
134: /**
135: * Invoked when a BPEL process instance is completed.
136: *
137: * @param instance The process instance reference.
138: */
139: public void processInstanceDied(
140: final BPELProcessInstanceRef instance) {
141: System.out.println("- processInstanceDied(" + instance + ")");
142:
143: getProcessInstancesModel().processInstanceDied(instance);
144: }
145:
146: /**
147: * Debugger server set the instance of <code>VirtualBPELEngine</code> to
148: * debugger client.
149: *
150: * @param engine The <code>VirtualBPELEngine</code> object.
151: */
152: public void setVirtualBPELEngine(final VirtualBPELEngine engine) {
153: System.out.println("- setVirtualBPELEngine("
154: + engine.toString() + ")");
155:
156: myVirtualBpelEngine = engine;
157:
158: final ProcessInstancesModelImpl model = getProcessInstancesModel();
159:
160: for (String procName : engine.allDeployedBPELs()) {
161: final BPELProcessRef processRef = engine
162: .getBPELProcess(procName);
163:
164: model.getProcess(processRef);
165:
166: for (String instName : processRef.allProcessInstanceIDs()) {
167: final BPELProcessInstanceRef instanceRef = processRef
168: .getProcessInstance(instName);
169:
170: model.processInstanceStarted(instanceRef);
171: }
172: }
173: }
174:
175: public VirtualBPELEngine getVirtualBPELEngine() {
176: return myVirtualBpelEngine;
177: }
178:
179: // Private /////////////////////////////////////////////////////////////////
180: private ProcessInstancesModelImpl getProcessInstancesModel() {
181: return myDebugger.getProcessInstancesModel();
182: }
183: }
|