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.action;
021:
022: import java.util.Collections;
023: import java.util.Map;
024: import java.util.Set;
025: import org.netbeans.api.debugger.ActionsManager;
026: import org.netbeans.modules.bpel.debugger.api.BpelDebugger;
027: import org.netbeans.modules.bpel.debugger.api.DebugException;
028: import org.netbeans.modules.bpel.debugger.BpelDebuggerImpl;
029: import org.netbeans.spi.debugger.ActionsProviderSupport;
030: import org.netbeans.spi.debugger.ContextProvider;
031: import org.openide.util.RequestProcessor;
032:
033: /**
034: * Starts the debugger by attaching to a BPEL service engine.
035: */
036: public class DebugProjectActionProvider extends ActionsProviderSupport {
037:
038: protected ContextProvider mLookupProvider;
039: private BpelDebuggerImpl mDebugger;
040:
041: public DebugProjectActionProvider(ContextProvider lookupProvider) {
042: mLookupProvider = lookupProvider;
043: mDebugger = (BpelDebuggerImpl) mLookupProvider.lookupFirst(
044: null, BpelDebugger.class);
045: setEnabled(ActionsManager.ACTION_START, true);
046: }
047:
048: public Set getActions() {
049: return Collections.singleton(ActionsManager.ACTION_START);
050: }
051:
052: public void doAction(Object action) {
053: // awt version used instead - postAction
054: }
055:
056: @Override
057: public void postAction(Object action,
058: Runnable actionPerformedNotifier) {
059: final Map params = mLookupProvider.lookupFirst(null, Map.class);
060:
061: RequestProcessor.getDefault().post(new Runnable() {
062: public void run() {
063: mDebugger.setStartingThread(Thread.currentThread());
064: try {
065: Map bpelseParams = null;
066: for (Object objEntry : params.entrySet()) {
067: final Map.Entry entry = (Map.Entry) objEntry;
068: final String key = (String) entry.getKey();
069:
070: if ("sun-bpel-engine".equals(key)) {
071: bpelseParams = (Map) entry.getValue();
072: break;
073: }
074: }
075: if (bpelseParams == null) {
076: return;
077: }
078:
079: final String j2eeServerInstance = (String) params
080: .get("j2eeServerInstance");
081: final String host = getServerInstanceHost(j2eeServerInstance);
082: final Integer port = new Integer(
083: (String) bpelseParams.get("port"));
084:
085: mDebugger.setRunning(host, port);
086: } catch (Exception ex) {
087: mDebugger.setException(new DebugException(ex));
088: } finally {
089: mDebugger.unsetStartingThread();
090: }
091: }
092: });
093: if (actionPerformedNotifier != null) {
094: actionPerformedNotifier.run();
095: }
096: }
097:
098: private static String getServerInstanceHost(
099: String j2eeServerInstance) {
100: //the j2eeServerInstance has the following format:
101: //"[C:\Sun\glassfish_b32]deployer:Sun:AppServer::localhost:4848"
102: //so we can obtain a host from the string itself
103: //TODO:is there more reliable way to obtain a host?
104: int to = j2eeServerInstance.lastIndexOf(":");
105: int from = j2eeServerInstance.lastIndexOf(":", to - 1);
106: return j2eeServerInstance.substring(from + 1, to);
107: }
108: }
|