KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > JavaRemoteApplicationLaunchConfigurationDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.launching;
12
13
14 import com.ibm.icu.text.MessageFormat;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20 import org.eclipse.debug.core.ILaunch;
21 import org.eclipse.debug.core.ILaunchConfiguration;
22 import org.eclipse.debug.core.model.IDebugTarget;
23 import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
24 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
25 import org.eclipse.jdt.launching.IVMConnector;
26 import org.eclipse.jdt.launching.JavaRuntime;
27
28 /**
29  * Launch configuration delegate for a remote Java application.
30  */

31 public class JavaRemoteApplicationLaunchConfigurationDelegate extends AbstractJavaLaunchConfigurationDelegate {
32
33     /* (non-Javadoc)
34      * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
35      */

36     public void launch(ILaunchConfiguration configuration, String JavaDoc mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
37
38         if (monitor == null) {
39             monitor = new NullProgressMonitor();
40         }
41
42         monitor.beginTask(MessageFormat.format(LaunchingMessages.JavaRemoteApplicationLaunchConfigurationDelegate_Attaching_to__0_____1, new String JavaDoc[]{configuration.getName()}), 3);
43         // check for cancellation
44
if (monitor.isCanceled()) {
45             return;
46         }
47                     
48         monitor.subTask(LaunchingMessages.JavaRemoteApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1);
49                         
50         String JavaDoc connectorId = getVMConnectorId(configuration);
51         IVMConnector connector = null;
52         if (connectorId == null) {
53             connector = JavaRuntime.getDefaultVMConnector();
54         } else {
55             connector = JavaRuntime.getVMConnector(connectorId);
56         }
57         if (connector == null) {
58             abort(LaunchingMessages.JavaRemoteApplicationLaunchConfigurationDelegate_Connector_not_specified_2, null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE);
59         }
60         
61         Map JavaDoc argMap = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map JavaDoc)null);
62         
63         int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
64         argMap.put("timeout", ""+connectTimeout); //$NON-NLS-1$//$NON-NLS-2$
65

66         // check for cancellation
67
if (monitor.isCanceled()) {
68             return;
69         }
70         
71         monitor.worked(1);
72         
73         monitor.subTask(LaunchingMessages.JavaRemoteApplicationLaunchConfigurationDelegate_Creating_source_locator____2);
74         // set the default source locator if required
75
setDefaultSourceLocator(launch, configuration);
76         monitor.worked(1);
77         
78         // connect to remote VM
79
connector.connect(argMap, monitor, launch);
80         
81         // check for cancellation
82
if (monitor.isCanceled()) {
83             IDebugTarget[] debugTargets = launch.getDebugTargets();
84             for (int i = 0; i < debugTargets.length; i++) {
85                 IDebugTarget target = debugTargets[i];
86                 if (target.canDisconnect()) {
87                     target.disconnect();
88                 }
89             }
90             return;
91         }
92         
93         monitor.done();
94     }
95     
96 }
97
Popular Tags