1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
/* * @(#)RefAddr.java 1.9 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.naming; /** * This class represents the address of a communications end-point. * It consists of a type that describes the communication mechanism * and an address contents determined by an RefAddr subclass. *<p> * For example, an address type could be "BSD Printer Address", * which specifies that it is an address to be used with the BSD printing * protocol. Its contents could be the machine name identifying the * location of the printer server that understands this protocol. *<p> * A RefAddr is contained within a Reference. *<p> * RefAddr is an abstract class. Concrete implementations of it * determine its synchronization properties. * * @author Rosanna Lee * @author Scott Seligman * @version 1.9 05/11/17 * * @see Reference * @see LinkRef * @see StringRefAddr * @see BinaryRefAddr * @since 1.3 */ /*<p> * The serialized form of a RefAddr object consists of only its type name * String. */ public abstract class RefAddr implements java.io.Serializable { /** * Contains the type of this address. * @serial */ protected String addrType; /** * Constructs a new instance of RefAddr using its address type. * * @param addrType A non-null string describing the type of the address. */ protected RefAddr(String addrType) { this.addrType = addrType; } /** * Retrieves the address type of this address. * * @return The non-null address type of this address. */ public String getType() { return addrType; } /** * Retrieves the contents of this address. * * @return The possibly null address contents. */ public abstract Object getContent(); /** * Determines whether obj is equal to this RefAddr. *<p> * obj is equal to this RefAddr all of these conditions are true *<ul> non-null *<li> instance of RefAddr *<li> obj has the same address type as this RefAddr (using String.compareTo()) *<li> both obj and this RefAddr's contents are null or they are equal * (using the equals() test). *</ul> * @param obj possibly null obj to check. * @return true if obj is equal to this refaddr; false otherwise. * @see #getContent * @see #getType */ public boolean equals(Object obj) { if ((obj != null) && (obj instanceof RefAddr)) { RefAddr target = (RefAddr)obj; if (addrType.compareTo(target.addrType) == 0) { Object thisobj = this.getContent(); Object thatobj = target.getContent(); if (thisobj == thatobj) return true; if (thisobj != null) return thisobj.equals(thatobj); } } return false; } /** * Computes the hash code of this address using its address type and contents. * The hash code is the sum of the hash code of the address type and * the hash code of the address contents. * * @return The hash code of this address as an int. * @see java.lang.Object#hashCode */ public int hashCode() { return (getContent() == null) ? addrType.hashCode() : addrType.hashCode() + getContent().hashCode(); } /** * Generates the string representation of this address. * The string consists of the address's type and contents with labels. * This representation is intended for display only and not to be parsed. * @return The non-null string representation of this address. */ public String toString(){ StringBuffer str = new StringBuffer("Type: " + addrType + "\n"); str.append("Content: " + getContent() + "\n"); return (str.toString()); } /** * Use serialVersionUID from JNDI 1.1.1 for interoperability */ private static final long serialVersionUID = -1468165120479154358L; }