001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.naming;
019:
020: import java.io.Serializable;
021:
022: /**
023: * This is an abstract class describing the address of an object which is
024: * outside of a naming system. It contains an address type and the address
025: * itself is dealt with by its subclasses, for example,
026: * <code>BinaryRefAddr</code> and <code>StringRefAddr
027: * </code>.
028: *
029: * @see BinaryRefAddr
030: * @see StringRefAddr
031: */
032: public abstract class RefAddr implements Serializable {
033:
034: /*
035: * This constant is used during deserialization to check the version which
036: * created the serialized object.
037: */
038: static final long serialVersionUID = -1468165120479154358L;
039:
040: /**
041: * The type of the address.
042: *
043: * @serial
044: */
045: protected String addrType;
046:
047: /**
048: * Constructs a <code>RefAddr</code> instance using the supplied address
049: * type.
050: *
051: * @param type
052: * the address type which may be null
053: */
054: protected RefAddr(String type) {
055: this .addrType = type;
056: }
057:
058: /**
059: * Returns true if this address is equal to the supplied object
060: * <code>o</code>. They are considered equal if the address types are
061: * equal and the address contents are equivalent. *
062: *
063: * @param o
064: * the object to compare with
065: * @return true if this address is equal to <code>o</code>, otherwise
066: * false
067: */
068: @Override
069: public boolean equals(Object o) {
070: if (o instanceof RefAddr) {
071: RefAddr a = (RefAddr) o;
072: return this .addrType.equals(a.addrType)
073: && (null == this .getContent() ? null == a
074: .getContent() : this .getContent().equals(
075: a.getContent()));
076: }
077: return false;
078: }
079:
080: /**
081: * Gets the address itself which may be null. Each subclass of
082: * <code>RefAddr</code> describes the format of the returned address.
083: *
084: * @return the address itself
085: */
086: public abstract Object getContent();
087:
088: /**
089: * Gets the type of this address.
090: *
091: * @return the type of this address which cannot be null
092: */
093: public String getType() {
094: return addrType;
095: }
096:
097: /**
098: * Returns the hashcode for this address. The result is the sum of the
099: * hashcode of its address type and address.
100: *
101: * @return the hashcode of this address
102: */
103: @Override
104: public int hashCode() {
105: return this .addrType.hashCode()
106: + (null == this .getContent() ? 0 : this .getContent()
107: .hashCode());
108: }
109:
110: /**
111: * Returns the string representation of this address. This contains the
112: * string representations of the address type and the address.
113: *
114: * @return the string representation of this address
115: */
116: @SuppressWarnings("nls")
117: @Override
118: public String toString() {
119: return "The type of the address is: "
120: + this .addrType
121: + "\nThe content of the address is: "
122: + (null == this .getContent() ? "null" : this
123: .getContent().toString()) + "\n";
124: }
125:
126: }
|