001: /*
002: * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.jdi;
027:
028: import com.sun.tools.jdi.*;
029: import com.sun.jdi.connect.*;
030: import com.sun.jdi.connect.spi.*;
031: import com.sun.jdi.VirtualMachine;
032: import java.util.Map;
033: import java.io.IOException;
034:
035: public class RawCommandLineLauncher extends AbstractLauncher implements
036: LaunchingConnector {
037:
038: static private final String ARG_COMMAND = "command";
039: static private final String ARG_ADDRESS = "address";
040: static private final String ARG_QUOTE = "quote";
041:
042: TransportService transportService;
043: Transport transport;
044:
045: public TransportService transportService() {
046: return transportService;
047: }
048:
049: public Transport transport() {
050: return transport;
051: }
052:
053: public RawCommandLineLauncher() {
054: super ();
055:
056: try {
057: Class c = Class
058: .forName("com.sun.tools.jdi.SharedMemoryTransportService");
059: transportService = (TransportService) c.newInstance();
060: transport = new Transport() {
061: public String name() {
062: return "dt_shmem";
063: }
064: };
065: } catch (ClassNotFoundException x) {
066: } catch (UnsatisfiedLinkError x) {
067: } catch (InstantiationException x) {
068: } catch (IllegalAccessException x) {
069: }
070: ;
071:
072: if (transportService == null) {
073: transportService = new SocketTransportService();
074: transport = new Transport() {
075: public String name() {
076: return "dt_socket";
077: }
078: };
079: }
080:
081: addStringArgument(ARG_COMMAND, getString("raw.command.label"),
082: getString("raw.command"), "", true);
083: addStringArgument(ARG_QUOTE, getString("raw.quote.label"),
084: getString("raw.quote"), "\"", true);
085:
086: addStringArgument(ARG_ADDRESS, getString("raw.address.label"),
087: getString("raw.address"), "", true);
088: }
089:
090: public VirtualMachine launch(
091: Map<String, ? extends Connector.Argument> arguments)
092: throws IOException, IllegalConnectorArgumentsException,
093: VMStartException {
094: String command = argument(ARG_COMMAND, arguments).value();
095: String address = argument(ARG_ADDRESS, arguments).value();
096:
097: String quote = argument(ARG_QUOTE, arguments).value();
098:
099: if (quote.length() > 1) {
100: throw new IllegalConnectorArgumentsException(
101: "Invalid length", ARG_QUOTE);
102: }
103:
104: TransportService.ListenKey listener = transportService
105: .startListening(address);
106:
107: try {
108: return launch(tokenizeCommand(command, quote.charAt(0)),
109: address, listener, transportService);
110: } finally {
111: transportService.stopListening(listener);
112: }
113: }
114:
115: public String name() {
116: return "com.sun.jdi.RawCommandLineLaunch";
117: }
118:
119: public String description() {
120: return getString("raw.description");
121: }
122: }
|