1 11 package org.eclipse.jdi.internal; 12 13 14 import java.io.FileOutputStream ; 15 import java.io.IOException ; 16 import java.io.InputStream ; 17 import java.io.OutputStream ; 18 import java.io.PrintWriter ; 19 import java.net.URL ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 import java.util.MissingResourceException ; 23 import java.util.PropertyResourceBundle ; 24 25 import org.eclipse.jdi.internal.connect.SocketAttachingConnectorImpl; 26 import org.eclipse.jdi.internal.connect.SocketLaunchingConnectorImpl; 27 import org.eclipse.jdi.internal.connect.SocketListeningConnectorImpl; 28 import org.eclipse.jdi.internal.connect.SocketRawLaunchingConnectorImpl; 29 import org.eclipse.jdt.debug.core.JDIDebugModel; 30 31 import com.sun.jdi.VirtualMachine; 32 import com.sun.jdi.VirtualMachineManager; 33 import com.sun.jdi.connect.LaunchingConnector; 34 import com.sun.jdi.connect.spi.Connection; 35 36 42 public class VirtualMachineManagerImpl implements VirtualMachineManager { 43 44 public static int MAJOR_INTERFACE_VERSION = 1; 45 46 public static int MINOR_INTERFACE_VERSION = 5; 47 48 private PrintWriter fVerbosePrintWriter = null; 49 50 List fConnectedVMs = new ArrayList (); 51 52 private boolean fVerbose = false; 53 54 private String fVerboseFile = null; 55 56 59 public VirtualMachineManagerImpl() { 60 61 getPreferences(); 62 63 if (fVerbose) { 65 OutputStream out; 66 if (fVerboseFile != null && fVerboseFile.length() > 0) { 67 try { 68 out = new FileOutputStream (fVerboseFile); 69 } catch (IOException e) { 70 out = System.out; 71 System.out.println(JDIMessages.VirtualMachineManagerImpl_Could_not_open_verbose_file___1 + fVerboseFile + JDIMessages.VirtualMachineManagerImpl_____2 + e); } 73 } else { 74 out = System.out; 75 } 76 fVerbosePrintWriter = new PrintWriter (out); 77 } 78 } 79 80 83 public int majorInterfaceVersion() { 84 return MAJOR_INTERFACE_VERSION; 85 } 86 87 90 public int minorInterfaceVersion() { 91 return MINOR_INTERFACE_VERSION; 92 } 93 94 97 private void getPreferences() { 98 URL url = getClass().getResource("/jdi.ini"); if (url == null) { 101 return; 102 } 103 104 try { 105 InputStream stream = url.openStream(); 106 PropertyResourceBundle prefs = new PropertyResourceBundle (stream); 107 108 try { 109 fVerbose = Boolean.valueOf(prefs.getString("User.verbose")).booleanValue(); } catch (MissingResourceException e) { 111 } 112 113 try { 114 fVerboseFile = prefs.getString("Verbose.out"); } catch (MissingResourceException e) { 116 } 117 118 } catch (IOException e) { 119 } 120 121 } 122 123 128 public int getGlobalRequestTimeout() { 129 try { 130 if (JDIDebugModel.getPreferences() != null) { 131 return JDIDebugModel.getPreferences().getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT); 132 } 133 return JDIDebugModel.DEF_REQUEST_TIMEOUT; 135 } catch (NoClassDefFoundError e) { 136 } 137 return 3000; 139 } 140 141 144 public void addConnectedVM(VirtualMachineImpl vm) { 145 fConnectedVMs.add(vm); 146 } 147 148 151 public void removeConnectedVM(VirtualMachineImpl vm) { 152 fConnectedVMs.remove(vm); 153 } 154 155 158 public List connectedVirtualMachines() { 159 return fConnectedVMs; 160 } 161 162 165 public List allConnectors() { 166 List result = new ArrayList (attachingConnectors()); 167 result.addAll(launchingConnectors()); 168 result.addAll(listeningConnectors()); 169 return result; 170 } 171 172 175 public List attachingConnectors() { 176 ArrayList list = new ArrayList (1); 177 list.add(new SocketAttachingConnectorImpl(this)); 178 return list; 179 } 180 181 184 public List launchingConnectors() { 185 ArrayList list = new ArrayList (2); 186 list.add(new SocketLaunchingConnectorImpl(this)); 187 list.add(new SocketRawLaunchingConnectorImpl(this)); 188 return list; 189 } 190 191 194 public List listeningConnectors() { 195 ArrayList list = new ArrayList (1); 196 list.add(new SocketListeningConnectorImpl(this)); 197 return list; 198 } 199 200 203 public LaunchingConnector defaultConnector() { 204 return new SocketLaunchingConnectorImpl(this); 205 } 206 207 210 public PrintWriter verbosePrintWriter() { 211 return fVerbosePrintWriter; 212 } 213 214 public VirtualMachine createVirtualMachine(Connection connection) throws IOException { 215 VirtualMachineImpl vmImpl = new VirtualMachineImpl(connection); 216 return vmImpl; 217 } 218 219 public VirtualMachine createVirtualMachine(Connection connection, Process process) throws IOException { 220 VirtualMachineImpl vmImpl = new VirtualMachineImpl(connection); 221 vmImpl.setLaunchedProcess(process); 222 return vmImpl; 223 } 224 } 225 | Popular Tags |