1. /*
  2. * @(#)LinkException.java 1.8 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.naming;
  8. /**
  9. * This exception is used to describe problems encounter while resolving links.
  10. * Addition information is added to the base NamingException for pinpointing
  11. * the problem with the link.
  12. *<p>
  13. * Analogous to how NamingException captures name resolution information,
  14. * LinkException captures "link"-name resolution information pinpointing
  15. * the problem encountered while resolving a link. All these fields may
  16. * be null.
  17. * <ul>
  18. * <li> Link Resolved Name. Portion of link name that has been resolved.
  19. * <li> Link Resolved Object. Object to which resolution of link name proceeded.
  20. * <li> Link Remaining Name. Portion of link name that has not been resolved.
  21. * <li> Link Explanation. Detail explaining why link resolution failed.
  22. *</ul>
  23. *
  24. *<p>
  25. * A LinkException instance is not synchronized against concurrent
  26. * multithreaded access. Multiple threads trying to access and modify
  27. * a single LinkException instance should lock the object.
  28. *
  29. * @author Rosanna Lee
  30. * @author Scott Seligman
  31. * @version 1.8 03/12/19
  32. *
  33. * @see Context#lookupLink
  34. * @see LinkRef
  35. * @since 1.3
  36. */
  37. /*<p>
  38. * The serialized form of a LinkException object consists of the
  39. * serialized fields of its NamingException superclass, the link resolved
  40. * name (a Name object), the link resolved object, link remaining name
  41. * (a Name object), and the link explanation String.
  42. */
  43. public class LinkException extends NamingException {
  44. /**
  45. * Contains the part of the link that has been successfully resolved.
  46. * It is a composite name and can be null.
  47. * This field is initialized by the constructors.
  48. * You should access and manipulate this field
  49. * through its get and set methods.
  50. * @serial
  51. * @see #getLinkResolvedName
  52. * @see #setLinkResolvedName
  53. */
  54. protected Name linkResolvedName;
  55. /**
  56. * Contains the object to which resolution of the part of the link was successful.
  57. * Can be null. This field is initialized by the constructors.
  58. * You should access and manipulate this field
  59. * through its get and set methods.
  60. * @serial
  61. * @see #getLinkResolvedObj
  62. * @see #setLinkResolvedObj
  63. */
  64. protected Object linkResolvedObj;
  65. /**
  66. * Contains the remaining link name that has not been resolved yet.
  67. * It is a composite name and can be null.
  68. * This field is initialized by the constructors.
  69. * You should access and manipulate this field
  70. * through its get and set methods.
  71. * @serial
  72. * @see #getLinkRemainingName
  73. * @see #setLinkRemainingName
  74. */
  75. protected Name linkRemainingName;
  76. /**
  77. * Contains the exception of why resolution of the link failed.
  78. * Can be null. This field is initialized by the constructors.
  79. * You should access and manipulate this field
  80. * through its get and set methods.
  81. * @serial
  82. * @see #getLinkExplanation
  83. * @see #setLinkExplanation
  84. */
  85. protected String linkExplanation;
  86. /**
  87. * Constructs a new instance of LinkException with an explanation
  88. * All the other fields are initialized to null.
  89. * @param explanation A possibly null string containing additional
  90. * detail about this exception.
  91. * @see java.lang.Throwable#getMessage
  92. */
  93. public LinkException(String explanation) {
  94. super(explanation);
  95. linkResolvedName = null;
  96. linkResolvedObj = null;
  97. linkRemainingName = null;
  98. linkExplanation = null;
  99. }
  100. /**
  101. * Constructs a new instance of LinkException.
  102. * All the non-link-related and link-related fields are initialized to null.
  103. */
  104. public LinkException() {
  105. super();
  106. linkResolvedName = null;
  107. linkResolvedObj = null;
  108. linkRemainingName = null;
  109. linkExplanation = null;
  110. }
  111. /**
  112. * Retrieves the leading portion of the link name that was resolved
  113. * successfully.
  114. *
  115. * @return The part of the link name that was resolved successfully.
  116. * It is a composite name. It can be null, which means
  117. * the link resolved name field has not been set.
  118. * @see #getLinkResolvedObj
  119. * @see #setLinkResolvedName
  120. */
  121. public Name getLinkResolvedName() {
  122. return this.linkResolvedName;
  123. }
  124. /**
  125. * Retrieves the remaining unresolved portion of the link name.
  126. * @return The part of the link name that has not been resolved.
  127. * It is a composite name. It can be null, which means
  128. * the link remaining name field has not been set.
  129. * @see #setLinkRemainingName
  130. */
  131. public Name getLinkRemainingName() {
  132. return this.linkRemainingName;
  133. }
  134. /**
  135. * Retrieves the object to which resolution was successful.
  136. * This is the object to which the resolved link name is bound.
  137. *
  138. * @return The possibly null object that was resolved so far.
  139. * If null, it means the link resolved object field has not been set.
  140. * @see #getLinkResolvedName
  141. * @see #setLinkResolvedObj
  142. */
  143. public Object getLinkResolvedObj() {
  144. return this.linkResolvedObj;
  145. }
  146. /**
  147. * Retrieves the explanation associated with the problem encounter
  148. * when resolving a link.
  149. *
  150. * @return The possibly null detail string explaining more about the problem
  151. * with resolving a link.
  152. * If null, it means there is no
  153. * link detail message for this exception.
  154. * @see #setLinkExplanation
  155. */
  156. public String getLinkExplanation() {
  157. return this.linkExplanation;
  158. }
  159. /**
  160. * Sets the explanation associated with the problem encounter
  161. * when resolving a link.
  162. *
  163. * @param msg The possibly null detail string explaining more about the problem
  164. * with resolving a link. If null, it means no detail will be recorded.
  165. * @see #getLinkExplanation
  166. */
  167. public void setLinkExplanation(String msg) {
  168. this.linkExplanation = msg;
  169. }
  170. /**
  171. * Sets the resolved link name field of this exception.
  172. *<p>
  173. * <tt>name</tt> is a composite name. If the intent is to set
  174. * this field using a compound name or string, you must
  175. * "stringify" the compound name, and create a composite
  176. * name with a single component using the string. You can then
  177. * invoke this method using the resulting composite name.
  178. *<p>
  179. * A copy of <code>name</code> is made and stored.
  180. * Subsequent changes to <code>name</code> does not
  181. * affect the copy in this NamingException and vice versa.
  182. *
  183. *
  184. * @param name The name to set resolved link name to. This can be null.
  185. * If null, it sets the link resolved name field to null.
  186. * @see #getLinkResolvedName
  187. */
  188. public void setLinkResolvedName(Name name) {
  189. if (name != null) {
  190. this.linkResolvedName = (Name)(name.clone());
  191. } else {
  192. this.linkResolvedName = null;
  193. }
  194. }
  195. /**
  196. * Sets the remaining link name field of this exception.
  197. *<p>
  198. * <tt>name</tt> is a composite name. If the intent is to set
  199. * this field using a compound name or string, you must
  200. * "stringify" the compound name, and create a composite
  201. * name with a single component using the string. You can then
  202. * invoke this method using the resulting composite name.
  203. *<p>
  204. * A copy of <code>name</code> is made and stored.
  205. * Subsequent changes to <code>name</code> does not
  206. * affect the copy in this NamingException and vice versa.
  207. *
  208. * @param name The name to set remaining link name to. This can be null.
  209. * If null, it sets the remaining name field to null.
  210. * @see #getLinkRemainingName
  211. */
  212. public void setLinkRemainingName(Name name) {
  213. if (name != null)
  214. this.linkRemainingName = (Name)(name.clone());
  215. else
  216. this.linkRemainingName = null;
  217. }
  218. /**
  219. * Sets the link resolved object field of this exception.
  220. * This indicates the last successfully resolved object of link name.
  221. * @param obj The object to set link resolved object to. This can be null.
  222. * If null, the link resolved object field is set to null.
  223. * @see #getLinkResolvedObj
  224. */
  225. public void setLinkResolvedObj(Object obj) {
  226. this.linkResolvedObj = obj;
  227. }
  228. /**
  229. * Generates the string representation of this exception.
  230. * This string consists of the NamingException information plus
  231. * the link's remaining name.
  232. * This string is used for debugging and not meant to be interpreted
  233. * programmatically.
  234. * @return The non-null string representation of this link exception.
  235. */
  236. public String toString() {
  237. return super.toString() + "; Link Remaining Name: '" +
  238. this.linkRemainingName + "'";
  239. }
  240. /**
  241. * Generates the string representation of this exception.
  242. * This string consists of the NamingException information plus
  243. * the additional information of resolving the link.
  244. * If 'detail' is true, the string also contains information on
  245. * the link resolved object. If false, this method is the same
  246. * as the form of toString() that accepts no parameters.
  247. * This string is used for debugging and not meant to be interpreted
  248. * programmatically.
  249. *
  250. * @param detail If true, add information about the link resolved
  251. * object.
  252. * @return The non-null string representation of this link exception.
  253. */
  254. public String toString(boolean detail) {
  255. if (!detail || this.linkResolvedObj == null)
  256. return this.toString();
  257. return this.toString() + "; Link Resolved Object: " +
  258. this.linkResolvedObj;
  259. }
  260. /**
  261. * Use serialVersionUID from JNDI 1.1.1 for interoperability
  262. */
  263. private static final long serialVersionUID = -7967662604076777712L;
  264. };