Path: blob/master/src/java.naming/share/classes/javax/naming/LinkException.java
41152 views
/*1* Copyright (c) 1999, 2019, 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 exception is used to describe problems encountered while resolving links.29* Additional information is added to the base NamingException for pinpointing30* the problem with the link.31*<p>32* Analogously to how NamingException captures name resolution information,33* LinkException captures "link"-name resolution information pinpointing34* the problem encountered while resolving a link. All these fields may35* be null.36* <ul>37* <li> Link Resolved Name. Portion of link name that has been resolved.38* <li> Link Resolved Object. Object to which resolution of link name proceeded.39* <li> Link Remaining Name. Portion of link name that has not been resolved.40* <li> Link Explanation. Detail explaining why link resolution failed.41*</ul>42*43*<p>44* A LinkException instance is not synchronized against concurrent45* multithreaded access. Multiple threads trying to access and modify46* a single LinkException instance should lock the object.47*48* @author Rosanna Lee49* @author Scott Seligman50*51* @see Context#lookupLink52* @see LinkRef53* @since 1.354*/555657/*<p>58* The serialized form of a LinkException object consists of the59* serialized fields of its NamingException superclass, the link resolved60* name (a Name object), the link resolved object, link remaining name61* (a Name object), and the link explanation String.62*/636465public class LinkException extends NamingException {66/**67* Contains the part of the link that has been successfully resolved.68* It is a composite name and can be null.69* This field is initialized by the constructors.70* You should access and manipulate this field71* through its get and set methods.72* @serial73* @see #getLinkResolvedName74* @see #setLinkResolvedName75*/76protected Name linkResolvedName;7778/**79* Contains the object to which resolution of the part of the link was successful.80* Can be null. This field is initialized by the constructors.81* You should access and manipulate this field82* through its get and set methods.83* @serial84* @see #getLinkResolvedObj85* @see #setLinkResolvedObj86*/87@SuppressWarnings("serial") // Not statically typed as Serializable88protected Object linkResolvedObj;8990/**91* Contains the remaining link name that has not been resolved yet.92* It is a composite name and can be null.93* This field is initialized by the constructors.94* You should access and manipulate this field95* through its get and set methods.96* @serial97* @see #getLinkRemainingName98* @see #setLinkRemainingName99*/100protected Name linkRemainingName;101102/**103* Contains the exception of why resolution of the link failed.104* Can be null. This field is initialized by the constructors.105* You should access and manipulate this field106* through its get and set methods.107* @serial108* @see #getLinkExplanation109* @see #setLinkExplanation110*/111protected String linkExplanation;112113/**114* Constructs a new instance of LinkException with an explanation.115* All the other fields are initialized to null.116* @param explanation A possibly null string containing additional117* detail about this exception.118* @see java.lang.Throwable#getMessage119*/120public LinkException(String explanation) {121super(explanation);122linkResolvedName = null;123linkResolvedObj = null;124linkRemainingName = null;125linkExplanation = null;126}127128/**129* Constructs a new instance of LinkException.130* All the non-link-related and link-related fields are initialized to null.131*/132public LinkException() {133super();134linkResolvedName = null;135linkResolvedObj = null;136linkRemainingName = null;137linkExplanation = null;138}139140/**141* Retrieves the leading portion of the link name that was resolved142* successfully.143*144* @return The part of the link name that was resolved successfully.145* It is a composite name. It can be null, which means146* the link resolved name field has not been set.147* @see #getLinkResolvedObj148* @see #setLinkResolvedName149*/150public Name getLinkResolvedName() {151return this.linkResolvedName;152}153154/**155* Retrieves the remaining unresolved portion of the link name.156* @return The part of the link name that has not been resolved.157* It is a composite name. It can be null, which means158* the link remaining name field has not been set.159* @see #setLinkRemainingName160*/161public Name getLinkRemainingName() {162return this.linkRemainingName;163}164165/**166* Retrieves the object to which resolution was successful.167* This is the object to which the resolved link name is bound.168*169* @return The possibly null object that was resolved so far.170* If null, it means the link resolved object field has not been set.171* @see #getLinkResolvedName172* @see #setLinkResolvedObj173*/174public Object getLinkResolvedObj() {175return this.linkResolvedObj;176}177178/**179* Retrieves the explanation associated with the problem encountered180* when resolving a link.181*182* @return The possibly null detail string explaining more about the problem183* with resolving a link.184* If null, it means there is no185* link detail message for this exception.186* @see #setLinkExplanation187*/188public String getLinkExplanation() {189return this.linkExplanation;190}191192/**193* Sets the explanation associated with the problem encountered194* when resolving a link.195*196* @param msg The possibly null detail string explaining more about the problem197* with resolving a link. If null, it means no detail will be recorded.198* @see #getLinkExplanation199*/200public void setLinkExplanation(String msg) {201this.linkExplanation = msg;202}203204/**205* Sets the resolved link name field of this exception.206*<p>207* {@code name} is a composite name. If the intent is to set208* this field using a compound name or string, you must209* "stringify" the compound name, and create a composite210* name with a single component using the string. You can then211* invoke this method using the resulting composite name.212*<p>213* A copy of <code>name</code> is made and stored.214* Subsequent changes to <code>name</code> do not215* affect the copy in this NamingException and vice versa.216*217*218* @param name The name to set resolved link name to. This can be null.219* If null, it sets the link resolved name field to null.220* @see #getLinkResolvedName221*/222public void setLinkResolvedName(Name name) {223if (name != null) {224this.linkResolvedName = (Name)(name.clone());225} else {226this.linkResolvedName = null;227}228}229230/**231* Sets the remaining link name field of this exception.232*<p>233* {@code name} is a composite name. If the intent is to set234* this field using a compound name or string, you must235* "stringify" the compound name, and create a composite236* name with a single component using the string. You can then237* invoke this method using the resulting composite name.238*<p>239* A copy of <code>name</code> is made and stored.240* Subsequent changes to <code>name</code> do not241* affect the copy in this NamingException and vice versa.242*243* @param name The name to set remaining link name to. This can be null.244* If null, it sets the remaining name field to null.245* @see #getLinkRemainingName246*/247public void setLinkRemainingName(Name name) {248if (name != null)249this.linkRemainingName = (Name)(name.clone());250else251this.linkRemainingName = null;252}253254/**255* Sets the link resolved object field of this exception.256* This indicates the last successfully resolved object of link name.257* @param obj The object to set link resolved object to. This can be null.258* If null, the link resolved object field is set to null.259* @see #getLinkResolvedObj260*/261public void setLinkResolvedObj(Object obj) {262this.linkResolvedObj = obj;263}264265/**266* Generates the string representation of this exception.267* This string consists of the NamingException information plus268* the link's remaining name.269* This string is used for debugging and not meant to be interpreted270* programmatically.271* @return The non-null string representation of this link exception.272*/273public String toString() {274return super.toString() + "; Link Remaining Name: '" +275this.linkRemainingName + "'";276}277278/**279* Generates the string representation of this exception.280* This string consists of the NamingException information plus281* the additional information of resolving the link.282* If 'detail' is true, the string also contains information on283* the link resolved object. If false, this method is the same284* as the form of toString() that accepts no parameters.285* This string is used for debugging and not meant to be interpreted286* programmatically.287*288* @param detail If true, add information about the link resolved289* object.290* @return The non-null string representation of this link exception.291*/292public String toString(boolean detail) {293if (!detail || this.linkResolvedObj == null)294return this.toString();295296return this.toString() + "; Link Resolved Object: " +297this.linkResolvedObj;298}299300/**301* Use serialVersionUID from JNDI 1.1.1 for interoperability302*/303private static final long serialVersionUID = -7967662604076777712L;304};305306307