1 13 package org.eclipse.jdi.internal.connect; 14 15 16 import java.io.IOException ; 17 import java.util.List ; 18 19 import org.eclipse.jdi.Bootstrap; 20 import org.eclipse.jdi.internal.VirtualMachineImpl; 21 import org.eclipse.jdi.internal.VirtualMachineManagerImpl; 22 23 import com.sun.jdi.VirtualMachine; 24 import com.sun.jdi.connect.Connector; 25 import com.sun.jdi.connect.Transport; 26 import com.sun.jdi.connect.spi.Connection; 27 28 29 35 public abstract class ConnectorImpl implements Connector { 36 37 private VirtualMachineManagerImpl fVirtualMachineManager; 38 39 40 protected Transport fTransport; 41 42 protected VirtualMachineImpl fVirtualMachine; 43 44 47 public ConnectorImpl(VirtualMachineManagerImpl virtualMachineManager) { 48 fVirtualMachineManager = virtualMachineManager; 49 } 50 51 54 public VirtualMachineManagerImpl virtualMachineManager() { 55 return fVirtualMachineManager; 56 } 57 58 61 public VirtualMachineImpl virtualMachine() { 62 return fVirtualMachine; 63 } 64 65 68 public abstract String description(); 69 70 73 public abstract String name(); 74 75 78 void setTransport(Transport transport) { 79 fTransport = transport; 80 } 81 82 85 public Transport transport() { 86 return fTransport; 87 } 88 89 92 synchronized void close() { 93 virtualMachineManager().removeConnectedVM(fVirtualMachine); 94 } 95 96 99 protected VirtualMachine establishedConnection(Connection connection) throws IOException { 100 fVirtualMachine = (VirtualMachineImpl) Bootstrap.virtualMachineManager().createVirtualMachine(connection); 101 return fVirtualMachine; 102 } 103 104 107 public abstract class ArgumentImpl implements com.sun.jdi.connect.Connector.Argument { 108 private String fName; 109 private String fDescription; 110 private String fLabel; 111 private boolean fMustSpecify; 112 113 protected ArgumentImpl(String name, String description, String label, boolean mustSpecify) { 114 fName = name; 115 fLabel = label; 116 fDescription = description; 117 fMustSpecify = mustSpecify; 118 } 119 120 public String name() { 121 return fName; 122 } 123 124 public String description() { 125 return fDescription; 126 } 127 128 public String label() { 129 return fLabel; 130 } 131 132 public boolean mustSpecify() { 133 return fMustSpecify; 134 } 135 136 public abstract String value(); 137 public abstract void setValue(String value); 138 public abstract boolean isValid(String value); 139 public abstract String toString(); 140 } 141 142 public class StringArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.StringArgument { 143 private static final long serialVersionUID = 6009335074727417445L; 144 145 private String fValue; 146 147 protected StringArgumentImpl(String name, String description, String label, boolean mustSpecify) { 148 super(name, description, label, mustSpecify); 149 } 150 151 public String value() { 152 return fValue; 153 } 154 155 public void setValue(String value) { 156 fValue = value; 157 } 158 159 public boolean isValid(String value) { 160 return true; 161 } 162 163 public String toString() { 164 return fValue; 165 } 166 167 } 168 169 public class IntegerArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.IntegerArgument { 170 private static final long serialVersionUID = 6009335074727417445L; 171 private Integer fValue; 172 private int fMin; 173 private int fMax; 174 175 protected IntegerArgumentImpl(String name, String description, String label, boolean mustSpecify, int min, int max) { 176 super(name, description, label, mustSpecify); 177 fMin = min; 178 fMax = max; 179 } 180 181 public String value() { 182 return (fValue == null) ? null : fValue.toString(); 183 } 184 185 public void setValue(String value) { 186 fValue = new Integer (value); 187 } 188 189 public boolean isValid(String value) { 190 Integer val; 191 try { 192 val = new Integer (value); 193 } catch (NumberFormatException e) { 194 return false; 195 } 196 return isValid(val.intValue()); 197 } 198 199 public String toString() { 200 return value(); 201 } 202 203 public int intValue() { 204 return fValue.intValue(); 205 } 206 207 public void setValue(int value) { 208 fValue = new Integer (value); 209 } 210 211 public int min() { 212 return fMin; 213 } 214 215 public int max() { 216 return fMax; 217 } 218 219 public boolean isValid(int value) { 220 return fMin <= value && value <= fMax; 221 } 222 223 public String stringValueOf(int value) { 224 return new Integer (value).toString(); 225 } 226 } 227 228 public class BooleanArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.BooleanArgument { 229 private static final long serialVersionUID = 6009335074727417445L; 230 private Boolean fValue; 231 232 protected BooleanArgumentImpl(String name, String description, String label, boolean mustSpecify) { 233 super(name, description, label, mustSpecify); 234 } 235 236 public String value() { 237 return (fValue == null) ? null : fValue.toString(); 238 } 239 240 public void setValue(String value) { 241 fValue = Boolean.valueOf(value); 242 } 243 244 public boolean isValid(String value) { 245 return true; 246 } 247 248 public String toString() { 249 return value(); 250 } 251 252 public boolean booleanValue() { 253 return fValue.booleanValue(); 254 } 255 256 public void setValue(boolean value) { 257 fValue = Boolean.valueOf(value); 258 } 259 260 public String stringValueOf(boolean value) { 261 return Boolean.valueOf(value).toString(); 262 } 263 } 264 265 public class SelectedArgumentImpl extends StringArgumentImpl implements com.sun.jdi.connect.Connector.SelectedArgument { 266 private static final long serialVersionUID = 6009335074727417445L; 267 private List fChoices; 268 269 protected SelectedArgumentImpl(String name, String description, String label, boolean mustSpecify, List choices) { 270 super(name, description, label, mustSpecify); 271 fChoices = choices; 272 } 273 274 public List choices() { 275 return fChoices; 276 } 277 278 public boolean isValid(java.lang.String value) { 279 return fChoices.contains(value); 280 } 281 } 282 } 283 | Popular Tags |