001 /*
002 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.naming;
027
028 /**
029 * This class represents a Reference whose contents is a name, called the link name,
030 * that is bound to an atomic name in a context.
031 *<p>
032 * The name is a URL, or a name to be resolved relative to the initial
033 * context, or if the first character of the name is ".", the name
034 * is relative to the context in which the link is bound.
035 *<p>
036 * Normal resolution of names in context operations always follow links.
037 * Resolution of the link name itself may cause resolution to pass through
038 * other links. This gives rise to the possibility of a cycle of links whose
039 * resolution could not terminate normally. As a simple means to avoid such
040 * non-terminating resolutions, service providers may define limits on the
041 * number of links that may be involved in any single operation invoked
042 * by the caller.
043 *<p>
044 * A LinkRef contains a single StringRefAddr, whose type is "LinkAddress",
045 * and whose contents is the link name. The class name field of the
046 * Reference is that of this (LinkRef) class.
047 *<p>
048 * LinkRef is bound to a name using the normal Context.bind()/rebind(), and
049 * DirContext.bind()/rebind(). Context.lookupLink() is used to retrieve the link
050 * itself if the terminal atomic name is bound to a link.
051 *<p>
052 * Many naming systems support a native notion of link that may be used
053 * within the naming system itself. JNDI does not specify whether
054 * there is any relationship between such native links and JNDI links.
055 *<p>
056 * A LinkRef instance is not synchronized against concurrent access by multiple
057 * threads. Threads that need to access a LinkRef instance concurrently should
058 * synchronize amongst themselves and provide the necessary locking.
059 *
060 * @author Rosanna Lee
061 * @author Scott Seligman
062 * @version 1.7 03/12/19
063 *
064 * @see LinkException
065 * @see LinkLoopException
066 * @see MalformedLinkException
067 * @see Context#lookupLink
068 * @since 1.3
069 */
070
071 /*<p>
072 * The serialized form of a LinkRef object consists of the serialized
073 * fields of its Reference superclass.
074 */
075
076 public class LinkRef extends Reference {
077 /* code for link handling */
078 static final String linkClassName = LinkRef.class.getName();
079 static final String linkAddrType = "LinkAddress";
080
081 /**
082 * Constructs a LinkRef for a name.
083 * @param linkName The non-null name for which to create this link.
084 */
085 public LinkRef(Name linkName) {
086 super (linkClassName, new StringRefAddr(linkAddrType, linkName
087 .toString()));
088 }
089
090 /**
091 * Constructs a LinkRef for a string name.
092 * @param linkName The non-null name for which to create this link.
093 */
094 public LinkRef(String linkName) {
095 super (linkClassName, new StringRefAddr(linkAddrType, linkName));
096 }
097
098 /**
099 * Retrieves the name of this link.
100 *
101 * @return The non-null name of this link.
102 * @exception MalformedLinkException If a link name could not be extracted
103 * @exception NamingException If a naming exception was encountered.
104 */
105 public String getLinkName() throws NamingException {
106 if (className != null && className.equals(linkClassName)) {
107 RefAddr addr = get(linkAddrType);
108 if (addr != null && addr instanceof StringRefAddr) {
109 return (String) ((StringRefAddr) addr).getContent();
110 }
111 }
112 throw new MalformedLinkException();
113 }
114
115 /**
116 * Use serialVersionUID from JNDI 1.1.1 for interoperability
117 */
118 private static final long serialVersionUID = -5386290613498931298L;
119 }
|