1 19 20 package com.sslexplorer.agent.client; 21 22 import java.io.IOException ; 23 24 import com.maverick.multiplex.Request; 25 import com.maverick.util.ByteArrayReader; 26 import com.maverick.util.ByteArrayWriter; 27 28 public abstract class AbstractResourceManager { 29 30 static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(AbstractResourceManager.class); 32 34 36 protected Agent agent; 37 38 public AbstractResourceManager(Agent agent) { 39 this.agent = agent; 40 } 41 42 public Agent getAgent() { 43 return agent; 44 } 45 46 public void getResources(int resourceType, String menu) { 47 try { 48 ByteArrayWriter baw = new ByteArrayWriter(); 49 baw.writeInt(resourceType); 50 Request request = new Request("getResources@3sp.com", baw.toByteArray()); 51 if (agent.getConnection().sendRequest(request, true)) { 52 if(request.getRequestData()!=null) { 53 if(agent.getGUI().isMenuExists(menu)) 54 agent.getGUI().clearMenu(menu); 55 else 56 agent.getGUI().addMenu(menu); 57 ByteArrayReader reader = new ByteArrayReader(request.getRequestData()); 58 int count = (int) reader.readInt(); 59 if (count > 0) { 60 for (int i = 0; i < count; i++) { 61 int resourceId = (int) reader.readInt(); 62 agent.getGUI().addMenuItem(menu, new ResourceLaunchAction(resourceId, reader.readString())); 63 } 64 } 65 } 66 } 67 } catch (IOException e) { 68 log.error("Failed to get resources.", e); 70 } 72 } 73 74 public abstract void launchResource(int resourceId); 75 76 class ResourceLaunchAction implements AgentAction { 77 78 int resourceId; 79 String displayName; 80 81 ResourceLaunchAction(int resourceId, String displayName) { 82 this.resourceId = resourceId; 83 this.displayName = displayName; 84 } 85 86 public void actionPerformed() { 87 88 Thread t = new Thread () { 89 public void run() { 90 launchResource(resourceId); 91 } 92 }; 93 t.start(); 94 } 95 96 public String getAction() { 97 return displayName; 98 } 99 100 } 101 } 102 | Popular Tags |