01: /*
02: * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25: package com.sun.tools.jdi;
26:
27: import com.sun.jdi.VirtualMachine;
28: import com.sun.jdi.connect.*;
29: import com.sun.jdi.connect.spi.*;
30: import java.util.Map;
31: import java.util.HashMap;
32: import java.io.IOException;
33: import java.net.InetAddress;
34: import java.net.UnknownHostException;
35:
36: /*
37: * An AttachingConnector that uses the SocketTransportService
38: */
39: public class SocketAttachingConnector extends GenericAttachingConnector {
40:
41: static final String ARG_PORT = "port";
42: static final String ARG_HOST = "hostname";
43:
44: public SocketAttachingConnector() {
45: super (new SocketTransportService());
46:
47: String defaultHostName;
48: try {
49: defaultHostName = InetAddress.getLocalHost().getHostName();
50: } catch (UnknownHostException e) {
51: defaultHostName = "";
52: }
53:
54: addStringArgument(ARG_HOST,
55: getString("socket_attaching.host.label"),
56: getString("socket_attaching.host"), defaultHostName,
57: false);
58:
59: addIntegerArgument(ARG_PORT,
60: getString("socket_attaching.port.label"),
61: getString("socket_attaching.port"), "", true, 0,
62: Integer.MAX_VALUE);
63:
64: transport = new Transport() {
65: public String name() {
66: return "dt_socket"; // for compatability reasons
67: }
68: };
69:
70: }
71:
72: /*
73: * Create an "address" from the hostname and port connector
74: * arguments and attach to the target VM.
75: */
76: public VirtualMachine attach(
77: Map<String, ? extends Connector.Argument> arguments)
78: throws IOException, IllegalConnectorArgumentsException {
79: String host = argument(ARG_HOST, arguments).value();
80: if (host.length() > 0) {
81: host = host + ":";
82: }
83: String address = host + argument(ARG_PORT, arguments).value();
84: return super .attach(address, arguments);
85: }
86:
87: public String name() {
88: return "com.sun.jdi.SocketAttach";
89: }
90:
91: public String description() {
92: return getString("socket_attaching.description");
93: }
94: }
|