fr/dyade/aaa/agent/conf/A3CMLServer.java

00001 /*
00002  * Copyright (C) 2001 - 2004 ScalAgent Distributed Technologies 
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or any later version.
00008  * 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00017  * USA.
00018  */
00019 package fr.dyade.aaa.agent.conf;
00020 
00021 import java.io.*;
00022 import java.util.*;
00023 
00027 public class A3CMLServer implements Serializable {
00031   private static final long serialVersionUID = 1L;
00032   public short sid = -1;
00033   public String name = null;
00034   public String hostname = null;
00036   public String domain = null;
00041   public int port = -1;
00042   public Hashtable nat = null;
00043   public Vector networks = null;
00044   public Vector services = null;
00045   public String jvmArgs = null;
00046   public Hashtable properties = null;
00050   public boolean visited = false;
00056   public short gateway = -1;
00061   public int hops = -1;
00062 
00063   public A3CMLServer(short sid,
00064                      String name,
00065                      String hostname) throws Exception {
00066     this.sid = sid;
00067     if ((name == null) || (name.length() == 0))
00068       this.name = "s#" + sid;
00069     else
00070       this.name = name;
00071     this.hostname = hostname;
00072     this.services = new Vector();
00073     this.networks = new Vector();
00074   }
00075 
00076   public void addNetwork(A3CMLNetwork newNetwork) throws Exception {
00077     for (int i = 0; i < networks.size(); i++) {
00078       A3CMLNetwork network = (A3CMLNetwork)networks.elementAt(i);
00079       if (network.domain.equals(newNetwork.domain)) {
00080         throw new Exception("Network " + newNetwork.domain + "already added");
00081       }
00082     }
00083     networks.addElement(newNetwork);
00084   }
00085 
00086   public void removeNetwork(String domainName) {
00087     for (int i = 0; i < networks.size(); i++) {
00088       A3CMLNetwork network = (A3CMLNetwork)networks.elementAt(i);
00089       if (network.domain.equals(domainName)) {
00090         networks.removeElementAt(i);
00091       }
00092     }
00093   }
00094 
00095   public void addService(A3CMLService newService) throws Exception {
00096     for (int i = 0; i < services.size(); i++) {
00097       A3CMLService service = (A3CMLService)services.elementAt(i);
00098       if (service.classname.equals(newService.classname)) {
00099         throw new Exception("Service " + newService.classname + "already added");
00100       }
00101     }
00102     services.addElement(newService);
00103   }
00104 
00105   public void removeService(String serviceClassName) {
00106     for (int i = 0; i < services.size(); i++) {
00107       A3CMLService service = (A3CMLService)services.elementAt(i);
00108       if (service.classname.equals(serviceClassName)) {
00109         services.removeElementAt(i);
00110       }
00111     }
00112   }
00113 
00114   public A3CMLProperty addProperty(A3CMLProperty prop) {
00115     if (properties == null)
00116       properties = new Hashtable();
00117     return (A3CMLProperty) properties.put(prop.name, prop);
00118   }
00119   
00120   public A3CMLProperty getProperty(String name) {
00121     if (properties == null) return null;
00122     return (A3CMLProperty) properties.get(name);
00123   }
00124   
00125   public A3CMLProperty removeProperty(String name) {
00126     if (properties != null)
00127       return (A3CMLProperty) properties.remove(name);
00128     return null;
00129   }
00130   
00131   public boolean containsProperty(String name) {
00132     if (properties != null)
00133       return properties.containsKey(name);
00134     return false;
00135   }
00136 
00137   public A3CMLNat addNat(A3CMLNat natElement) {
00138     if (nat == null)
00139       nat = new Hashtable();
00140     return (A3CMLNat) nat.put(new Short(natElement.sid), natElement);
00141   }
00142 
00143   public A3CMLNat getNat(short sid) {
00144     if (nat == null) return null;
00145     return (A3CMLNat) nat.get(new Short(sid));
00146   }
00147   
00148   public A3CMLNat removeNat(short sid) {
00149     if (nat != null)
00150       return (A3CMLNat) nat.remove(new Short(sid));
00151     return null;
00152   }
00153   
00154   public boolean containsNat(short sid) {
00155     if (nat != null)
00156       return nat.containsKey(new Short(sid));
00157     return false;
00158   }
00159   public final String getJvmArgs() {
00160     if (jvmArgs != null) return jvmArgs;
00161     return "";
00162   }
00163 
00164   public final A3CMLService getService(String classname) throws UnknownServiceException {
00165     if (services != null) {
00166       for (int i = services.size() - 1; i >= 0; i--) {
00167         A3CMLService service = (A3CMLService) services.elementAt(i);
00168         if (service.classname.equals(classname))
00169           return service;
00170       }
00171     }
00172     throw new UnknownServiceException("Unknown service \"" + classname +
00173                                       "\" on server#" + sid);
00174   }
00175 
00176   public final String getServiceArgs(String classname) throws UnknownServiceException {
00177     if (services != null) {
00178       for (int i = services.size() -1; i >=0; i--) {
00179         A3CMLService service = (A3CMLService) services.elementAt(i);
00180         if (service.classname.equals(classname))
00181           return service.args;
00182       }
00183     }
00184     throw new UnknownServiceException("Unknown service \"" + classname +
00185                                       "\" on server#" + sid);
00186   }
00187 
00188   public A3CMLNetwork getNetwork(String domainName) {
00189     for (int i = networks.size() -1; i >=0; i--) {
00190       A3CMLNetwork nw = (A3CMLNetwork) networks.elementAt(i);
00191       if (nw.domain.equals(domainName)) {
00192         return nw;
00193       }
00194     }
00195     return null;
00196   }
00197 
00198   public A3CMLServer duplicate(Hashtable context) throws Exception {
00199     A3CMLServer clone = null;
00200     Short serverSid = new Short(sid);
00201     if (!context.containsKey(serverSid)) {
00202       clone = duplicate();
00203       context.put(serverSid,clone);
00204     } else
00205       clone = (A3CMLServer) context.get(serverSid);
00206     return clone;
00207   }
00208 
00209   public A3CMLServer duplicate() throws Exception {
00210     A3CMLServer clone = new A3CMLServer(sid, 
00211                                         name, 
00212                                         hostname);
00213     if (networks != null) {
00214       for (Enumeration n = networks.elements(); n.hasMoreElements(); )
00215         clone.networks.addElement(
00216           ((A3CMLNetwork) n.nextElement()).duplicate());
00217     }
00218     clone.gateway = gateway;
00219     clone.domain = domain;
00220     clone.port = port;
00221 
00222     // super class
00223     clone.visited = visited;
00224     if (services != null) {
00225       for (Enumeration e = services.elements(); e.hasMoreElements(); )
00226         clone.services.addElement(
00227           ((A3CMLService) e.nextElement()).duplicate());
00228     }
00229     if (properties != null) {
00230       for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
00231         
00232         String pName = (String) e.nextElement();
00233         A3CMLProperty prop = (A3CMLProperty) properties.get(pName);
00234         if (prop != null) {
00235           if (clone.properties == null) clone.properties = new Hashtable();
00236           clone.properties.put(pName, prop.duplicate());
00237         }
00238       }
00239     }
00240     if (nat != null) {
00241       for (Enumeration e = nat.elements(); e.hasMoreElements(); )
00242         clone.addNat(
00243           ((A3CMLNat) e.nextElement()).duplicate());
00244     }
00245     clone.jvmArgs = jvmArgs;
00246 
00247     return clone;
00248   }
00249 
00250   public String toString() {
00251     StringBuffer strBuf = new StringBuffer();
00252     strBuf.append("(");
00253     strBuf.append(super.toString());
00254     strBuf.append(",name=").append(name);
00255     strBuf.append(",sid=").append(sid);
00256     strBuf.append(",hostname=").append(hostname);
00257     strBuf.append(",port=").append(port);
00258     strBuf.append(",domain=").append(domain);
00259     strBuf.append(",visited=").append(visited);
00260     strBuf.append(",networks=").append(networks);
00261     strBuf.append(",jvmArgs=").append(jvmArgs);
00262     strBuf.append(",services=").append(services);
00263     strBuf.append(",properties=").append(properties);
00264     strBuf.append(",nat=").append(nat);
00265     strBuf.append(",gateway=").append(gateway);
00266     strBuf.append(",hops=").append(hops);
00267     strBuf.append(")");
00268     return strBuf.toString();
00269   }
00270 
00271   public boolean equals(Object obj) {
00272     if (obj == null) return false;
00273 
00274     if (obj instanceof A3CMLServer) {
00275       A3CMLServer server = (A3CMLServer) obj;
00276       if ((sid == server.sid) &&
00277           name.equals(server.name) &&
00278           ((hostname == server.hostname) ||
00279            ((hostname != null) && hostname.equals(server.hostname))) &&
00280           ((domain == server.domain) ||
00281            ((domain != null) && domain.equals(server.domain))) &&
00282           (port == server.port) &&
00283           services.equals(server.services) &&
00284           ((jvmArgs == server.jvmArgs) ||
00285            ((jvmArgs != null) && jvmArgs.equals(server.jvmArgs))) &&
00286           ((properties == server.properties) ||
00287            ((properties != null) && properties.equals(server.properties))) &&
00288           ((nat == server.nat) ||
00289            ((nat != null) && nat.equals(server.nat))) &&
00290           networks.equals(server.networks) &&
00291           (visited == server.visited) &&
00292           (gateway == server.gateway))
00293         return true;
00294     }
00295     return false;
00296   }
00297 }

Generated on Tue Sep 16 16:14:27 2008 for joram by  doxygen 1.5.0