jdk/src/java.naming/share/classes/javax/naming/LinkRef.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 25859 3317bb8137f4
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2004, 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 a Reference whose contents is a name, called the link name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  * that is bound to an atomic name in a context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  * The name is a URL, or a name to be resolved relative to the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * context, or if the first character of the name is ".", the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  * is relative to the context in which the link is bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * Normal resolution of names in context operations always follow links.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * Resolution of the link name itself may cause resolution to pass through
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * other  links. This gives rise to the possibility of a cycle of links whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * resolution could not terminate normally. As a simple means to avoid such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * non-terminating resolutions, service providers may define limits on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * number of links that may be involved in any single operation invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * A LinkRef contains a single StringRefAddr, whose type is "LinkAddress",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * and whose contents is the link name. The class name field of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * Reference is that of this (LinkRef) class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * LinkRef is bound to a name using the normal Context.bind()/rebind(), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * DirContext.bind()/rebind(). Context.lookupLink() is used to retrieve the link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * itself if the terminal atomic name is bound to a link.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  * Many naming systems support a native notion of link that may be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  * within the naming system itself. JNDI does not specify whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * there is any relationship between such native links and JNDI links.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  * A LinkRef instance is not synchronized against concurrent access by multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * threads. Threads that need to access a LinkRef instance concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  * synchronize amongst themselves and provide the necessary locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  * @see LinkException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  * @see LinkLoopException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  * @see MalformedLinkException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  * @see Context#lookupLink
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  /*<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  * The serialized form of a LinkRef object consists of the serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  * fields of its Reference superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public class LinkRef extends Reference {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* code for link handling */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static final String linkClassName = LinkRef.class.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static final String linkAddrType = "LinkAddress";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      * Constructs a LinkRef for a name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      * @param linkName The non-null name for which to create this link.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public LinkRef(Name linkName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        super(linkClassName, new StringRefAddr(linkAddrType, linkName.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      * Constructs a LinkRef for a string name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      * @param linkName The non-null name for which to create this link.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public LinkRef(String linkName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        super(linkClassName, new StringRefAddr(linkAddrType, linkName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      * Retrieves the name of this link.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      * @return The non-null name of this link.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      * @exception MalformedLinkException If a link name could not be extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      * @exception NamingException If a naming exception was encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public String getLinkName() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (className != null && className.equals(linkClassName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            RefAddr addr = get(linkAddrType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            if (addr != null && addr instanceof StringRefAddr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                return (String)((StringRefAddr)addr).getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        throw new MalformedLinkException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final long serialVersionUID = -5386290613498931298L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}