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