001 /*
002 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.naming.spi;
027
028 import javax.naming.Name;
029 import javax.naming.Context;
030 import javax.naming.CompositeName;
031 import javax.naming.InvalidNameException;
032
033 /**
034 * This class represents the result of resolution of a name.
035 * It contains the object to which name was resolved, and the portion
036 * of the name that has not been resolved.
037 *<p>
038 * A ResolveResult instance is not synchronized against concurrent
039 * multithreaded access. Multiple threads trying to access and modify
040 * a single ResolveResult instance should lock the object.
041 *
042 * @author Rosanna Lee
043 * @author Scott Seligman
044 * @version 1.10 03/12/19
045 * @since 1.3
046 */
047 public class ResolveResult implements java.io.Serializable {
048 /**
049 * Field containing the Object that was resolved to successfully.
050 * It can be null only when constructed using a subclass.
051 * Constructors should always initialize this.
052 * @serial
053 */
054 protected Object resolvedObj;
055 /**
056 * Field containing the remaining name yet to be resolved.
057 * It can be null only when constructed using a subclass.
058 * Constructors should always initialize this.
059 * @serial
060 */
061 protected Name remainingName;
062
063 /**
064 * Constructs an instance of ResolveResult with the
065 * resolved object and remaining name both initialized to null.
066 */
067 protected ResolveResult() {
068 resolvedObj = null;
069 remainingName = null;
070 }
071
072 /**
073 * Constructs a new instance of ResolveResult consisting of
074 * the resolved object and the remaining unresolved component.
075 *
076 * @param robj The non-null object resolved to.
077 * @param rcomp The single remaining name component that has yet to be
078 * resolved. Cannot be null (but can be empty).
079 */
080 public ResolveResult(Object robj, String rcomp) {
081 resolvedObj = robj;
082 try {
083 remainingName = new CompositeName(rcomp);
084 // remainingName.appendComponent(rcomp);
085 } catch (InvalidNameException e) {
086 // ignore; shouldn't happen
087 }
088 }
089
090 /**
091 * Constructs a new instance of ResolveResult consisting of
092 * the resolved Object and the remaining name.
093 *
094 * @param robj The non-null Object resolved to.
095 * @param rname The non-null remaining name that has yet to be resolved.
096 */
097 public ResolveResult(Object robj, Name rname) {
098 resolvedObj = robj;
099 setRemainingName(rname);
100 }
101
102 /**
103 * Retrieves the remaining unresolved portion of the name.
104 *
105 * @return The remaining unresolved portion of the name.
106 * Cannot be null but empty OK.
107 * @see #appendRemainingName
108 * @see #appendRemainingComponent
109 * @see #setRemainingName
110 */
111 public Name getRemainingName() {
112 return this .remainingName;
113 }
114
115 /**
116 * Retrieves the Object to which resolution was successful.
117 *
118 * @return The Object to which resolution was successful. Cannot be null.
119 * @see #setResolvedObj
120 */
121 public Object getResolvedObj() {
122 return this .resolvedObj;
123 }
124
125 /**
126 * Sets the remaining name field of this result to name.
127 * A copy of name is made so that modifying the copy within
128 * this ResolveResult does not affect <code>name</code> and
129 * vice versa.
130 *
131 * @param name The name to set remaining name to. Cannot be null.
132 * @see #getRemainingName
133 * @see #appendRemainingName
134 * @see #appendRemainingComponent
135 */
136 public void setRemainingName(Name name) {
137 if (name != null)
138 this .remainingName = (Name) (name.clone());
139 else {
140 // ??? should throw illegal argument exception
141 this .remainingName = null;
142 }
143 }
144
145 /**
146 * Adds components to the end of remaining name.
147 *
148 * @param name The components to add. Can be null.
149 * @see #getRemainingName
150 * @see #setRemainingName
151 * @see #appendRemainingComponent
152 */
153 public void appendRemainingName(Name name) {
154 // System.out.println("appendingRemainingName: " + name.toString());
155 // Exception e = new Exception();
156 // e.printStackTrace();
157 if (name != null) {
158 if (this .remainingName != null) {
159 try {
160 this .remainingName.addAll(name);
161 } catch (InvalidNameException e) {
162 // ignore; shouldn't happen for composite name
163 }
164 } else {
165 this .remainingName = (Name) (name.clone());
166 }
167 }
168 }
169
170 /**
171 * Adds a single component to the end of remaining name.
172 *
173 * @param name The component to add. Can be null.
174 * @see #getRemainingName
175 * @see #appendRemainingName
176 */
177 public void appendRemainingComponent(String name) {
178 if (name != null) {
179 CompositeName rname = new CompositeName();
180 try {
181 rname.add(name);
182 } catch (InvalidNameException e) {
183 // ignore; shouldn't happen for empty composite name
184 }
185 appendRemainingName(rname);
186 }
187 }
188
189 /**
190 * Sets the resolved Object field of this result to obj.
191 *
192 * @param obj The object to use for setting the resolved obj field.
193 * Cannot be null.
194 * @see #getResolvedObj
195 */
196 public void setResolvedObj(Object obj) {
197 this .resolvedObj = obj;
198 // ??? should check for null?
199 }
200
201 private static final long serialVersionUID = -4552108072002407559L;
202 }
|