0N/A/*
2362N/A * Copyright (c) 1999, 2003, 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;
0N/A
0N/A/**
0N/A * This class represents the object name and class name pair of a binding
0N/A * found in a context.
0N/A *<p>
0N/A * A context consists of name-to-object bindings.
0N/A * The NameClassPair class represents the name and the
0N/A * class of the bound object. It consists
0N/A * of a name and a string representing the
0N/A * package-qualified class name.
0N/A *<p>
0N/A * Use subclassing for naming systems that generate contents of
0N/A * a name/class pair dynamically.
0N/A *<p>
0N/A * A NameClassPair instance is not synchronized against concurrent
0N/A * access by multiple threads. Threads that need to access a NameClassPair
0N/A * concurrently should synchronize amongst themselves and provide
0N/A * the necessary locking.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A *
0N/A * @see Context#list
0N/A * @since 1.3
0N/A */
0N/A
0N/A /*
0N/A * <p>
0N/A * The serialized form of a NameClassPair object consists of the name (a
0N/A * String), class name (a String), and isRelative flag (a boolean).
0N/A */
0N/A
0N/Apublic class NameClassPair implements java.io.Serializable {
0N/A /**
0N/A * Contains the name of this NameClassPair.
0N/A * It is initialized by the constructor and can be updated using
0N/A * <tt>setName()</tt>.
0N/A * @serial
0N/A * @see #getName
0N/A * @see #setName
0N/A */
0N/A private String name;
0N/A
0N/A /**
0N/A *Contains the class name contained in this NameClassPair.
0N/A * It is initialized by the constructor and can be updated using
0N/A * <tt>setClassName()</tt>.
0N/A * @serial
0N/A * @see #getClassName
0N/A * @see #setClassName
0N/A */
0N/A private String className;
0N/A
0N/A /**
0N/A * Contains the full name of this NameClassPair within its
0N/A * own namespace.
0N/A * It is initialized using <tt>setNameInNamespace()</tt>
0N/A * @serial
0N/A * @see #getNameInNamespace
0N/A * @see #setNameInNamespace
0N/A */
0N/A private String fullName = null;
0N/A
0N/A
0N/A /**
0N/A * Records whether the name of this <tt>NameClassPair</tt>
0N/A * is relative to the target context.
0N/A * It is initialized by the constructor and can be updated using
0N/A * <tt>setRelative()</tt>.
0N/A * @serial
0N/A * @see #isRelative
0N/A * @see #setRelative
0N/A * @see #getName
0N/A * @see #setName
0N/A */
0N/A private boolean isRel = true;
0N/A
0N/A /**
0N/A * Constructs an instance of a NameClassPair given its
0N/A * name and class name.
0N/A *
0N/A * @param name The non-null name of the object. It is relative
0N/A * to the <em>target context</em> (which is
0N/A * named by the first parameter of the <code>list()</code> method)
0N/A * @param className The possibly null class name of the object
0N/A * bound to name. It is null if the object bound is null.
0N/A * @see #getClassName
0N/A * @see #setClassName
0N/A * @see #getName
0N/A * @see #setName
0N/A */
0N/A public NameClassPair(String name, String className) {
0N/A this.name = name;
0N/A this.className = className;
0N/A }
0N/A
0N/A /**
0N/A * Constructs an instance of a NameClassPair given its
0N/A * name, class name, and whether it is relative to the listing context.
0N/A *
0N/A * @param name The non-null name of the object.
0N/A * @param className The possibly null class name of the object
0N/A * bound to name. It is null if the object bound is null.
0N/A * @param isRelative true if <code>name</code> is a name relative
0N/A * to the target context (which is named by the first parameter
0N/A * of the <code>list()</code> method); false if <code>name</code>
0N/A * is a URL string.
0N/A * @see #getClassName
0N/A * @see #setClassName
0N/A * @see #getName
0N/A * @see #setName
0N/A * @see #isRelative
0N/A * @see #setRelative
0N/A */
0N/A public NameClassPair(String name, String className, boolean isRelative) {
0N/A this.name = name;
0N/A this.className = className;
0N/A this.isRel = isRelative;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the class name of the object bound to the name of this binding.
0N/A * If a reference or some other indirect information is bound,
0N/A * retrieves the class name of the eventual object that
0N/A * will be returned by <tt>Binding.getObject()</tt>.
0N/A *
0N/A * @return The possibly null class name of object bound.
0N/A * It is null if the object bound is null.
0N/A * @see Binding#getObject
0N/A * @see Binding#getClassName
0N/A * @see #setClassName
0N/A */
0N/A public String getClassName() {
0N/A return className;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the name of this binding.
0N/A * If <tt>isRelative()</tt> is true, this name is relative to the
0N/A * target context (which is named by the first parameter of the
0N/A * <tt>list()</tt>).
0N/A * If <tt>isRelative()</tt> is false, this name is a URL string.
0N/A *
0N/A * @return The non-null name of this binding.
0N/A * @see #isRelative
0N/A * @see #setName
0N/A */
0N/A public String getName() {
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Sets the name of this binding.
0N/A *
0N/A * @param name the non-null string to use as the name.
0N/A * @see #getName
0N/A * @see #setRelative
0N/A */
0N/A public void setName(String name) {
0N/A this.name = name;
0N/A }
0N/A
0N/A /**
0N/A * Sets the class name of this binding.
0N/A *
0N/A * @param name the possibly null string to use as the class name.
0N/A * If null, <tt>Binding.getClassName()</tt> will return
0N/A * the actual class name of the object in the binding.
0N/A * The class name will be null if the object bound is null.
0N/A * @see #getClassName
0N/A * @see Binding#getClassName
0N/A */
0N/A public void setClassName(String name) {
0N/A this.className = name;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether the name of this binding is
0N/A * relative to the target context (which is named by
0N/A * the first parameter of the <code>list()</code> method).
0N/A *
0N/A * @return true if the name of this binding is relative to the
0N/A * target context;
0N/A * false if the name of this binding is a URL string.
0N/A * @see #setRelative
0N/A * @see #getName
0N/A */
0N/A public boolean isRelative() {
0N/A return isRel;
0N/A }
0N/A
0N/A /**
0N/A * Sets whether the name of this binding is relative to the target
0N/A * context (which is named by the first parameter of the <code>list()</code>
0N/A * method).
0N/A *
0N/A * @param r If true, the name of binding is relative to the target context;
0N/A * if false, the name of binding is a URL string.
0N/A * @see #isRelative
0N/A * @see #setName
0N/A */
0N/A public void setRelative(boolean r) {
0N/A isRel = r;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the full name of this binding.
0N/A * The full name is the absolute name of this binding within
0N/A * its own namespace. See {@link Context#getNameInNamespace()}.
0N/A * <p>
0N/A *
0N/A * In naming systems for which the notion of full name does not
0N/A * apply to this binding an <tt>UnsupportedOperationException</tt>
0N/A * is thrown.
0N/A * This exception is also thrown when a service provider written before
0N/A * the introduction of the method is in use.
0N/A * <p>
0N/A * The string returned by this method is not a JNDI composite name and
0N/A * should not be passed directly to context methods.
0N/A *
0N/A * @return The full name of this binding.
0N/A * @throws UnsupportedOperationException if the notion of full name
0N/A * does not apply to this binding in the naming system.
0N/A * @since 1.5
0N/A * @see #setNameInNamespace
0N/A * @see #getName
0N/A */
0N/A public String getNameInNamespace() {
0N/A if (fullName == null) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A return fullName;
0N/A }
0N/A
0N/A /**
0N/A * Sets the full name of this binding.
0N/A * This method must be called to set the full name whenever a
0N/A * <tt>NameClassPair</tt> is created and a full name is
0N/A * applicable to this binding.
0N/A * <p>
0N/A * Setting the full name to null, or not setting it at all, will
0N/A * cause <tt>getNameInNamespace()</tt> to throw an exception.
0N/A *
0N/A * @param fullName The full name to use.
0N/A * @since 1.5
0N/A * @see #getNameInNamespace
0N/A * @see #setName
0N/A */
0N/A public void setNameInNamespace(String fullName) {
0N/A this.fullName = fullName;
0N/A }
0N/A
0N/A /**
0N/A * Generates the string representation of this name/class pair.
0N/A * The string representation consists of the name and class name separated
0N/A * by a colon (':').
0N/A * The contents of this string is useful
0N/A * for debugging and is not meant to be interpreted programmatically.
0N/A *
0N/A * @return The string representation of this name/class pair.
0N/A */
0N/A public String toString() {
0N/A return (isRelative() ? "" : "(not relative)") + getName() + ": " +
0N/A getClassName();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Use serialVersionUID from JNDI 1.1.1 for interoperability
0N/A */
0N/A private static final long serialVersionUID = 5620776610160863339L;
0N/A}