1 11 package org.eclipse.jdi.internal.connect; 12 13 14 import java.io.IOException ; 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.eclipse.jdi.internal.VirtualMachineManagerImpl; 21 22 import com.sun.jdi.VirtualMachine; 23 import com.sun.jdi.connect.AttachingConnector; 24 import com.sun.jdi.connect.Connector; 25 import com.sun.jdi.connect.IllegalConnectorArgumentsException; 26 import com.sun.jdi.connect.spi.Connection; 27 28 public class SocketAttachingConnectorImpl extends ConnectorImpl implements AttachingConnector { 29 30 private String fHostname; 31 32 private int fPort; 33 private int fTimeout; 34 35 38 public SocketAttachingConnectorImpl(VirtualMachineManagerImpl virtualMachineManager) { 39 super(virtualMachineManager); 40 41 SocketTransportImpl transport = new SocketTransportImpl(); 43 setTransport(transport); 44 } 45 46 49 public Map defaultArguments() { 50 HashMap arguments = new HashMap (2); 51 52 StringArgumentImpl strArg = new StringArgumentImpl("hostname", ConnectMessages.SocketAttachingConnectorImpl_Machine_name_to_which_to_attach_for_VM_connections_1, ConnectMessages.SocketAttachingConnectorImpl_Host_2, false); strArg.setValue("localhost"); arguments.put(strArg.name(), strArg); 56 57 IntegerArgumentImpl intArg = new IntegerArgumentImpl("port", ConnectMessages.SocketAttachingConnectorImpl_Port_number_to_which_to_attach_for_VM_connections_3, ConnectMessages.SocketAttachingConnectorImpl_Port_4, true, SocketTransportImpl.MIN_PORTNR, SocketTransportImpl.MAX_PORTNR); arguments.put(intArg.name(), intArg); 60 61 IntegerArgumentImpl timeoutArg = new IntegerArgumentImpl("timeout", ConnectMessages.SocketAttachingConnectorImpl_1, ConnectMessages.SocketAttachingConnectorImpl_2, false, 0, Integer.MAX_VALUE); timeoutArg.setValue(0); arguments.put(timeoutArg.name(), timeoutArg); 65 66 return arguments; 67 } 68 69 72 public String name() { 73 return "com.sun.jdi.SocketAttach"; } 75 76 79 public String description() { 80 return ConnectMessages.SocketAttachingConnectorImpl_Attaches_by_socket_to_other_VMs_5; 81 } 82 83 86 private void getConnectionArguments(Map connectionArgs) throws IllegalConnectorArgumentsException { 87 String attribute = ""; try { 89 attribute = "hostname"; fHostname = ((Connector.StringArgument)connectionArgs.get(attribute)).value(); 91 attribute = "port"; fPort = ((Connector.IntegerArgument)connectionArgs.get(attribute)).intValue(); 93 attribute = "timeout"; Object object = connectionArgs.get(attribute); 95 if (object != null) { 96 Connector.IntegerArgument timeoutArg = (IntegerArgument) object; 97 if (timeoutArg.value() != null) { 98 fTimeout = timeoutArg.intValue(); 99 } 100 } 101 } catch (ClassCastException e) { 102 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketAttachingConnectorImpl_Connection_argument_is_not_of_the_right_type_6, attribute); 103 } catch (NullPointerException e) { 104 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketAttachingConnectorImpl_Necessary_connection_argument_is_null_7, attribute); 105 } catch (NumberFormatException e) { 106 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketAttachingConnectorImpl_Connection_argument_is_not_a_number_8, attribute); 107 } 108 } 109 110 114 public VirtualMachine attach(Map connectionArgs) throws IOException , IllegalConnectorArgumentsException { 115 getConnectionArguments(connectionArgs); 116 Connection connection = null; 117 try { 118 connection = ((SocketTransportImpl)fTransport).attach(fHostname, fPort, fTimeout, 0); 119 } catch (IllegalArgumentException e) { 120 List args = new ArrayList (); 121 args.add("hostname"); args.add("port"); throw new IllegalConnectorArgumentsException(e.getMessage(), args); 124 } 125 return establishedConnection(connection); 126 } 127 } 128 | Popular Tags |