KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > arooa > registry > ServerId


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.arooa.registry;
5
6 import java.io.ObjectStreamException JavaDoc;
7 import java.io.Serializable JavaDoc;
8
9 /**
10  * Enapsulate a server identifier as an object. Typically the server id
11  * will be the url of the server.
12  *
13  * @author Rob Gordon.
14  */

15 public class ServerId implements Serializable JavaDoc {
16     private static final long serialVersionUID= 20051117;
17     
18     /** An object which represents the local Oddjob. */
19     private static final ServerId local = new ServerId("local");
20     
21     /** The serverId string. */
22     private final String JavaDoc serverId;
23     
24     /**
25      * Create a ServerId for the give server id String.
26      *
27      * @param serverId The server id String.
28      */

29     public ServerId(String JavaDoc serverId) {
30         if (serverId == null) {
31             throw new NullPointerException JavaDoc("Server Id must not be null.");
32         }
33         this.serverId = serverId;
34     }
35     
36     /*
37      * (non-Javadoc)
38      * @see java.lang.Object#toString()
39      */

40     public String JavaDoc toString() {
41         return serverId;
42     }
43     
44     /*
45      * (non-Javadoc)
46      * @see java.lang.Object#equals(java.lang.Object)
47      */

48     public boolean equals(Object JavaDoc o) {
49         if (!(o instanceof ServerId)) {
50             return false;
51         }
52         ServerId other = (ServerId) o;
53         if (other == local) {
54             return this == local;
55         }
56         if (this == local) {
57             return other == local;
58         }
59         return this.serverId.equals(other.serverId);
60         
61     }
62     
63     /*
64      * (non-Javadoc)
65      * @see java.lang.Object#hashCode()
66      */

67     public int hashCode() {
68         return serverId.hashCode();
69     }
70     
71     /**
72      * Get the local ServerId.
73      *
74      * @return The local ServerId.
75      */

76     public static ServerId local() {
77         return local;
78     }
79     
80     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
81         if (serverId.equals(local.serverId)) {
82             return local;
83         }
84         else {
85             return this;
86         }
87     }
88
89 }
90
Popular Tags