KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > RefAddr


1 /*
2  * @(#)RefAddr.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.naming;
9
10 /**
11   * This class represents the address of a communications end-point.
12   * It consists of a type that describes the communication mechanism
13   * and an address contents determined by an RefAddr subclass.
14   *<p>
15   * For example, an address type could be "BSD Printer Address",
16   * which specifies that it is an address to be used with the BSD printing
17   * protocol. Its contents could be the machine name identifying the
18   * location of the printer server that understands this protocol.
19   *<p>
20   * A RefAddr is contained within a Reference.
21   *<p>
22   * RefAddr is an abstract class. Concrete implementations of it
23   * determine its synchronization properties.
24   *
25   * @author Rosanna Lee
26   * @author Scott Seligman
27   * @version 1.8 03/12/19
28   *
29   * @see Reference
30   * @see LinkRef
31   * @see StringRefAddr
32   * @see BinaryRefAddr
33   * @since 1.3
34   */

35
36   /*<p>
37   * The serialized form of a RefAddr object consists of only its type name
38   * String.
39   */

40
41 public abstract class RefAddr implements java.io.Serializable JavaDoc {
42     /**
43      * Contains the type of this address.
44      * @serial
45      */

46     protected String JavaDoc addrType;
47
48     /**
49       * Constructs a new instance of RefAddr using its address type.
50       *
51       * @param addrType A non-null string describing the type of the address.
52       */

53     protected RefAddr(String JavaDoc addrType) {
54     this.addrType = addrType;
55     }
56
57     /**
58       * Retrieves the address type of this address.
59       *
60       * @return The non-null address type of this address.
61       */

62     public String JavaDoc getType() {
63     return addrType;
64     }
65     
66     /**
67       * Retrieves the contents of this address.
68       *
69       * @return The possibly null address contents.
70       */

71     public abstract Object JavaDoc getContent();
72
73     /**
74       * Determines whether obj is equal to this RefAddr.
75       *<p>
76       * obj is equal to this RefAddr all of these conditions are true
77       *<ul> non-null
78       *<li> instance of RefAddr
79       *<li> obj has the same address type as this RefAddr (using String.compareTo())
80       *<li> both obj and this RefAddr's contents are null or they are equal
81       * (using the equals() test).
82       *</ul>
83       * @param obj possibly null obj to check.
84       * @return true if obj is equal to this refaddr; false otherwise.
85       * @see #getContent
86       * @see #getType
87       */

88     public boolean equals(Object JavaDoc obj) {
89     if ((obj != null) && (obj instanceof RefAddr JavaDoc)) {
90         RefAddr JavaDoc target = (RefAddr JavaDoc)obj;
91         if (addrType.compareTo(target.addrType) == 0) {
92         Object JavaDoc thisobj = this.getContent();
93         Object JavaDoc thatobj = target.getContent();
94         if (thisobj == thatobj)
95             return true;
96         if (thisobj != null)
97             return thisobj.equals(thatobj);
98         }
99     }
100     return false;
101     }
102
103     /**
104       * Computes the hash code of this address using its address type and contents.
105       * The hash code is the sum of the hash code of the address type and
106       * the hash code of the address contents.
107       *
108       * @return The hash code of this address as an int.
109       * @see java.lang.Object#hashCode
110       */

111     public int hashCode() {
112     return (getContent() == null)
113         ? addrType.hashCode()
114         : addrType.hashCode() + getContent().hashCode();
115     }
116     
117     /**
118       * Generates the string representation of this address.
119       * The string consists of the address's type and contents with labels.
120       * This representation is intended for display only and not to be parsed.
121       * @return The non-null string representation of this address.
122       */

123     public String JavaDoc toString(){
124     StringBuffer JavaDoc str = new StringBuffer JavaDoc("Type: " + addrType + "\n");
125
126     str.append("Content: " + getContent() + "\n");
127     return (str.toString());
128     }
129
130     /**
131      * Use serialVersionUID from JNDI 1.1.1 for interoperability
132      */

133     private static final long serialVersionUID = -1468165120479154358L;
134 }
135
Popular Tags