KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
25  * The class <code>PServer</code> describes a persistent agent server.
26  */

27 public class A3CMLPServer extends A3CMLServer implements Serializable {
28   /** Domain (1st hop) used to access this server from current node. */
29   public String domain = null;
30   /**
31    * Communication port if the server is directly accessible by the root
32    * server.
33    */

34   public int port = -1;
35
36   public A3CMLPServer(short sid,
37                       String name,
38                       String hostname) throws Exception {
39     super(sid, name, hostname);
40   }
41
42   public void addNetwork(A3CMLNetwork newNetwork) throws Exception {
43     for (int i = 0; i < networks.size(); i++) {
44       A3CMLNetwork network = (A3CMLNetwork)networks.elementAt(i);
45       if (network.domain.equals(newNetwork.domain)) {
46         throw new Exception("Network " + newNetwork.domain + "already added");
47       }
48     }
49     networks.addElement(newNetwork);
50   }
51
52   public void removeNetwork(String domainName) {
53     for (int i = 0; i < networks.size(); i++) {
54       A3CMLNetwork network = (A3CMLNetwork)networks.elementAt(i);
55       if (network.domain.equals(domainName)) {
56         networks.removeElementAt(i);
57       }
58     }
59   }
60
61   public A3CMLPServer duplicate(Hashtable context) throws Exception {
62     A3CMLPServer clone = null;
63     Short serverSid = new Short(sid);
64     if (!context.containsKey(serverSid)) {
65       clone = duplicate();
66       context.put(serverSid,clone);
67     } else
68       clone = (A3CMLPServer) context.get(serverSid);
69     return clone;
70   }
71
72   public A3CMLPServer duplicate() throws Exception {
73     A3CMLPServer clone = new A3CMLPServer(sid,
74                                           name,
75                                           hostname);
76     if (networks != null) {
77       for (Enumeration n = networks.elements(); n.hasMoreElements(); )
78         clone.networks.addElement(
79           ((A3CMLNetwork) n.nextElement()).duplicate());
80     }
81     clone.gateway = gateway;
82     clone.domain = domain;
83     clone.port = port;
84
85     // super class
86
clone.visited = visited;
87     if (services != null) {
88       for (Enumeration e = services.elements(); e.hasMoreElements(); )
89         clone.services.addElement(
90           ((A3CMLService) e.nextElement()).duplicate());
91     }
92     if (properties != null) {
93       for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
94         Short sid = (Short) e.nextElement();
95         clone.properties.put(sid,
96                              ((A3CMLProperty) properties.get(sid)).duplicate());
97       }
98     }
99     if (nat != null) {
100       for (Enumeration e = nat.elements(); e.hasMoreElements(); )
101         clone.addNat(
102           ((A3CMLNat) e.nextElement()).duplicate());
103     }
104     clone.jvmArgs = jvmArgs;
105
106     return clone;
107   }
108
109   public String toString() {
110     StringBuffer strBuf = new StringBuffer();
111     strBuf.append("(");
112     strBuf.append(super.toString());
113     strBuf.append(",port=").append(port);
114     strBuf.append(",domain=").append(domain);
115     strBuf.append(")");
116     return strBuf.toString();
117   }
118
119   public boolean equals(Object obj) {
120     if (obj == null) return false;
121
122     if (obj instanceof A3CMLPServer) {
123       A3CMLPServer server = (A3CMLPServer) obj;
124       if (super.equals(server) &&
125           ((domain == server.domain) ||
126            ((domain != null) && domain.equals(server.domain))) &&
127           (port == server.port))
128       return true;
129     }
130     return false;
131   }
132
133 // private void writeObject(java.io.ObjectOutputStream out)
134
// throws IOException {
135
// out.writeObject(domain);
136
// out.writeInt(port);
137
// }
138

139 // private void readObject(java.io.ObjectInputStream in)
140
// throws IOException, ClassNotFoundException {
141
// domain = (String) in.readObject();
142
// port = in.readInt();
143
// gateway = -1;
144
// visited = false;
145
// }
146
}
147
Popular Tags