001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.naming;
019:
020: /**
021: * Naming operations may throw a <code>LinkException</code> when attempting to
022: * resolve links. Methods are provided to save diagnostic information about how
023: * far link resolution has progressed.
024: * <p>
025: * Multithreaded access to a single <code>LinkException</code> instance is
026: * only safe when client code uses appropriate synchronization and locking.
027: * </p>
028: */
029: public class LinkException extends NamingException {
030:
031: /*
032: * This constant is used during deserialization to check the version which
033: * created the serialized object.
034: */
035: private final static long serialVersionUID = -7967662604076777712L;
036:
037: /**
038: * Description of why the link could not be resolved.
039: */
040: protected String linkExplanation;
041:
042: /**
043: * Composite name containing the name which could not be resolved.
044: */
045: protected Name linkRemainingName;
046:
047: /**
048: * Composite name containing the name which was resolved.
049: */
050: protected Name linkResolvedName;
051:
052: /**
053: * Contains the object that linkResolvedName relates to.
054: */
055: protected Object linkResolvedObj;
056:
057: /**
058: * Constructs a <code>LinkException</code> instance with all data
059: * initialized to null.
060: */
061: public LinkException() {
062: super ();
063: }
064:
065: /**
066: * Constructs a <code>LinkException</code> instance with the specified
067: * message.
068: *
069: * @param s
070: * The detail message for the exception. It may be null.
071: */
072: public LinkException(String s) {
073: super (s);
074: }
075:
076: /**
077: * Outputs the string representation of this <code>NamingException</code>
078: * together with the details of the remaining name.
079: *
080: * @return the string representation of this <code>NamingException</code>
081: * together with the details of the remaining name.
082: */
083: @Override
084: public String toString() {
085: return toStringImpl(false);
086: }
087:
088: private String toStringImpl(boolean b) {
089: StringBuffer sb = new StringBuffer(super .toString());
090: sb
091: .append("; the link remaining name is - '").append(linkRemainingName).append( //$NON-NLS-1$
092: "'"); //$NON-NLS-1$
093: if (b && null != linkResolvedObj) {
094: sb.append("; the link resolved object is - '").append( //$NON-NLS-1$
095: linkResolvedObj).append("'"); //$NON-NLS-1$
096: }
097: return sb.toString();
098: }
099:
100: /**
101: * Outputs the string representation of this <code>NamingException</code>
102: * together with the details of the remaining name.
103: * <p>
104: * If boolean b is set to true then also outputs the resolved object.<br/>
105: * If boolean b is set to false then the behavior is the same as
106: * <code>toString()</code>.
107: *
108: * @param b
109: * Indicates if the resolved object need to be outputted.
110: * @return the string representation of this <code>NamingException</code>
111: * together with the details of the remaining name.
112: */
113: @Override
114: public String toString(boolean b) {
115: return toStringImpl(b);
116: }
117:
118: /**
119: * Retrieves the value of the <code>linkExplanation</code> field.
120: *
121: * @return the value of the <code>linkExplanation</code> field.
122: */
123: public String getLinkExplanation() {
124: return linkExplanation;
125: }
126:
127: /**
128: * Retrieves the value of the <code>linkRemainingName</code> field.
129: *
130: * @return the value of the <code>linkRemainingName</code> field.
131: */
132: public Name getLinkRemainingName() {
133: return linkRemainingName;
134: }
135:
136: /**
137: * Retrieves the value of the <code>linkResolvedName</code> field.
138: *
139: * @return the value of the <code>linkResolvedName</code> field.
140: */
141: public Name getLinkResolvedName() {
142: return linkResolvedName;
143: }
144:
145: /**
146: * Retrieves the value of the <code>linkResolvedObj</code> field.
147: *
148: * @return the value of the <code>linkResolvedObj</code> field.
149: */
150: public Object getLinkResolvedObj() {
151: return linkResolvedObj;
152: }
153:
154: /**
155: * Sets the <code>linkExplanation</code> field to the specified value.
156: *
157: * @param string
158: * the new <code>linkExplanation</code> value to be set.
159: */
160: public void setLinkExplanation(String string) {
161: linkExplanation = string;
162: }
163:
164: /**
165: * Sets the <code>linkRemainingName</code> to the specified name. It may
166: * be null. The remaining name details must not change even if the original
167: * <code>Name</code> itself changes.
168: *
169: * @param name
170: * the new <code>linkRemainingName</code> value to be set. It
171: * may be null.
172: */
173: public void setLinkRemainingName(Name name) {
174: linkRemainingName = null == name ? null : (Name) name.clone();
175: }
176:
177: /**
178: * Sets the <code>linkResolvedName</code> to the specified name. This may
179: * be null. The resolved name details must not change even if the original
180: * <code>Name</code> itself changes.
181: *
182: * @param name
183: * the new <code>linkResolvedName</code> value to be set.
184: */
185: public void setLinkResolvedName(Name name) {
186: linkResolvedName = null == name ? null : (Name) name.clone();
187: }
188:
189: /**
190: * Sets the <code>linkResolvedObj</code> field to object. This may be
191: * null.
192: *
193: * @param object
194: * the new <code>linkResolvedObj</code> value to be set.
195: */
196: public void setLinkResolvedObj(Object object) {
197: linkResolvedObj = object;
198: }
199:
200: }
|