1 19 20 package org.netbeans.modules.debugger.jpda; 21 22 import java.util.HashSet ; 23 import java.util.Map ; 24 import org.netbeans.api.debugger.DebuggerManager; 25 import org.netbeans.api.debugger.Session; 26 import org.netbeans.api.debugger.jpda.JPDADebugger; 27 import org.netbeans.api.debugger.jpda.LaunchingDICookie; 28 import org.netbeans.spi.debugger.SessionProvider; 29 import org.netbeans.spi.debugger.ContextProvider; 30 import org.openide.util.NbBundle; 31 32 33 37 public class LaunchingSessionProvider extends SessionProvider { 38 39 private ContextProvider contextProvider; 40 private LaunchingDICookie launchingCookie; 41 42 public LaunchingSessionProvider (ContextProvider contextProvider) { 43 this.contextProvider = contextProvider; 44 launchingCookie = (LaunchingDICookie) contextProvider.lookupFirst 45 (null, LaunchingDICookie.class); 46 }; 47 48 public String getSessionName () { 49 Map arguments = (Map ) contextProvider.lookupFirst 50 (null, Map .class); 51 if (arguments != null) { 52 String processName = (String ) arguments.get ("name"); 53 if (processName != null) 54 return findUnique (processName); 55 } 56 String sessionName = launchingCookie.getClassName (); 57 int i = sessionName.lastIndexOf ('.'); 58 if (i >= 0) 59 sessionName = sessionName.substring (i + 1); 60 return findUnique (sessionName); 61 }; 62 63 public String getLocationName () { 64 return NbBundle.getMessage 65 (LaunchingSessionProvider.class, "CTL_Localhost"); 66 } 67 68 public String getTypeID () { 69 return JPDADebugger.SESSION_ID; 70 } 71 72 public Object [] getServices () { 73 return new Object [0]; 74 } 75 76 static String findUnique (String sessionName) { 77 DebuggerManager cd = DebuggerManager.getDebuggerManager (); 78 Session[] ds = cd.getSessions (); 79 80 int i, k = ds.length; 82 HashSet <Integer > m = new HashSet <Integer >(); 83 for (i = 0; i < k; i++) { 84 String pn = ds [i].getName (); 85 if (!pn.startsWith (sessionName)) continue; 86 if (pn.equals (sessionName)) { 87 m.add (new Integer (0)); 88 continue; 89 } 90 91 try { 92 int t = Integer.parseInt (pn.substring (sessionName.length ())); 93 m.add (new Integer (t)); 94 } catch (Exception e) { 95 } 96 } 97 98 k = m.size (); 100 for (i = 0; i < k; i++) 101 if (!m.contains (new Integer (i))) 102 break; 103 if (i > 0) sessionName = sessionName + i; 104 return sessionName; 105 }; 106 } 107 108 | Popular Tags |