Merge from mainline.
[official-gcc.git] / libjava / classpath / javax / naming / NameClassPair.java
blob7925d45d8b738244ec3d9dea3397e31dfa09ac8f
1 /* NameClassPair.java --
2 Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.naming;
41 import java.io.Serializable;
43 /**
44 * <code>NameClassPair</code> represents the name-classname mapping pair
45 * of a binding in a context.
46 * <p>
47 * Bindings are mappings of a name to an object and this class is used to
48 * specify the mapping of the name to the class type of the bound object.
49 * As classname the fully qualified classname is used.
50 * </p>
52 * @author Tom Tromey (tromey@redhat.com)
53 * @since 1.3
55 public class NameClassPair implements Serializable
57 private static final long serialVersionUID = 5620776610160863339L;
59 /**
60 * Constructs an instance with the given name and classname.
62 * @param name the name of the binding relative to the target context
63 * (may not be <code>null</code>)
64 * @param className the name of the class. If <code>null</code> the bound
65 * object is also <code>null</code>
67 public NameClassPair (String name, String className)
69 this (name, className, true);
72 /**
73 * Constructs an instance with the given name and classname and a
74 * flag indicating if the name is relative to the target context.
76 * @param name the name of the binding (may not be <code>null</code>)
77 * @param className the name of the class. If <code>null</code> the bound
78 * object is also <code>null</code>
79 * @param isRelative flag indicating if the name is relative or not
81 public NameClassPair (String name, String className, boolean isRelative)
83 this.name = name;
84 this.className = className;
85 this.isRel = isRelative;
88 /**
89 * Returns the classname of the binding.
90 * @return The fully qualified classname or <code>null</code> if the
91 * bound object is null.
93 public String getClassName ()
95 return className;
98 /**
99 * Returns the name of the binding.
100 * @return The name.
102 public String getName ()
104 return name;
108 * Checks whether the name is relative to the target context or not.
109 * @return <code>true</code> if the name is relative,
110 * <code>false</code> otherwise.
112 public boolean isRelative ()
114 return isRel;
118 * Sets the classname of the bound object.
119 * @param name the classname to set (maybe <code>null</code>)
121 public void setClassName (String name)
123 this.className = name;
127 * Sets the name of the binding.
128 * @param name the name to set
130 public void setName (String name)
132 this.name = name;
136 * Sets if the name is relative to the target context.
137 * @param r <code>true</code> to mark as relative
139 public void setRelative (boolean r)
141 this.isRel = r;
145 * Sets the full name for this binding. Setting the full name by this
146 * method is the only way to initialize full names of bindings if
147 * supported by a specific naming system.
149 * @param fullName the full name of this binding. If not set or set to
150 * <code>null</code> the <code>getNameInNamespace()</code> method will
151 * throw an exception
153 * @see #getNameInNamespace()
155 * @since 1.5
157 public void setNameInNamespace(String fullName)
159 this.fullName = fullName;
163 * Returns the full name for this binding. The full name of a binding is
164 * defined as the absolute name in its own namespace and is not valid
165 * outside.
167 * @return The full name in the bindings namespace.
168 * @throws UnsupportedOperationException if no full name is applicable in
169 * the specific naming system.
171 * @see Context#getNameInNamespace()
173 * @since 1.5
175 public String getNameInNamespace()
177 if (this.fullName == null)
178 throw new UnsupportedOperationException();
180 return this.fullName;
184 * Returns the string representation.
185 * @return The string <code>getName() + ":" + getClassName()</code>.
187 public String toString ()
189 // Specified by class documentation.
190 return name + ":" + className;
193 // These field names are fixed by the serialization spec.
194 private String name;
195 private String className;
196 private boolean isRel;
197 private String fullName;