0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.naming.spi;
0N/A
0N/Aimport javax.naming.Name;
0N/Aimport javax.naming.Context;
0N/Aimport javax.naming.CompositeName;
0N/Aimport javax.naming.InvalidNameException;
0N/A
0N/A/**
0N/A * This class represents the result of resolution of a name.
0N/A * It contains the object to which name was resolved, and the portion
0N/A * of the name that has not been resolved.
0N/A *<p>
0N/A * A ResolveResult instance is not synchronized against concurrent
0N/A * multithreaded access. Multiple threads trying to access and modify
0N/A * a single ResolveResult instance should lock the object.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A * @since 1.3
0N/A */
0N/Apublic class ResolveResult implements java.io.Serializable {
0N/A /**
0N/A * Field containing the Object that was resolved to successfully.
0N/A * It can be null only when constructed using a subclass.
0N/A * Constructors should always initialize this.
0N/A * @serial
0N/A */
0N/A protected Object resolvedObj;
0N/A /**
0N/A * Field containing the remaining name yet to be resolved.
0N/A * It can be null only when constructed using a subclass.
0N/A * Constructors should always initialize this.
0N/A * @serial
0N/A */
0N/A protected Name remainingName;
0N/A
0N/A /**
0N/A * Constructs an instance of ResolveResult with the
0N/A * resolved object and remaining name both initialized to null.
0N/A */
0N/A protected ResolveResult() {
0N/A resolvedObj = null;
0N/A remainingName = null;
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new instance of ResolveResult consisting of
0N/A * the resolved object and the remaining unresolved component.
0N/A *
0N/A * @param robj The non-null object resolved to.
0N/A * @param rcomp The single remaining name component that has yet to be
0N/A * resolved. Cannot be null (but can be empty).
0N/A */
0N/A public ResolveResult(Object robj, String rcomp) {
0N/A resolvedObj = robj;
0N/A try {
0N/A remainingName = new CompositeName(rcomp);
0N/A// remainingName.appendComponent(rcomp);
0N/A } catch (InvalidNameException e) {
0N/A // ignore; shouldn't happen
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new instance of ResolveResult consisting of
0N/A * the resolved Object and the remaining name.
0N/A *
0N/A * @param robj The non-null Object resolved to.
0N/A * @param rname The non-null remaining name that has yet to be resolved.
0N/A */
0N/A public ResolveResult(Object robj, Name rname) {
0N/A resolvedObj = robj;
0N/A setRemainingName(rname);
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the remaining unresolved portion of the name.
0N/A *
0N/A * @return The remaining unresolved portion of the name.
0N/A * Cannot be null but empty OK.
0N/A * @see #appendRemainingName
0N/A * @see #appendRemainingComponent
0N/A * @see #setRemainingName
0N/A */
0N/A public Name getRemainingName() {
0N/A return this.remainingName;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the Object to which resolution was successful.
0N/A *
0N/A * @return The Object to which resolution was successful. Cannot be null.
0N/A * @see #setResolvedObj
0N/A */
0N/A public Object getResolvedObj() {
0N/A return this.resolvedObj;
0N/A }
0N/A
0N/A /**
0N/A * Sets the remaining name field of this result to name.
0N/A * A copy of name is made so that modifying the copy within
0N/A * this ResolveResult does not affect <code>name</code> and
0N/A * vice versa.
0N/A *
0N/A * @param name The name to set remaining name to. Cannot be null.
0N/A * @see #getRemainingName
0N/A * @see #appendRemainingName
0N/A * @see #appendRemainingComponent
0N/A */
0N/A public void setRemainingName(Name name) {
0N/A if (name != null)
0N/A this.remainingName = (Name)(name.clone());
0N/A else {
0N/A // ??? should throw illegal argument exception
0N/A this.remainingName = null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds components to the end of remaining name.
0N/A *
0N/A * @param name The components to add. Can be null.
0N/A * @see #getRemainingName
0N/A * @see #setRemainingName
0N/A * @see #appendRemainingComponent
0N/A */
0N/A public void appendRemainingName(Name name) {
0N/A// System.out.println("appendingRemainingName: " + name.toString());
0N/A// Exception e = new Exception();
0N/A// e.printStackTrace();
0N/A if (name != null) {
0N/A if (this.remainingName != null) {
0N/A try {
0N/A this.remainingName.addAll(name);
0N/A } catch (InvalidNameException e) {
0N/A // ignore; shouldn't happen for composite name
0N/A }
0N/A } else {
0N/A this.remainingName = (Name)(name.clone());
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds a single component to the end of remaining name.
0N/A *
0N/A * @param name The component to add. Can be null.
0N/A * @see #getRemainingName
0N/A * @see #appendRemainingName
0N/A */
0N/A public void appendRemainingComponent(String name) {
0N/A if (name != null) {
0N/A CompositeName rname = new CompositeName();
0N/A try {
0N/A rname.add(name);
0N/A } catch (InvalidNameException e) {
0N/A // ignore; shouldn't happen for empty composite name
0N/A }
0N/A appendRemainingName(rname);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the resolved Object field of this result to obj.
0N/A *
0N/A * @param obj The object to use for setting the resolved obj field.
0N/A * Cannot be null.
0N/A * @see #getResolvedObj
0N/A */
0N/A public void setResolvedObj(Object obj) {
0N/A this.resolvedObj = obj;
0N/A // ??? should check for null?
0N/A }
0N/A
0N/A private static final long serialVersionUID = -4552108072002407559L;
0N/A}