Showing the changes to java/pkg/javax/naming/RefAddr.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,151 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package javax.naming; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * This class represents the address of a communications end-point. | |
| 30 | + * It consists of a type that describes the communication mechanism | |
| 31 | + * and an address contents determined by an RefAddr subclass. | |
| 32 | + *<p> | |
| 33 | + * For example, an address type could be "BSD Printer Address", | |
| 34 | + * which specifies that it is an address to be used with the BSD printing | |
| 35 | + * protocol. Its contents could be the machine name identifying the | |
| 36 | + * location of the printer server that understands this protocol. | |
| 37 | + *<p> | |
| 38 | + * A RefAddr is contained within a Reference. | |
| 39 | + *<p> | |
| 40 | + * RefAddr is an abstract class. Concrete implementations of it | |
| 41 | + * determine its synchronization properties. | |
| 42 | + * | |
| 43 | + * @author Rosanna Lee | |
| 44 | + * @author Scott Seligman | |
| 45 | + * | |
| 46 | + * @see Reference | |
| 47 | + * @see LinkRef | |
| 48 | + * @see StringRefAddr | |
| 49 | + * @see BinaryRefAddr | |
| 50 | + * @since 1.3 | |
| 51 | + */ | |
| 52 | + | |
| 53 | + /*<p> | |
| 54 | + * The serialized form of a RefAddr object consists of only its type name | |
| 55 | + * String. | |
| 56 | + */ | |
| 57 | + | |
| 58 | +public abstract class RefAddr implements java.io.Serializable { | |
| 59 | + /** | |
| 60 | + * Contains the type of this address. | |
| 61 | + * @serial | |
| 62 | + */ | |
| 63 | + protected String addrType; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Constructs a new instance of RefAddr using its address type. | |
| 67 | + * | |
| 68 | + * @param addrType A non-null string describing the type of the address. | |
| 69 | + */ | |
| 70 | + protected RefAddr(String addrType) { | |
| 71 | + this.addrType = addrType; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Retrieves the address type of this address. | |
| 76 | + * | |
| 77 | + * @return The non-null address type of this address. | |
| 78 | + */ | |
| 79 | + public String getType() { | |
| 80 | + return addrType; | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Retrieves the contents of this address. | |
| 85 | + * | |
| 86 | + * @return The possibly null address contents. | |
| 87 | + */ | |
| 88 | + public abstract Object getContent(); | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Determines whether obj is equal to this RefAddr. | |
| 92 | + *<p> | |
| 93 | + * obj is equal to this RefAddr all of these conditions are true | |
| 94 | + *<ul> non-null | |
| 95 | + *<li> instance of RefAddr | |
| 96 | + *<li> obj has the same address type as this RefAddr (using String.compareTo()) | |
| 97 | + *<li> both obj and this RefAddr's contents are null or they are equal | |
| 98 | + * (using the equals() test). | |
| 99 | + *</ul> | |
| 100 | + * @param obj possibly null obj to check. | |
| 101 | + * @return true if obj is equal to this refaddr; false otherwise. | |
| 102 | + * @see #getContent | |
| 103 | + * @see #getType | |
| 104 | + */ | |
| 105 | + public boolean equals(Object obj) { | |
| 106 | + if ((obj != null) && (obj instanceof RefAddr)) { | |
| 107 | + RefAddr target = (RefAddr)obj; | |
| 108 | + if (addrType.compareTo(target.addrType) == 0) { | |
| 109 | + Object thisobj = this.getContent(); | |
| 110 | + Object thatobj = target.getContent(); | |
| 111 | + if (thisobj == thatobj) | |
| 112 | + return true; | |
| 113 | + if (thisobj != null) | |
| 114 | + return thisobj.equals(thatobj); | |
| 115 | + } | |
| 116 | + } | |
| 117 | + return false; | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * Computes the hash code of this address using its address type and contents. | |
| 122 | + * The hash code is the sum of the hash code of the address type and | |
| 123 | + * the hash code of the address contents. | |
| 124 | + * | |
| 125 | + * @return The hash code of this address as an int. | |
| 126 | + * @see java.lang.Object#hashCode | |
| 127 | + */ | |
| 128 | + public int hashCode() { | |
| 129 | + return (getContent() == null) | |
| 130 | + ? addrType.hashCode() | |
| 131 | + : addrType.hashCode() + getContent().hashCode(); | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Generates the string representation of this address. | |
| 136 | + * The string consists of the address's type and contents with labels. | |
| 137 | + * This representation is intended for display only and not to be parsed. | |
| 138 | + * @return The non-null string representation of this address. | |
| 139 | + */ | |
| 140 | + public String toString(){ | |
| 141 | + StringBuffer str = new StringBuffer("Type: " + addrType + "\n"); | |
| 142 | + | |
| 143 | + str.append("Content: " + getContent() + "\n"); | |
| 144 | + return (str.toString()); | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Use serialVersionUID from JNDI 1.1.1 for interoperability | |
| 149 | + */ | |
| 150 | + private static final long serialVersionUID = -1468165120479154358L; | |
| 151 | +} | |