KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > naming > DefaultContextContainer


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@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.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.naming;
28
29 /** The AdminConsole's imports */
30 import java.util.Enumeration JavaDoc;
31
32 import org.objectweb.util.browser.api.Entry;
33 import org.objectweb.util.browser.core.api.ContextContainer;
34
35 /**
36  * Basic implementation of the Context interface
37  *
38  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
39  * @version 0.1
40  */

41 public class DefaultContextContainer
42     extends DefaultContext
43     implements ContextContainer {
44
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     // ==================================================================
52
//
53
// Constructors.
54
//
55
// ==================================================================
56

57     /**
58      * Empty contstructor
59      */

60     public DefaultContextContainer() {
61         super();
62     }
63
64     // ==================================================================
65
//
66
// Internal methods.
67
//
68
// ==================================================================
69

70     /**
71      * Removes the object corresponding to the given id from the context
72      * This method modifies the target context.
73      * @param id The name of the entry to be removed.
74      */

75     protected void remove(String JavaDoc id){
76         Entry oldEntry = getLocalEntry(id);
77         if (oldEntry != null) {
78             elts_.remove(oldEntry);
79         }
80     }
81     
82     // ==================================================================
83
//
84
// Additional public methods for class DefaultContextContainer.
85
//
86
// ==================================================================
87

88     /**
89      * Returns the entry identify by the given name
90      * @param name The key of the entry
91      * @return The associated entry or null.
92      */

93     public Entry getLocalEntry(String JavaDoc name) {
94         for (Enumeration JavaDoc e = elts_.elements(); e.hasMoreElements();) {
95             Entry entry = (Entry) e.nextElement();
96             if (entry.getName().toString().equals(name)) {
97                 return entry;
98             }
99         }
100         return null;
101     }
102
103     /**
104      * Returns the value of the entry identify by the given name
105      * @param name The key of the entry
106      * @return The value of the associated entry or null.
107      */

108     public Object JavaDoc getLocalValue(String JavaDoc name){
109         Entry entry = getLocalEntry(name);
110         return entry!=null ? entry.getValue() : null;
111     }
112
113     /**
114      * Adds an object into the container.
115      * If an entry with the same id already exists in the container, this one is replaced by the new value.
116      *
117      * This method does not modify the given id and the given object, But it modifies the target context.
118      *
119      * @param id The name of the entry to be retrieved.
120      * @param object The object to add
121      *
122      */

123     public void addEntry(String JavaDoc id, Object JavaDoc object) {
124         if (object != null) {
125             remove(id);
126             elts_.add(createEntry(object, id));
127         }
128     }
129
130     /**
131      * Removes the object corresponding to the given id from the context
132      * This method modifies the target context.
133      * @param id The name of the entry to be removed.
134      */

135     public void removeEntry(String JavaDoc id) {
136         remove(id);
137     }
138
139     /**
140      * Removes all of the elements from this context.
141      */

142     public void clear(){
143         elts_.clear();
144     }
145     
146     /**
147      * Provides the number of entries contained within the InitialContext.
148      * @return
149      */

150     public int
151     getSize(){
152         return elts_.size();
153     }
154    
155 }
156
Popular Tags