1 5 package ve.luz.ica.jackass.daemon; 6 7 import java.util.HashMap ; 8 import java.util.Map ; 9 import java.util.Iterator ; 10 11 import ve.luz.ica.jackass.deploy.daemon.NodeDeployer; 12 13 18 public final class SingleHostNodeDeployerManager implements NodeDeployerManager 19 { 20 private static final String NULL_ARGS = "Null Arguments"; 21 private static final NullPointerException NULL_ARGS_EXCEPTION = new NullPointerException (NULL_ARGS); 22 23 private Map nodeDeployerMap; 25 28 public SingleHostNodeDeployerManager() 29 { 30 nodeDeployerMap = new HashMap (); 31 } 32 33 36 public NodeDeployer[] getNodeDeployers(String itemName) 37 { 38 NodeDeployer nd = getNodeDeployer(itemName); 39 return new NodeDeployer[] {nd}; 40 } 41 42 45 public void addNodeDeployer(String itemName, NodeDeployer nodeDeployer) 46 { 47 if (itemName == null || nodeDeployer == null) 48 { 49 throw NULL_ARGS_EXCEPTION; 50 } 51 52 nodeDeployerMap.put(itemName, nodeDeployer); 53 } 54 55 58 public void removeNodeDeployer(String itemName, NodeDeployer nodeDeployer) 59 { 60 NodeDeployer nd = getNodeDeployer(itemName); 61 if (nd.equals(nodeDeployer)) 62 { 63 nodeDeployerMap.remove(itemName); 64 } 65 } 66 67 70 public void removeNodeDeployer(NodeDeployer nodeDeployer) 71 { 72 for (Iterator i = nodeDeployerMap.values().iterator(); i.hasNext();) 73 { 74 NodeDeployer nd = (NodeDeployer) i.next(); 75 if (nd.equals(nodeDeployer)) 76 { 77 i.remove(); 78 } 79 } 80 } 81 82 85 public void removeItem(String itemName) 86 { 87 nodeDeployerMap.remove(itemName); 88 } 89 90 94 public void removeNodeDeployer(String itemName) 95 { 96 if (itemName == null) 97 { 98 throw NULL_ARGS_EXCEPTION; 99 } 100 101 nodeDeployerMap.remove(itemName); 102 } 103 104 109 private NodeDeployer getNodeDeployer(String itemName) 110 { 111 if (itemName == null) 112 { 113 throw NULL_ARGS_EXCEPTION; 114 } 115 NodeDeployer nodeDeployer = (NodeDeployer) nodeDeployerMap.get(itemName); 116 if (nodeDeployer == null) 117 { 118 return null; 119 } 120 return nodeDeployer; 121 } 122 } 123 | Popular Tags |