Path: blob/master/src/java.naming/share/classes/javax/naming/spi/ResolveResult.java
41159 views
/*1* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.spi;2627import javax.naming.Name;28import javax.naming.Context;29import javax.naming.CompositeName;30import javax.naming.InvalidNameException;3132/**33* This class represents the result of resolution of a name.34* It contains the object to which name was resolved, and the portion35* of the name that has not been resolved.36*<p>37* A ResolveResult instance is not synchronized against concurrent38* multithreaded access. Multiple threads trying to access and modify39* a single ResolveResult instance should lock the object.40*41* @author Rosanna Lee42* @author Scott Seligman43* @since 1.344*/45public class ResolveResult implements java.io.Serializable {46/**47* Field containing the Object that was resolved to successfully.48* It can be null only when constructed using a subclass.49* Constructors should always initialize this.50* @serial51*/52@SuppressWarnings("serial") // Not statically typed as Serializable53protected Object resolvedObj;54/**55* Field containing the remaining name yet to be resolved.56* It can be null only when constructed using a subclass.57* Constructors should always initialize this.58* @serial59*/60protected Name remainingName;6162/**63* Constructs an instance of ResolveResult with the64* resolved object and remaining name both initialized to null.65*/66protected ResolveResult() {67resolvedObj = null;68remainingName = null;69}7071/**72* Constructs a new instance of ResolveResult consisting of73* the resolved object and the remaining unresolved component.74*75* @param robj The non-null object resolved to.76* @param rcomp The single remaining name component that has yet to be77* resolved. Cannot be null (but can be empty).78*/79public ResolveResult(Object robj, String rcomp) {80resolvedObj = robj;81try {82remainingName = new CompositeName(rcomp);83// remainingName.appendComponent(rcomp);84} catch (InvalidNameException e) {85// ignore; shouldn't happen86}87}8889/**90* Constructs a new instance of ResolveResult consisting of91* the resolved Object and the remaining name.92*93* @param robj The non-null Object resolved to.94* @param rname The non-null remaining name that has yet to be resolved.95*/96public ResolveResult(Object robj, Name rname) {97resolvedObj = robj;98setRemainingName(rname);99}100101/**102* Retrieves the remaining unresolved portion of the name.103*104* @return The remaining unresolved portion of the name.105* Cannot be null but empty OK.106* @see #appendRemainingName107* @see #appendRemainingComponent108* @see #setRemainingName109*/110public Name getRemainingName() {111return this.remainingName;112}113114/**115* Retrieves the Object to which resolution was successful.116*117* @return The Object to which resolution was successful. Cannot be null.118* @see #setResolvedObj119*/120public Object getResolvedObj() {121return this.resolvedObj;122}123124/**125* Sets the remaining name field of this result to name.126* A copy of name is made so that modifying the copy within127* this ResolveResult does not affect <code>name</code> and128* vice versa.129*130* @param name The name to set remaining name to. Cannot be null.131* @see #getRemainingName132* @see #appendRemainingName133* @see #appendRemainingComponent134*/135public void setRemainingName(Name name) {136if (name != null)137this.remainingName = (Name)(name.clone());138else {139// ??? should throw illegal argument exception140this.remainingName = null;141}142}143144/**145* Adds components to the end of remaining name.146*147* @param name The components to add. Can be null.148* @see #getRemainingName149* @see #setRemainingName150* @see #appendRemainingComponent151*/152public void appendRemainingName(Name name) {153// System.out.println("appendingRemainingName: " + name.toString());154// Exception e = new Exception();155// e.printStackTrace();156if (name != null) {157if (this.remainingName != null) {158try {159this.remainingName.addAll(name);160} catch (InvalidNameException e) {161// ignore; shouldn't happen for composite name162}163} else {164this.remainingName = (Name)(name.clone());165}166}167}168169/**170* Adds a single component to the end of remaining name.171*172* @param name The component to add. Can be null.173* @see #getRemainingName174* @see #appendRemainingName175*/176public void appendRemainingComponent(String name) {177if (name != null) {178CompositeName rname = new CompositeName();179try {180rname.add(name);181} catch (InvalidNameException e) {182// ignore; shouldn't happen for empty composite name183}184appendRemainingName(rname);185}186}187188/**189* Sets the resolved Object field of this result to obj.190*191* @param obj The object to use for setting the resolved obj field.192* Cannot be null.193* @see #getResolvedObj194*/195public void setResolvedObj(Object obj) {196this.resolvedObj = obj;197// ??? should check for null?198}199200private static final long serialVersionUID = -4552108072002407559L;201}202203204