jdk/src/java.naming/share/classes/javax/naming/LinkRef.java
changeset 25859 3317bb8137f4
parent 5506 202f599c92aa
equal deleted inserted replaced
25858:836adbf7a2cd 25859:3317bb8137f4
       
     1 /*
       
     2  * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package javax.naming;
       
    27 
       
    28 /**
       
    29   * This class represents a Reference whose contents is a name, called the link name,
       
    30   * that is bound to an atomic name in a context.
       
    31   *<p>
       
    32   * The name is a URL, or a name to be resolved relative to the initial
       
    33   * context, or if the first character of the name is ".", the name
       
    34   * is relative to the context in which the link is bound.
       
    35   *<p>
       
    36   * Normal resolution of names in context operations always follow links.
       
    37   * Resolution of the link name itself may cause resolution to pass through
       
    38   * other  links. This gives rise to the possibility of a cycle of links whose
       
    39   * resolution could not terminate normally. As a simple means to avoid such
       
    40   * non-terminating resolutions, service providers may define limits on the
       
    41   * number of links that may be involved in any single operation invoked
       
    42   * by the caller.
       
    43   *<p>
       
    44   * A LinkRef contains a single StringRefAddr, whose type is "LinkAddress",
       
    45   * and whose contents is the link name. The class name field of the
       
    46   * Reference is that of this (LinkRef) class.
       
    47   *<p>
       
    48   * LinkRef is bound to a name using the normal Context.bind()/rebind(), and
       
    49   * DirContext.bind()/rebind(). Context.lookupLink() is used to retrieve the link
       
    50   * itself if the terminal atomic name is bound to a link.
       
    51   *<p>
       
    52   * Many naming systems support a native notion of link that may be used
       
    53   * within the naming system itself. JNDI does not specify whether
       
    54   * there is any relationship between such native links and JNDI links.
       
    55   *<p>
       
    56   * A LinkRef instance is not synchronized against concurrent access by multiple
       
    57   * threads. Threads that need to access a LinkRef instance concurrently should
       
    58   * synchronize amongst themselves and provide the necessary locking.
       
    59   *
       
    60   * @author Rosanna Lee
       
    61   * @author Scott Seligman
       
    62   *
       
    63   * @see LinkException
       
    64   * @see LinkLoopException
       
    65   * @see MalformedLinkException
       
    66   * @see Context#lookupLink
       
    67   * @since 1.3
       
    68   */
       
    69 
       
    70   /*<p>
       
    71   * The serialized form of a LinkRef object consists of the serialized
       
    72   * fields of its Reference superclass.
       
    73   */
       
    74 
       
    75 public class LinkRef extends Reference {
       
    76     /* code for link handling */
       
    77     static final String linkClassName = LinkRef.class.getName();
       
    78     static final String linkAddrType = "LinkAddress";
       
    79 
       
    80     /**
       
    81       * Constructs a LinkRef for a name.
       
    82       * @param linkName The non-null name for which to create this link.
       
    83       */
       
    84     public LinkRef(Name linkName) {
       
    85         super(linkClassName, new StringRefAddr(linkAddrType, linkName.toString()));
       
    86     }
       
    87 
       
    88     /**
       
    89       * Constructs a LinkRef for a string name.
       
    90       * @param linkName The non-null name for which to create this link.
       
    91       */
       
    92     public LinkRef(String linkName) {
       
    93         super(linkClassName, new StringRefAddr(linkAddrType, linkName));
       
    94     }
       
    95 
       
    96     /**
       
    97       * Retrieves the name of this link.
       
    98       *
       
    99       * @return The non-null name of this link.
       
   100       * @exception MalformedLinkException If a link name could not be extracted
       
   101       * @exception NamingException If a naming exception was encountered.
       
   102       */
       
   103     public String getLinkName() throws NamingException {
       
   104         if (className != null && className.equals(linkClassName)) {
       
   105             RefAddr addr = get(linkAddrType);
       
   106             if (addr != null && addr instanceof StringRefAddr) {
       
   107                 return (String)((StringRefAddr)addr).getContent();
       
   108             }
       
   109         }
       
   110         throw new MalformedLinkException();
       
   111     }
       
   112     /**
       
   113      * Use serialVersionUID from JNDI 1.1.1 for interoperability
       
   114      */
       
   115     private static final long serialVersionUID = -5386290613498931298L;
       
   116 }