KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > common > lib > DefaultContextContainer


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 package org.objectweb.util.explorer.core.common.lib;
27
28 import java.util.Enumeration JavaDoc;
29
30 import org.objectweb.util.explorer.api.Entry;
31 import org.objectweb.util.explorer.core.common.api.ContextContainer;
32
33 /**
34  *
35  *
36  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
37  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
38  *
39  * @version 0.1
40  */

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

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

58     // ==================================================================
59
//
60
// Internal methods.
61
//
62
// ==================================================================
63

64     /**
65      * Removes the object corresponding to the given id from the context
66      * This method modifies the target context.
67      * @param name The name of the entry to be removed.
68      */

69     protected void remove(Object JavaDoc name){
70         Entry oldEntry = getEntry(name);
71         if (oldEntry != null) {
72             elements_.remove(oldEntry);
73         }
74     }
75     
76     // ==================================================================
77
//
78
// Public methods for ContextContainer interface.
79
//
80
// ==================================================================
81

82     /* (non-Javadoc)
83      * @see org.objectweb.util.explorer.core.common.api.ContextContainer#addEntry(java.lang.Object, java.lang.Object)
84      */

85     public void addEntry(Object JavaDoc name, Object JavaDoc value) {
86         if (value != null) {
87             remove(name);
88             elements_.add(createEntry(name, value));
89         }
90     }
91
92     /* (non-Javadoc)
93      * @see org.objectweb.util.explorer.core.common.api.ContextContainer#addEntry(org.objectweb.util.explorer.api.Entry)
94      */

95     public void addEntry(Entry entry){
96         if (entry != null) {
97             remove(entry.getName());
98             elements_.add(entry);
99         }
100     }
101
102     /* (non-Javadoc)
103      * @see org.objectweb.util.explorer.core.common.api.ContextContainer#getEntry(java.lang.Object)
104      */

105     public Entry getEntry(Object JavaDoc name) {
106         for (Enumeration JavaDoc e = elements_.elements(); e.hasMoreElements();) {
107             Entry entry = (Entry) e.nextElement();
108             if (entry.getName().toString().equals(name)) {
109                 return entry;
110             }
111         }
112         return null;
113     }
114     
115     /* (non-Javadoc)
116      * @see org.objectweb.util.explorer.core.common.api.ContextContainer#removeEntry(java.lang.Object)
117      */

118     public void removeEntry(Object JavaDoc name) {
119         remove(name);
120     }
121
122     /* (non-Javadoc)
123      * @see org.objectweb.util.explorer.core.common.api.ContextContainer#clear()
124      */

125     public void clear() {
126         elements_.clear();
127     }
128
129     /* (non-Javadoc)
130      * @see org.objectweb.util.explorer.core.common.api.ContextContainer#getSize()
131      */

132     public int getSize() {
133         return elements_.size();
134     }
135
136 }
137
138
Popular Tags