Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/naming/spi/ResolveResult.java
38918 views
/*1* Copyright (c) 1999, 2004, 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*/52protected Object resolvedObj;53/**54* Field containing the remaining name yet to be resolved.55* It can be null only when constructed using a subclass.56* Constructors should always initialize this.57* @serial58*/59protected Name remainingName;6061/**62* Constructs an instance of ResolveResult with the63* resolved object and remaining name both initialized to null.64*/65protected ResolveResult() {66resolvedObj = null;67remainingName = null;68}6970/**71* Constructs a new instance of ResolveResult consisting of72* the resolved object and the remaining unresolved component.73*74* @param robj The non-null object resolved to.75* @param rcomp The single remaining name component that has yet to be76* resolved. Cannot be null (but can be empty).77*/78public ResolveResult(Object robj, String rcomp) {79resolvedObj = robj;80try {81remainingName = new CompositeName(rcomp);82// remainingName.appendComponent(rcomp);83} catch (InvalidNameException e) {84// ignore; shouldn't happen85}86}8788/**89* Constructs a new instance of ResolveResult consisting of90* the resolved Object and the remaining name.91*92* @param robj The non-null Object resolved to.93* @param rname The non-null remaining name that has yet to be resolved.94*/95public ResolveResult(Object robj, Name rname) {96resolvedObj = robj;97setRemainingName(rname);98}99100/**101* Retrieves the remaining unresolved portion of the name.102*103* @return The remaining unresolved portion of the name.104* Cannot be null but empty OK.105* @see #appendRemainingName106* @see #appendRemainingComponent107* @see #setRemainingName108*/109public Name getRemainingName() {110return this.remainingName;111}112113/**114* Retrieves the Object to which resolution was successful.115*116* @return The Object to which resolution was successful. Cannot be null.117* @see #setResolvedObj118*/119public Object getResolvedObj() {120return this.resolvedObj;121}122123/**124* Sets the remaining name field of this result to name.125* A copy of name is made so that modifying the copy within126* this ResolveResult does not affect <code>name</code> and127* vice versa.128*129* @param name The name to set remaining name to. Cannot be null.130* @see #getRemainingName131* @see #appendRemainingName132* @see #appendRemainingComponent133*/134public void setRemainingName(Name name) {135if (name != null)136this.remainingName = (Name)(name.clone());137else {138// ??? should throw illegal argument exception139this.remainingName = null;140}141}142143/**144* Adds components to the end of remaining name.145*146* @param name The components to add. Can be null.147* @see #getRemainingName148* @see #setRemainingName149* @see #appendRemainingComponent150*/151public void appendRemainingName(Name name) {152// System.out.println("appendingRemainingName: " + name.toString());153// Exception e = new Exception();154// e.printStackTrace();155if (name != null) {156if (this.remainingName != null) {157try {158this.remainingName.addAll(name);159} catch (InvalidNameException e) {160// ignore; shouldn't happen for composite name161}162} else {163this.remainingName = (Name)(name.clone());164}165}166}167168/**169* Adds a single component to the end of remaining name.170*171* @param name The component to add. Can be null.172* @see #getRemainingName173* @see #appendRemainingName174*/175public void appendRemainingComponent(String name) {176if (name != null) {177CompositeName rname = new CompositeName();178try {179rname.add(name);180} catch (InvalidNameException e) {181// ignore; shouldn't happen for empty composite name182}183appendRemainingName(rname);184}185}186187/**188* Sets the resolved Object field of this result to obj.189*190* @param obj The object to use for setting the resolved obj field.191* Cannot be null.192* @see #getResolvedObj193*/194public void setResolvedObj(Object obj) {195this.resolvedObj = obj;196// ??? should check for null?197}198199private static final long serialVersionUID = -4552108072002407559L;200}201202203