KickJava   Java API By Example, From Geeks To Geeks.

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


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): Philippe Merle, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.naming;
28
29 /** To use the Context interface. */
30 import org.objectweb.util.browser.api.Context;
31 import org.objectweb.util.browser.api.Entry;
32 import org.objectweb.util.browser.api.Wrapper;
33 import org.objectweb.util.browser.core.api.Decoder;
34
35 /**
36  * Basic implementation of the Context interface
37  * for intercepting message
38  *
39  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
40  * @version 0.1
41  */

42 public class ContextDecoderManager
43     implements Context, Wrapper {
44     
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50

51     /** The decoder. */
52     protected Decoder decoder_;
53
54     /** The delegate */
55     protected Context 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 an array containing the entries contained by the target context.
90      * @return A new array of entry.
91      */

92     public Entry[] getEntries(){
93         Entry[] entries = delegate_.getEntries();
94         Entry[] decodedEntries = new Entry[entries.length];
95         for (int i = 0; i < entries.length; i++) {
96             if (entries[i] != null)
97                 decodedEntries[i] = createEntry(decoder_.decode(entries[i].getValue()),entries[i].getName().toString());
98         }
99         return decodedEntries;
100     }
101
102     // ==================================================================
103
//
104
// Additional public methods for Wrapper interface.
105
//
106
// ==================================================================
107

108     /**
109      * Fix the wrapped object
110      *
111      * @param object The object to wrap
112      *
113      */

114     public void setWrapped(Object JavaDoc object) {
115         //((Wrapper)delegate_).setWrapped(decoder_.decode(object));
116
((Wrapper) delegate_).setWrapped(object);
117     }
118
119     /**
120      * Gets the wrapped object
121      *
122      * @return The wrapped object
123      *
124      */

125     public Object JavaDoc getWrapped() {
126         return ((Wrapper) delegate_).getWrapped();
127     }
128
129     // ==================================================================
130
//
131
// Additional public methods.
132
//
133
// ==================================================================
134

135     /**
136      * Fixes the delegate of the decoder
137      */

138     public void setDelegate(Context context) {
139         delegate_ = context;
140     }
141
142     /**
143      * Fixes the decoder
144      */

145     public void setDecoder(Decoder decoder) {
146         decoder_ = decoder;
147     }
148 }
149
Popular Tags