001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.naming.spi;
019:
020: import javax.naming.Name;
021: import javax.naming.InvalidNameException;
022: import javax.naming.CompositeName;
023:
024: /**
025: * An instance of <code>ResolveResult</code> is produced when a name
026: * resolution operation has completed. The instance must contain the object
027: * associated with the successfully resolved name, and any remaining portion of
028: * the name yet to be resolved. Where a <code>String</code> parameter is used
029: * to specify a name, it should be considered to be a composite name.
030: * <p>
031: * Multithreaded access to a single <code>ResolveResult</code> instance is
032: * only safe when client code locks the object first.
033: * </p>
034: */
035: public class ResolveResult implements java.io.Serializable {
036:
037: static final long serialVersionUID = -4552108072002407559L;
038:
039: /**
040: * This field holds the object associated with the resolved name. It may be
041: * null only when a subclass is constructed. It must be initialized to a
042: * non-null value by constructors of this class.
043: *
044: * @serial
045: */
046: protected Object resolvedObj;
047:
048: /**
049: * This field holds the portion of a resolved name that remains to be
050: * resolved. It may be null only when a subclass is constructed. It must be
051: * initialized to a non-null value by constructors of this class.
052: *
053: * @serial
054: */
055: protected Name remainingName;
056:
057: /**
058: * This is the default constructor implicitly invoked by subclass
059: * constructors. This constructor set both the resolved object and the
060: * remaining name to null.
061: */
062: protected ResolveResult() {
063: this .resolvedObj = null;
064: this .remainingName = null;
065: }
066:
067: /**
068: * This constructor creates a instance with the specified resolved object
069: * and a specified remaining name of type <code>String</code>. The name
070: * argument may not be null, but may be empty. The object argument may not
071: * be null.
072: *
073: * @param o
074: * may not be null
075: * @param s
076: * may not be null, but may be empty
077: */
078: public ResolveResult(Object o, String s) {
079: this .resolvedObj = o;
080: try {
081: this .remainingName = new CompositeName(s);
082: } catch (InvalidNameException e) {
083: this .remainingName = null;
084: }
085: }
086:
087: /**
088: * This constructor creates a instance with the specified resolved object
089: * and a remaining name of type <code>Name</code>. The name argument may
090: * not be null, but may be empty. The object argument may not be null.
091: *
092: * @param o
093: * may not be null
094: * @param n
095: * may not be null
096: */
097: public ResolveResult(Object o, Name n) {
098: this .resolvedObj = o;
099: if (null == n) {
100: this .remainingName = null;
101: } else {
102: this .remainingName = (Name) n.clone();
103: }
104: }
105:
106: /**
107: * Extends the remaining name (remainingName) with a single specified name
108: * component. The name argument may be null, but this leaves the remaining
109: * name unmodified.
110: *
111: * @param s
112: * the name component to be added to the remaining name. A null
113: * leaves the remaining name unmodified.
114: */
115: public void appendRemainingComponent(String s) {
116: if (null != s) {
117: if (null == this .remainingName) {
118: this .remainingName = new CompositeName();
119: }
120: try {
121: remainingName.add(s);
122: } catch (InvalidNameException e) {
123: throw new Error(e.getMessage());
124: }
125: }
126: }
127:
128: /**
129: * Extends the remaining name (remainingName) with all components of the
130: * specified name. The name argument may be null, but this leaves the
131: * remaining name unmodified.
132: *
133: * @param n
134: * the name to be added to the remaining name A null leaves the
135: * remaining name unmodified.
136: */
137: public void appendRemainingName(Name n) {
138: if (null != n) {
139: if (null == this .remainingName) {
140: this .remainingName = (Name) n.clone();
141: } else {
142: try {
143: this .remainingName.addAll(n);
144: } catch (InvalidNameException e) {
145: throw new Error(e.getMessage());
146: }
147: }
148: }
149: }
150:
151: /**
152: * Returns any unresolved portion of the name that was resolved (the
153: * remaining name). The returned <code>Name</code> may be empty, but may
154: * not be null.
155: *
156: * @return any unresolved portion of the name that was resolved (the
157: * remaining name).
158: */
159: public Name getRemainingName() {
160: return this .remainingName;
161: }
162:
163: /**
164: * Returns the non-null object that was resolved (resolved object).
165: *
166: * @return the non-null object that was resolved (resolved object).
167: */
168: public Object getResolvedObj() {
169: return this .resolvedObj;
170: }
171:
172: /**
173: * Sets the remaining name (remainingName) to a copy of the specified
174: * <code>Name</code> parameter may be empty, but not null.
175: *
176: * @param n
177: * a name, may be empty, but no null
178: */
179: public void setRemainingName(Name n) {
180: if (null == n) {
181: this .remainingName = null;
182: } else {
183: this .remainingName = (Name) n.clone();
184: }
185: }
186:
187: /**
188: * Sets the resolved object (resolved object) to o which may not be null.
189: *
190: * @param o
191: * an object, may not be null
192: */
193: public void setResolvedObj(Object o) {
194: this.resolvedObj = o;
195: }
196:
197: }
|