Path: blob/master/src/java.naming/share/classes/javax/naming/RefAddr.java
41152 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming;2627/**28* This class represents the address of a communications end-point.29* It consists of a type that describes the communication mechanism30* and an address contents determined by an RefAddr subclass.31*<p>32* For example, an address type could be "BSD Printer Address",33* which specifies that it is an address to be used with the BSD printing34* protocol. Its contents could be the machine name identifying the35* location of the printer server that understands this protocol.36*<p>37* A RefAddr is contained within a Reference.38*<p>39* RefAddr is an abstract class. Concrete implementations of it40* determine its synchronization properties.41*42* @author Rosanna Lee43* @author Scott Seligman44*45* @see Reference46* @see LinkRef47* @see StringRefAddr48* @see BinaryRefAddr49* @since 1.350*/5152/*<p>53* The serialized form of a RefAddr object consists of only its type name54* String.55*/5657public abstract class RefAddr implements java.io.Serializable {58/**59* Contains the type of this address.60* @serial61*/62protected String addrType;6364/**65* Constructs a new instance of RefAddr using its address type.66*67* @param addrType A non-null string describing the type of the address.68*/69protected RefAddr(String addrType) {70this.addrType = addrType;71}7273/**74* Retrieves the address type of this address.75*76* @return The non-null address type of this address.77*/78public String getType() {79return addrType;80}8182/**83* Retrieves the contents of this address.84*85* @return The possibly null address contents.86*/87public abstract Object getContent();8889/**90* Determines whether obj is equal to this RefAddr.91*<p>92* obj is equal to this RefAddr if all of these conditions are true93*<ul>94*<li> non-null95*<li> instance of RefAddr96*<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 equal98* (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 #getContent103* @see #getType104*/105public boolean equals(Object obj) {106if ((obj != null) && (obj instanceof RefAddr)) {107RefAddr target = (RefAddr)obj;108if (addrType.compareTo(target.addrType) == 0) {109Object thisobj = this.getContent();110Object thatobj = target.getContent();111if (thisobj == thatobj)112return true;113if (thisobj != null)114return thisobj.equals(thatobj);115}116}117return false;118}119120/**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 and123* the hash code of the address contents.124*125* @return The hash code of this address as an int.126* @see java.lang.Object#hashCode127*/128public int hashCode() {129return (getContent() == null)130? addrType.hashCode()131: addrType.hashCode() + getContent().hashCode();132}133134/**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*/140public String toString(){141StringBuilder str = new StringBuilder("Type: " + addrType + "\n");142143str.append("Content: " + getContent() + "\n");144return (str.toString());145}146147/**148* Use serialVersionUID from JNDI 1.1.1 for interoperability149*/150private static final long serialVersionUID = -1468165120479154358L;151}152153154