1 19 package fr.dyade.aaa.agent.conf; 20 21 import java.io.*; 22 import java.util.*; 23 24 27 public class A3CMLServer implements Serializable { 28 public short sid = -1; 29 public String name = null; 30 public String hostname = null; 31 32 public String domain = null; 33 37 public int port = -1; 38 public Hashtable nat = null; 39 public Vector networks = null; 40 public Vector services = null; 41 public String jvmArgs = null; 42 public Hashtable properties = null; 43 46 public boolean visited = false; 47 52 public short gateway = -1; 53 57 public int hops = -1; 58 59 public A3CMLServer(short sid, 60 String name, 61 String hostname) throws Exception { 62 this.sid = sid; 63 if ((name == null) || (name.length() == 0)) 64 this.name = "s#" + sid; 65 else 66 this.name = name; 67 this.hostname = hostname; 68 this.services = new Vector(); 69 this.networks = new Vector(); 70 } 71 72 public void addNetwork(A3CMLNetwork newNetwork) throws Exception { 73 for (int i = 0; i < networks.size(); i++) { 74 A3CMLNetwork network = (A3CMLNetwork)networks.elementAt(i); 75 if (network.domain.equals(newNetwork.domain)) { 76 throw new Exception ("Network " + newNetwork.domain + "already added"); 77 } 78 } 79 networks.addElement(newNetwork); 80 } 81 82 public void removeNetwork(String domainName) { 83 for (int i = 0; i < networks.size(); i++) { 84 A3CMLNetwork network = (A3CMLNetwork)networks.elementAt(i); 85 if (network.domain.equals(domainName)) { 86 networks.removeElementAt(i); 87 } 88 } 89 } 90 91 public void addService(A3CMLService newService) throws Exception { 92 for (int i = 0; i < services.size(); i++) { 93 A3CMLService service = (A3CMLService)services.elementAt(i); 94 if (service.classname.equals(newService.classname)) { 95 throw new Exception ("Service " + newService.classname + "already added"); 96 } 97 } 98 services.addElement(newService); 99 } 100 101 public void removeService(String serviceClassName) { 102 for (int i = 0; i < services.size(); i++) { 103 A3CMLService service = (A3CMLService)services.elementAt(i); 104 if (service.classname.equals(serviceClassName)) { 105 services.removeElementAt(i); 106 } 107 } 108 } 109 110 public A3CMLProperty addProperty(A3CMLProperty prop) { 111 if (properties == null) 112 properties = new Hashtable(); 113 return (A3CMLProperty) properties.put(prop.name, prop); 114 } 115 116 public A3CMLProperty getProperty(String name) { 117 if (properties == null) return null; 118 return (A3CMLProperty) properties.get(name); 119 } 120 121 public A3CMLProperty removeProperty(String name) { 122 if (properties != null) 123 return (A3CMLProperty) properties.remove(name); 124 return null; 125 } 126 127 public boolean containsProperty(String name) { 128 if (properties != null) 129 return properties.containsKey(name); 130 return false; 131 } 132 133 public A3CMLNat addNat(A3CMLNat natElement) { 134 if (nat == null) 135 nat = new Hashtable(); 136 return (A3CMLNat) nat.put(new Short (natElement.sid), natElement); 137 } 138 139 public A3CMLNat getNat(short sid) { 140 if (nat == null) return null; 141 return (A3CMLNat) nat.get(new Short (sid)); 142 } 143 144 public A3CMLNat removeNat(short sid) { 145 if (nat != null) 146 return (A3CMLNat) nat.remove(new Short (sid)); 147 return null; 148 } 149 150 public boolean containsNat(short sid) { 151 if (nat != null) 152 return nat.containsKey(new Short (sid)); 153 return false; 154 } 155 public final String getJvmArgs() { 156 if (jvmArgs != null) return jvmArgs; 157 return ""; 158 } 159 160 public final A3CMLService getService(String classname) throws UnknownServiceException { 161 if (services != null) { 162 for (int i = services.size() - 1; i >= 0; i--) { 163 A3CMLService service = (A3CMLService) services.elementAt(i); 164 if (service.classname.equals(classname)) 165 return service; 166 } 167 } 168 throw new UnknownServiceException("Unknown service \"" + classname + 169 "\" on server#" + sid); 170 } 171 172 public final String getServiceArgs(String classname) throws UnknownServiceException { 173 if (services != null) { 174 for (int i = services.size() -1; i >=0; i--) { 175 A3CMLService service = (A3CMLService) services.elementAt(i); 176 if (service.classname.equals(classname)) 177 return service.args; 178 } 179 } 180 throw new UnknownServiceException("Unknown service \"" + classname + 181 "\" on server#" + sid); 182 } 183 184 public A3CMLNetwork getNetwork(String domainName) { 185 for (int i = networks.size() -1; i >=0; i--) { 186 A3CMLNetwork nw = (A3CMLNetwork) networks.elementAt(i); 187 if (nw.domain.equals(domainName)) { 188 return nw; 189 } 190 } 191 return null; 192 } 193 194 public A3CMLServer duplicate(Hashtable context) throws Exception { 195 A3CMLServer clone = null; 196 Short serverSid = new Short (sid); 197 if (!context.containsKey(serverSid)) { 198 clone = duplicate(); 199 context.put(serverSid,clone); 200 } else 201 clone = (A3CMLServer) context.get(serverSid); 202 return clone; 203 } 204 205 public A3CMLServer duplicate() throws Exception { 206 A3CMLServer clone = new A3CMLServer(sid, 207 name, 208 hostname); 209 if (networks != null) { 210 for (Enumeration n = networks.elements(); n.hasMoreElements(); ) 211 clone.networks.addElement( 212 ((A3CMLNetwork) n.nextElement()).duplicate()); 213 } 214 clone.gateway = gateway; 215 clone.domain = domain; 216 clone.port = port; 217 218 clone.visited = visited; 220 if (services != null) { 221 for (Enumeration e = services.elements(); e.hasMoreElements(); ) 222 clone.services.addElement( 223 ((A3CMLService) e.nextElement()).duplicate()); 224 } 225 if (properties != null) { 226 for (Enumeration e = properties.keys(); e.hasMoreElements(); ) { 227 228 String pName = (String ) e.nextElement(); 229 A3CMLProperty prop = (A3CMLProperty) properties.get(pName); 230 if (prop != null) { 231 if (clone.properties == null) clone.properties = new Hashtable(); 232 clone.properties.put(pName, prop.duplicate()); 233 } 234 } 235 } 236 if (nat != null) { 237 for (Enumeration e = nat.elements(); e.hasMoreElements(); ) 238 clone.addNat( 239 ((A3CMLNat) e.nextElement()).duplicate()); 240 } 241 clone.jvmArgs = jvmArgs; 242 243 return clone; 244 } 245 246 public String toString() { 247 StringBuffer strBuf = new StringBuffer (); 248 strBuf.append("("); 249 strBuf.append(super.toString()); 250 strBuf.append(",name=").append(name); 251 strBuf.append(",sid=").append(sid); 252 strBuf.append(",hostname=").append(hostname); 253 strBuf.append(",port=").append(port); 254 strBuf.append(",domain=").append(domain); 255 strBuf.append(",visited=").append(visited); 256 strBuf.append(",networks=").append(networks); 257 strBuf.append(",jvmArgs=").append(jvmArgs); 258 strBuf.append(",services=").append(services); 259 strBuf.append(",properties=").append(properties); 260 strBuf.append(",nat=").append(nat); 261 strBuf.append(",gateway=").append(gateway); 262 strBuf.append(",hops=").append(hops); 263 strBuf.append(")"); 264 return strBuf.toString(); 265 } 266 267 public boolean equals(Object obj) { 268 if (obj == null) return false; 269 270 if (obj instanceof A3CMLServer) { 271 A3CMLServer server = (A3CMLServer) obj; 272 if ((sid == server.sid) && 273 name.equals(server.name) && 274 ((hostname == server.hostname) || 275 ((hostname != null) && hostname.equals(server.hostname))) && 276 ((domain == server.domain) || 277 ((domain != null) && domain.equals(server.domain))) && 278 (port == server.port) && 279 services.equals(server.services) && 280 ((jvmArgs == server.jvmArgs) || 281 ((jvmArgs != null) && jvmArgs.equals(server.jvmArgs))) && 282 ((properties == server.properties) || 283 ((properties != null) && properties.equals(server.properties))) && 284 ((nat == server.nat) || 285 ((nat != null) && nat.equals(server.nat))) && 286 networks.equals(server.networks) && 287 (visited == server.visited) && 288 (gateway == server.gateway)) 289 return true; 290 } 291 return false; 292 } 293 } 294 | Popular Tags |