blob: 756bfde7d65bed62917ccd2a12696d2d38d59070 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * 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 */
25package com.sun.tools.jdi;
26
27import com.sun.jdi.VirtualMachine;
28import com.sun.jdi.connect.*;
29import com.sun.jdi.connect.spi.*;
30import java.util.Map;
31import java.util.HashMap;
32import java.io.IOException;
33import java.net.InetAddress;
34import java.net.UnknownHostException;
35
36/*
37 * An AttachingConnector that uses the SocketTransportService
38 */
39public 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(
55 ARG_HOST,
56 getString("socket_attaching.host.label"),
57 getString("socket_attaching.host"),
58 defaultHostName,
59 false);
60
61 addIntegerArgument(
62 ARG_PORT,
63 getString("socket_attaching.port.label"),
64 getString("socket_attaching.port"),
65 "",
66 true,
67 0, Integer.MAX_VALUE);
68
69 transport = new Transport() {
70 public String name() {
71 return "dt_socket"; // for compatability reasons
72 }
73 };
74
75 }
76
77 /*
78 * Create an "address" from the hostname and port connector
79 * arguments and attach to the target VM.
80 */
81 public VirtualMachine
82 attach(Map<String,? extends Connector.Argument> arguments)
83 throws IOException, IllegalConnectorArgumentsException
84 {
85 String host = argument(ARG_HOST, arguments).value();
86 if (host.length() > 0) {
87 host = host + ":";
88 }
89 String address = host + argument(ARG_PORT, arguments).value();
90 return super.attach(address, arguments);
91 }
92
93 public String name() {
94 return "com.sun.jdi.SocketAttach";
95 }
96
97 public String description() {
98 return getString("socket_attaching.description");
99 }
100}