KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** To use the ContextContainer interface */
30 import org.objectweb.util.browser.api.Entry;
31 import org.objectweb.util.browser.api.Wrapper;
32 import org.objectweb.util.browser.core.api.ContextContainer;
33 import org.objectweb.util.browser.core.api.Decoder;
34
35 /**
36  * Interceptor for ContextContainer
37  *
38  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
39  * @version 0.1
40  */

41
42 public class ContextContainerDecoderManager
43     implements ContextContainer {
44
45     // ==================================================================
46
//
47
// Internal states.
48
//
49
// ==================================================================
50

51     /** The decoder. */
52     protected Decoder decoder_;
53
54     /** The delegate */
55     protected ContextContainer delegate_;
56
57     // ==================================================================
58
//
59
// Constructors.
60
//
61
// ==================================================================
62

63     // ==================================================================
64
//
65
// Internal methods.
66
//
67
// ==================================================================
68

69     /**
70      * Creates an Entry.
71      *
72      * @param value The value of the entry to create.
73      * @param id The id of the name of the entry to create.
74      *
75      * @return A new Entry.
76      *
77      */

78     protected Entry createEntry(Object JavaDoc value, String JavaDoc id) {
79         return new DefaultEntry(value, new DefaultName(id), this);
80     }
81
82     // ==================================================================
83
//
84
// Public methods for interface Context.
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         Entry e = delegate_.getLocalEntry(name);
95         return (e != null) ? createEntry(decoder_.decode(e.getValue()),e.getName().toString()): null;
96     }
97
98     /**
99      * Returns the value of the entry identify by the given name
100      * @param name The key of the entry
101      * @return The value of the associated entry or null.
102      */

103     public Object JavaDoc getLocalValue(String JavaDoc name){
104         Entry entry = getLocalEntry(name);
105         return entry!=null ? entry.getValue() : null;
106     }
107     
108     /**
109      * Returns an array containing the entries contained by the target context.
110      * @return A new array of entry.
111      */

112     public Entry[] getEntries(){
113         Entry[] entries = delegate_.getEntries();
114         Entry[] decodedEntries = new Entry[entries.length];
115         for (int i = 0; i < entries.length; i++) {
116             if (entries[i] != null)
117                 decodedEntries[i] = createEntry(decoder_.decode(entries[i].getValue()),entries[i].getName().toString());
118         }
119         return decodedEntries;
120     }
121
122     /**
123      *
124      */

125     public void clear() {
126         delegate_.clear();
127     }
128
129     /**
130      *
131      */

132     public int getSize() {
133         return delegate_.getSize();
134     }
135     
136     // ==================================================================
137
//
138
// Additional public methods for Wrapper interface.
139
//
140
// ==================================================================
141

142     /**
143      * Fix the wrapped object
144      *
145      * @param object The object to wrap
146      *
147      */

148     public void setWrapped(Object JavaDoc object) {
149         //((Wrapper)delegate_).setWrapped(decoder_.decode(object));
150
((Wrapper) delegate_).setWrapped(object);
151     }
152
153     /**
154      * Gets the wrapped object
155      *
156      * @return The wrapped object
157      *
158      */

159     public Object JavaDoc getWrapped() {
160         return ((Wrapper) delegate_).getWrapped();
161     }
162
163     // ==================================================================
164
//
165
// Additional public methods for class DefaultContextContainer.
166
//
167
// ==================================================================
168

169     /**
170      * Adds an object into the container.
171      * If an entry with the same id already exists in the container, this one is replaced by the new value.
172      * It decodes the given object and contacts the delegate object to add this entry
173      *
174      * This method does not modify the given id and the given object, But it modifies the target context.
175      *
176      * @param id The name of the entry to be retrieved.
177      * @param object The object to add
178      *
179      */

180     public void addEntry(String JavaDoc id, Object JavaDoc object) {
181         delegate_.addEntry(id, decoder_.decode(object));
182     }
183
184     /**
185      * Removes the object corresponding to the given id from the context
186      * This method modifies the target context.
187      * @param id The name of the entry to be removed.
188      */

189     public void removeEntry(String JavaDoc id) {
190         delegate_.removeEntry(id);
191     }
192
193     // ==================================================================
194
//
195
// Additional public methods.
196
//
197
// ==================================================================
198

199     /**
200      * Fixes the delegate of the decoder
201      */

202     public void setDelegate(ContextContainer context) {
203         delegate_ = context;
204     }
205
206     /**
207      * Fixes the decoder
208      */

209     public void setDecoder(Decoder decoder) {
210         decoder_ = decoder;
211     }
212     
213 }
214
Popular Tags