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