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