1 19 package fr.dyade.aaa.agent.conf; 20 21 import java.io.*; 22 import java.util.*; 23 24 import org.objectweb.util.monolog.api.*; 25 26 29 public class A3CMLDomain implements Serializable { 30 31 public String name = null; 32 33 public String network = null; 34 35 public Vector servers = null; 36 40 public short gateway = -1; 41 45 public int hops = -1; 46 47 49 public A3CMLDomain(String name, String network) throws Exception { 50 if (name.equals("local")) 51 throw new Exception ("Domain name \"" + name + "\" is reserved."); 52 this.name = name; 53 if ((network == null) || network.equals("")) 54 this.network = "fr.dyade.aaa.agent.SimpleNetwork"; 55 else 56 this.network = network; 57 } 59 60 public void addServer(A3CMLServer server) { 61 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 62 Log.logger.log(BasicLevel.DEBUG, 63 "A3CMLDomain.addServer(" + server + ')'); 64 if (servers == null) servers = new Vector(); 65 servers.addElement(server); 66 } 67 68 public void removeServer(A3CMLServer server) { 69 if (servers == null) return; 70 servers.removeElement(server); 71 } 72 73 public void removeServer(short sid) { 74 if (servers == null) return; 75 for (int i = 0; i < servers.size(); i++) { 76 A3CMLServer serv = (A3CMLServer) servers.elementAt(i); 77 if (serv.sid == sid) { 78 servers.removeElementAt(i); 79 } 80 } 81 } 82 83 88 public short[] getServersId() { 89 if (servers != null) { 90 short[] domainSids = new short[servers.size()]; 91 for (int i=0; i<domainSids.length; i++) { 92 domainSids[i] = ((A3CMLServer) servers.elementAt(i)).sid; 93 } 94 return domainSids; 95 } 96 return new short[0]; 97 } 98 99 public A3CMLDomain duplicate() throws Exception { 100 A3CMLDomain clone = new A3CMLDomain(name,network); 101 if (servers != null) { 102 for (Enumeration s = servers.elements(); s.hasMoreElements(); ) 103 clone.addServer(((A3CMLServer) s.nextElement()).duplicate()); 104 } 105 clone.gateway = gateway; 106 return clone; 107 } 108 109 public A3CMLDomain duplicate(Hashtable context) throws Exception { 110 A3CMLDomain clone = new A3CMLDomain(name,network); 111 if (servers != null) { 112 for (Enumeration s = servers.elements(); s.hasMoreElements(); ) 113 clone.addServer(((A3CMLServer) s.nextElement()).duplicate(context)); 114 } 115 clone.gateway = gateway; 116 return clone; 117 } 118 119 public String toString() { 120 StringBuffer strBuf = new StringBuffer (); 121 strBuf.append("(").append(super.toString()); 122 strBuf.append(",name=").append(name); 123 strBuf.append(",network=").append(network); 124 strBuf.append(",servers=").append(servers); 125 strBuf.append(",gateway=").append(gateway); 126 strBuf.append(",hops=").append(hops); 127 strBuf.append(")"); 128 129 return strBuf.toString(); 130 } 131 132 public boolean equals(Object obj) { 133 if (obj == null) return false; 134 135 if (obj instanceof A3CMLDomain) { 136 A3CMLDomain domain = (A3CMLDomain) obj; 137 if (name.equals(domain.name) && 138 network.equals(domain.network) && 139 ((servers == domain.servers) || 140 ((servers != null) && servers.equals(domain.servers))) && 141 (gateway == domain.gateway)) 142 return true; 143 } 144 return false; 145 } 146 147 154 } 164 | Popular Tags |