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