KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > agent > conf > A3CMLDomain


1 /*
2  * Copyright (C) 2001 - 2003 ScalAgent Distributed Technologies
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  */

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 /**
27  * The class <code>A3CMLDomain</code> describes an agent server domain.
28  */

29 public class A3CMLDomain implements Serializable {
30   /** Name of the domain. */
31   public String JavaDoc name = null;
32   /** Full name of Java class */
33   public String JavaDoc network = null;
34   /** Description of alls servers in domain */
35   public Vector servers = null;
36   /**
37    * Server Id. of router (1st hop) to access this domain from current node,
38    * if -1 the domain is not accessible.
39    */

40   public short gateway = -1;
41   /**
42    * Logical distance between the server of this domain and the root one, i.e.
43    * the number of hops to reach a server from the local one.
44    */

45   public int hops = -1;
46
47 // transient MessageConsumer consumer = null;
48

49   public A3CMLDomain(String JavaDoc name, String JavaDoc network) throws Exception JavaDoc {
50     if (name.equals("local"))
51       throw new Exception JavaDoc("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 // consumer = (Network) Class.forName(network).newInstance();
58
}
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 // public boolean containsServer(A3CMLServer server) {
84
// if (servers == null) return false;
85
// return servers.contains(server);
86
// }
87

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 JavaDoc {
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 JavaDoc {
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 JavaDoc toString() {
120     StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc();
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 JavaDoc 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 // private void writeObject(java.io.ObjectOutputStream out)
148
// throws IOException {
149
// out.writeUTF(name);
150
// out.writeUTF(network);
151
// out.writeObject(servers);
152
// }
153

154 // private void readObject(java.io.ObjectInputStream in)
155
// throws IOException, ClassNotFoundException,
156
// InstantiationException, IllegalAccessException {
157
// name = in.readUTF();
158
// network = in.readUTF();
159
// servers = (Vector) in.readObject();
160
// gateway = -1;
161
// consumer = (Network) Class.forName(network).newInstance();
162
// }
163
}
164
Popular Tags