001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.naming;
019:
020: /**
021: * Binding extends <code>NameClassPair</code> to associate an object in a
022: * naming service with its name, specified class name and relative flag. As with
023: * <code>NameClassPair</code>, a class name is only specified when it is
024: * necessary to override the real class name of the associated object.
025: * <p>
026: * Multithreaded access to a <code>Binding</code> instance is only safe when
027: * client code locks the object first.
028: * </p>
029: */
030: public class Binding extends NameClassPair {
031:
032: private static final long serialVersionUID = 8839217842691845890L;
033:
034: private Object boundObj;
035:
036: /**
037: * Construct a <code>Binding</code> from a name and a class. Relative flag
038: * is true.
039: *
040: * @param name
041: * a name, may not be <code>null</code>.
042: * @param obj
043: * an object bound with the name, may be <code>null</code>.
044: */
045: public Binding(String name, Object obj) {
046: this (name, null, obj, true);
047: }
048:
049: /**
050: * Construct a <code>Binding</code> from a name, an object and a relative
051: * flag.
052: *
053: * @param name
054: * a name, which may not be <code>null</code>.
055: * @param obj
056: * an object bound with the name, may be <code>null</code>.
057: * @param relative
058: * a relative flag
059: */
060: public Binding(String name, Object obj, boolean relative) {
061: this (name, null, obj, relative);
062: }
063:
064: /**
065: * Construct a <code>Binding</code> from a name, a class, and an object.
066: * The class and object parameters may be null. Relative flag is true.
067: *
068: * @param name
069: * a name, which may not be <code>null</code>.
070: * @param className
071: * a class name, may be <code>null</code>.
072: * @param obj
073: * an object bound with the name, may be <code>null</code>.
074: */
075: public Binding(String name, String className, Object obj) {
076: this (name, className, obj, true);
077: }
078:
079: /**
080: * Construct a <code>Binding</code> from a name, a class, an object and a
081: * relative flag. The class and object parameters may be null.
082: *
083: * @param name
084: * a name, which may not be <code>null</code>.
085: * @param className
086: * a class name, may be <code>null</code>.
087: * @param obj
088: * an object bound with the name, may be <code>null</code>.
089: * @param relative
090: * a relative flag
091: */
092: public Binding(String name, String className, Object obj,
093: boolean relative) {
094: super (name, className, relative);
095: this .boundObj = obj;
096: }
097:
098: /**
099: * Get the class name of this <code>Binding</code>. It may have been
100: * specified, in which case the class name field is set, and that is the
101: * string returned by this method. If the class name field has not been
102: * specified then the object associated with this <code>Binding</code> is
103: * interrogated to find its actual class name. If there is no class name
104: * field specified and no associated object then this method returns null.
105: *
106: * @return the class name
107: */
108: @Override
109: public String getClassName() {
110: if (super .getClassName() != null) {
111: return super .getClassName();
112: }
113: if (boundObj != null) {
114: return boundObj.getClass().getName();
115: }
116: return null;
117: }
118:
119: /**
120: * Get the object associated with this <code>Binding</code>. May return
121: * null.
122: *
123: * @return the object associated with this <code>Binding</code>. May
124: * return null.
125: */
126: public Object getObject() {
127: return boundObj;
128: }
129:
130: /**
131: * Set the object o associated with this <code>Binding</code>. The object
132: * may be null.
133: *
134: * @param object
135: * an object
136: */
137: public void setObject(Object object) {
138: this .boundObj = object;
139: }
140:
141: /**
142: * Provide a string representation of this object. This is the same as for
143: * <code>NameClassPair</code> but with the string representation of the
144: * <code>Binding</code> object appended to the end.
145: *
146: * @return a string representation of this <code>Binding</code>
147: */
148: @Override
149: public String toString() {
150: return super .toString() + ":" + boundObj; //$NON-NLS-1$
151: }
152:
153: }
|