Path: blob/master/src/java.naming/share/classes/javax/naming/LinkRef.java
41152 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming;2627/**28* This class represents a Reference whose contents is a name, called the link name,29* that is bound to an atomic name in a context.30*<p>31* The name is a URL, or a name to be resolved relative to the initial32* context, or if the first character of the name is ".", the name33* is relative to the context in which the link is bound.34*<p>35* Normal resolution of names in context operations always follow links.36* Resolution of the link name itself may cause resolution to pass through37* other links. This gives rise to the possibility of a cycle of links whose38* resolution could not terminate normally. As a simple means to avoid such39* non-terminating resolutions, service providers may define limits on the40* number of links that may be involved in any single operation invoked41* by the caller.42*<p>43* A LinkRef contains a single StringRefAddr, whose type is "LinkAddress",44* and whose contents is the link name. The class name field of the45* Reference is that of this (LinkRef) class.46*<p>47* LinkRef is bound to a name using the normal Context.bind()/rebind(), and48* DirContext.bind()/rebind(). Context.lookupLink() is used to retrieve the link49* itself if the terminal atomic name is bound to a link.50*<p>51* Many naming systems support a native notion of link that may be used52* within the naming system itself. JNDI does not specify whether53* there is any relationship between such native links and JNDI links.54*<p>55* A LinkRef instance is not synchronized against concurrent access by multiple56* threads. Threads that need to access a LinkRef instance concurrently should57* synchronize amongst themselves and provide the necessary locking.58*59* @author Rosanna Lee60* @author Scott Seligman61*62* @see LinkException63* @see LinkLoopException64* @see MalformedLinkException65* @see Context#lookupLink66* @since 1.367*/6869/*<p>70* The serialized form of a LinkRef object consists of the serialized71* fields of its Reference superclass.72*/7374public class LinkRef extends Reference {75/* code for link handling */76static final String linkClassName = LinkRef.class.getName();77static final String linkAddrType = "LinkAddress";7879/**80* Constructs a LinkRef for a name.81* @param linkName The non-null name for which to create this link.82*/83public LinkRef(Name linkName) {84super(linkClassName, new StringRefAddr(linkAddrType, linkName.toString()));85}8687/**88* Constructs a LinkRef for a string name.89* @param linkName The non-null name for which to create this link.90*/91public LinkRef(String linkName) {92super(linkClassName, new StringRefAddr(linkAddrType, linkName));93}9495/**96* Retrieves the name of this link.97*98* @return The non-null name of this link.99* @throws MalformedLinkException If a link name could not be extracted100* @throws NamingException If a naming exception was encountered.101*/102public String getLinkName() throws NamingException {103if (className != null && className.equals(linkClassName)) {104RefAddr addr = get(linkAddrType);105if (addr != null && addr instanceof StringRefAddr) {106return (String)((StringRefAddr)addr).getContent();107}108}109throw new MalformedLinkException();110}111/**112* Use serialVersionUID from JNDI 1.1.1 for interoperability113*/114private static final long serialVersionUID = -5386290613498931298L;115}116117118