KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > spi > ResolveResult


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
8 package javax.naming.spi;
9
10 import javax.naming.Name JavaDoc;
11 import javax.naming.Context JavaDoc;
12 import javax.naming.CompositeName JavaDoc;
13 import javax.naming.InvalidNameException JavaDoc;
14
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.10 03/12/19
27   * @since 1.3
28   */

29 public class ResolveResult implements java.io.Serializable JavaDoc {
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 JavaDoc 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 JavaDoc remainingName;
44
45     /**
46       * Constructs an instance of ResolveResult with the
47       * resolved object and remaining name both initialized to null.
48       */

49     protected ResolveResult() {
50     resolvedObj = null;
51     remainingName = null;
52     }
53
54     /**
55       * Constructs a new instance of ResolveResult consisting of
56       * the resolved object and the remaining unresolved component.
57       *
58       * @param robj The non-null object resolved to.
59       * @param rcomp The single remaining name component that has yet to be
60       * resolved. Cannot be null (but can be empty).
61       */

62     public ResolveResult(Object JavaDoc robj, String JavaDoc rcomp) {
63     resolvedObj = robj;
64     try {
65     remainingName = new CompositeName JavaDoc(rcomp);
66 // remainingName.appendComponent(rcomp);
67
} catch (InvalidNameException JavaDoc e) {
68         // ignore; shouldn't happen
69
}
70     }
71
72     /**
73       * Constructs a new instance of ResolveResult consisting of
74       * the resolved Object and the remaining name.
75       *
76       * @param robj The non-null Object resolved to.
77       * @param rname The non-null remaining name that has yet to be resolved.
78       */

79     public ResolveResult(Object JavaDoc robj, Name JavaDoc rname) {
80     resolvedObj = robj;
81     setRemainingName(rname);
82     }
83
84     /**
85      * Retrieves the remaining unresolved portion of the name.
86      *
87      * @return The remaining unresolved portion of the name.
88      * Cannot be null but empty OK.
89      * @see #appendRemainingName
90      * @see #appendRemainingComponent
91      * @see #setRemainingName
92      */

93     public Name JavaDoc getRemainingName() {
94     return this.remainingName;
95     }
96
97     /**
98      * Retrieves the Object to which resolution was successful.
99      *
100      * @return The Object to which resolution was successful. Cannot be null.
101       * @see #setResolvedObj
102      */

103     public Object JavaDoc getResolvedObj() {
104     return this.resolvedObj;
105     }
106
107     /**
108       * Sets the remaining name field of this result to name.
109       * A copy of name is made so that modifying the copy within
110       * this ResolveResult does not affect <code>name</code> and
111       * vice versa.
112       *
113       * @param name The name to set remaining name to. Cannot be null.
114       * @see #getRemainingName
115       * @see #appendRemainingName
116       * @see #appendRemainingComponent
117       */

118     public void setRemainingName(Name JavaDoc name) {
119     if (name != null)
120         this.remainingName = (Name JavaDoc)(name.clone());
121     else {
122         // ??? should throw illegal argument exception
123
this.remainingName = null;
124     }
125     }
126
127     /**
128       * Adds components to the end of remaining name.
129       *
130       * @param name The components to add. Can be null.
131       * @see #getRemainingName
132       * @see #setRemainingName
133       * @see #appendRemainingComponent
134       */

135     public void appendRemainingName(Name JavaDoc name) {
136 // System.out.println("appendingRemainingName: " + name.toString());
137
// Exception e = new Exception();
138
// e.printStackTrace();
139
if (name != null) {
140         if (this.remainingName != null) {
141         try {
142             this.remainingName.addAll(name);
143         } catch (InvalidNameException JavaDoc e) {
144             // ignore; shouldn't happen for composite name
145
}
146         } else {
147         this.remainingName = (Name JavaDoc)(name.clone());
148         }
149     }
150     }
151
152     /**
153       * Adds a single component to the end of remaining name.
154       *
155       * @param name The component to add. Can be null.
156       * @see #getRemainingName
157       * @see #appendRemainingName
158       */

159     public void appendRemainingComponent(String JavaDoc name) {
160     if (name != null) {
161         CompositeName JavaDoc rname = new CompositeName JavaDoc();
162         try {
163         rname.add(name);
164         } catch (InvalidNameException JavaDoc e) {
165         // ignore; shouldn't happen for empty composite name
166
}
167         appendRemainingName(rname);
168     }
169     }
170
171     /**
172       * Sets the resolved Object field of this result to obj.
173       *
174       * @param obj The object to use for setting the resolved obj field.
175       * Cannot be null.
176       * @see #getResolvedObj
177       */

178     public void setResolvedObj(Object JavaDoc obj) {
179     this.resolvedObj = obj;
180     // ??? should check for null?
181
}
182
183     private static final long serialVersionUID = -4552108072002407559L;
184 }
185
Popular Tags