KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > util > ServerAddress


1 /*
2  * Copyright (C) 2000 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  */

20 package fr.dyade.aaa.util;
21
22 import java.util.*;
23
24 public class ServerAddress implements java.io.Serializable JavaDoc {
25
26   public static ServerAddress valueOf(String JavaDoc s) throws Exception JavaDoc {
27     StringTokenizer tokenizer = new StringTokenizer(s, "=:");
28     String JavaDoc serverName = tokenizer.nextToken();
29     String JavaDoc hostName = tokenizer.nextToken();
30     String JavaDoc portS = tokenizer.nextToken();
31     int port = Integer.valueOf(portS).intValue();
32     return new ServerAddress(serverName, hostName, port);
33   }
34
35   private String JavaDoc serverName;
36
37   private String JavaDoc hostName;
38
39   private int port;
40
41   public ServerAddress(String JavaDoc serverName,
42                        String JavaDoc hostName,
43                        int port) {
44     this.serverName = serverName;
45     this.hostName = hostName;
46     this.port = port;
47   }
48
49   public final String JavaDoc getServerName() {
50     return serverName;
51   }
52
53   public final String JavaDoc getHostName() {
54     return hostName;
55   }
56
57   public final int getPort() {
58     return port;
59   }
60
61   public String JavaDoc toString() {
62     return serverName + '=' + hostName + ':' + port;
63   }
64
65   public boolean equals(Object JavaDoc obj) {
66     if (obj instanceof ServerAddress) {
67       ServerAddress sa = (ServerAddress)obj;
68       if (! sa.serverName.equals(serverName)) return false;
69       if (! sa.hostName.equals(hostName)) return false;
70       return (sa.port == port);
71     } else {
72       return false;
73     }
74   }
75 }
76
Popular Tags