1. /*
  2. * @(#)ResolveResult.java 1.7 01/02/09
  3. *
  4. * Copyright 1999-2001 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.spi;
  11. import javax.naming.Name;
  12. import javax.naming.Context;
  13. import javax.naming.CompositeName;
  14. import javax.naming.InvalidNameException;
  15. /**
  16. * This class represents the result of resolution of a name.
  17. * It contains the object to which name was resolved, and the portion
  18. * of the name that has not been resolved.
  19. *<p>
  20. * A ResolveResult instance is not synchronized against concurrent
  21. * multithreaded access. Multiple threads trying to access and modify
  22. * a single ResolveResult instance should lock the object.
  23. *
  24. * @author Rosanna Lee
  25. * @author Scott Seligman
  26. * @version 1.7 01/02/09
  27. * @since 1.3
  28. */
  29. public class ResolveResult implements java.io.Serializable {
  30. /**
  31. * Field containing the Object that was resolved to successfully.
  32. * It can be null only when constructed using a subclass.
  33. * Constructors should always initialize this.
  34. * @serial
  35. */
  36. protected Object resolvedObj;
  37. /**
  38. * Field containing the remaining name yet to be resolved.
  39. * It can be null only when constructed using a subclass.
  40. * Constructors should always initialize this.
  41. * @serial
  42. */
  43. protected Name remainingName;
  44. /**
  45. * Constructs an instance of ResolveResult with the
  46. * resolved object and remaining name both initialized to null.
  47. */
  48. protected ResolveResult() {
  49. resolvedObj = null;
  50. remainingName = null;
  51. }
  52. /**
  53. * Constructs a new instance of ResolveResult consisting of
  54. * the resolved object and the remaining unresolved component.
  55. *
  56. * @param robj The non-null object resolved to.
  57. * @param rcomp The single remaining name component that has yet to be
  58. * resolved. Cannot be null (but can be empty).
  59. */
  60. public ResolveResult(Object robj, String rcomp) {
  61. resolvedObj = robj;
  62. try {
  63. remainingName = new CompositeName(rcomp);
  64. // remainingName.appendComponent(rcomp);
  65. } catch (InvalidNameException e) {
  66. // ignore; shouldn't happen
  67. }
  68. }
  69. /**
  70. * Constructs a new instance of ResolveResult consisting of
  71. * the resolved Object and the remaining name.
  72. *
  73. * @param robj The non-null Object resolved to.
  74. * @param rname The non-null remaining name that has yet to be resolved.
  75. */
  76. public ResolveResult(Object robj, Name rname) {
  77. resolvedObj = robj;
  78. setRemainingName(rname);
  79. }
  80. /**
  81. * Retrieves the remaining unresolved portion of the name.
  82. *
  83. * @return The remaining unresolved portion of the name.
  84. * Cannot be null but empty OK.
  85. * @see #appendRemainingName
  86. * @see #appendRemainingComponent
  87. * @see #setRemainingName
  88. */
  89. public Name getRemainingName() {
  90. return this.remainingName;
  91. }
  92. /**
  93. * Retrieves the Object to which resolution was successful.
  94. *
  95. * @return The Object to which resolution was successful. Cannot be null.
  96. * @see #setResolvedObj
  97. */
  98. public Object getResolvedObj() {
  99. return this.resolvedObj;
  100. }
  101. /**
  102. * Sets the remaining name field of this result to name.
  103. * A copy of name is made so that modifying the copy within
  104. * this ResolveResult does not affect <code>name</code> and
  105. * vice versa.
  106. *
  107. * @param name The name to set remaining name to. Cannot be null.
  108. * @see #getRemainingName
  109. * @see #appendRemainingName
  110. * @see #appendRemainingComponent
  111. */
  112. public void setRemainingName(Name name) {
  113. if (name != null)
  114. this.remainingName = (Name)(name.clone());
  115. else {
  116. // ??? should throw illegal argument exception
  117. this.remainingName = null;
  118. }
  119. }
  120. /**
  121. * Adds components to the end of remaining name.
  122. *
  123. * @param name The components to add. Can be null.
  124. * @see #getRemainingName
  125. * @see #setRemainingName
  126. * @see #appendRemainingComponent
  127. */
  128. public void appendRemainingName(Name name) {
  129. // System.out.println("appendingRemainingName: " + name.toString());
  130. // Exception e = new Exception();
  131. // e.printStackTrace();
  132. if (name != null) {
  133. if (this.remainingName != null) {
  134. try {
  135. this.remainingName.addAll(name);
  136. } catch (InvalidNameException e) {
  137. // ignore; shouldn't happen for composite name
  138. }
  139. } else {
  140. this.remainingName = (Name)(name.clone());
  141. }
  142. }
  143. }
  144. /**
  145. * Adds a single component to the end of remaining name.
  146. *
  147. * @param name The component to add. Can be null.
  148. * @see #getRemainingName
  149. * @see #appendRemainingName
  150. */
  151. public void appendRemainingComponent(String name) {
  152. if (name != null) {
  153. CompositeName rname = new CompositeName();
  154. try {
  155. rname.add(name);
  156. } catch (InvalidNameException e) {
  157. // ignore; shouldn't happen for empty composite name
  158. }
  159. appendRemainingName(rname);
  160. }
  161. }
  162. /**
  163. * Sets the resolved Object field of this result to obj.
  164. *
  165. * @param obj The object to use for setting the resolved obj field.
  166. * Cannot be null.
  167. * @see #getResolvedObj
  168. */
  169. public void setResolvedObj(Object obj) {
  170. this.resolvedObj = obj;
  171. // ??? should check for null?
  172. }
  173. }