KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > naming > lib > DefaultEntry


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.explorer.core.naming.lib;
28
29 import org.objectweb.util.explorer.ExplorerUtils;
30 import org.objectweb.util.explorer.api.Context;
31 import org.objectweb.util.explorer.api.Entry;
32
33
34 /**
35  * Default basic implementation of the Entry interface.
36  *
37  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
38  * @version 0.1
39  */

40 public class DefaultEntry
41   implements Entry
42 {
43
44     // ==================================================================
45
//
46
// Internal states.
47
//
48
// ==================================================================
49

50     /** The name. */
51     protected Object JavaDoc name_;
52         
53     /** The value. */
54     protected Object JavaDoc value_;
55
56     /** The wrapper*/
57     protected Context wrapper_;
58     
59     // ==================================================================
60
//
61
// Constructors.
62
//
63
// ==================================================================
64

65     /**
66      * Constructs a DefaultEntry with a name and value.
67      *
68      * This constructor sets the name and value
69      * to respectively the given name and value.
70      *
71      * @param name The name.
72      * @param value The value.
73      *
74      * @postcondition
75      * getName() == name
76      * and getValue() == value
77      */

78     public DefaultEntry(Object JavaDoc name, Object JavaDoc value) {
79         // Inits the internal state.
80
name_ = name;
81         setValue(value);
82     }
83     
84     // ==================================================================
85
//
86
// Internal methods.
87
//
88
// ==================================================================
89

90     protected boolean equals(DefaultEntry entry){
91         if (entry!=null){
92             return (this==entry)
93                 || (ExplorerUtils.compareObjects(name_, entry.name_)
94                 && ExplorerUtils.compareObjects(value_, entry.value_));
95         }
96         return false;
97     }
98     
99     // ==================================================================
100
//
101
// Public methods for interface Entry.
102
//
103
// ==================================================================
104

105     /* (non-Javadoc)
106      * @see org.objectweb.util.explorer.api.Entry#getValue()
107      */

108     public Object JavaDoc getValue() {
109         return value_;
110     }
111     
112     /* (non-Javadoc)
113      * @see org.objectweb.util.explorer.api.Entry#setName()
114      */

115     public void setName(Object JavaDoc name) {
116         this.name_ = name;
117     }
118     
119     /* (non-Javadoc)
120      * @see org.objectweb.util.explorer.api.Entry#setValue(java.lang.Object)
121      */

122     public void setValue(Object JavaDoc value) {
123         this.value_ = value;
124         if(value!=null && value instanceof Context){
125             wrapper_ = (Context)value;
126         }
127     }
128     
129     /* (non-Javadoc)
130      * @see org.objectweb.util.explorer.api.Entry#getName()
131      */

132     public Object JavaDoc getName() {
133         return name_;
134     }
135
136     /* (non-Javadoc)
137      * @see org.objectweb.util.explorer.api.Entry#getWrapper()
138      */

139     public Context getWrapper() {
140         return wrapper_;
141     }
142     
143     /* (non-Javadoc)
144      * @see org.objectweb.util.explorer.api.Entry#setWrapper(org.objectweb.util.explorer.api.Context)
145      */

146     public void setWrapper(Context wrapper) {
147         this.wrapper_ = wrapper;
148     }
149     
150     // ==================================================================
151
//
152
// Public methods surcharging Object class.
153
//
154
// ==================================================================
155

156     /**
157      * Surcharging the Object.equals method.
158      * Tests if a given object is equals to the target entry.
159      *
160      * @param o The given object.
161      *
162      * @return
163      * true if the given entry is the same object as the target entry,
164      * or if it is an Entry instance and the name and value
165      * of the given entry are equals to the name and value
166      * of the target entry;
167      * false otherwise.
168      * `
169      * @see DefaultKey#equals(DefaultKey)
170      */

171     public boolean equals(Object JavaDoc o){
172         if(o!=null && o instanceof DefaultEntry)
173             return equals((DefaultEntry)o);
174         return false;
175     }
176     
177     /**
178      * Return a String representation of a BasicItemDescription
179      */

180     public String JavaDoc toString(){
181         return "DefaultEntry[" +
182                 "name=" + ExplorerUtils.toString(name_) +
183                 ", value=" + value_ +
184                 "]";
185     }
186
187     /**
188      * Returns a hash code value for the object.
189      * @see java.lang.Object#hashCode()
190      */

191     public int hashCode(){
192        return ExplorerUtils.getHashCode(name_)
193            + ExplorerUtils.getHashCode(value_);
194     }
195 }
196
Popular Tags