KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > context > ComponentContextForService


1 /*====================================================================
2  
3  Objectweb Browser 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.
23  Contributor(s): ______________________________________.
24  
25  ---------------------------------------------------------------------
26  $Id: ComponentContextForService.java,v 1.1 2004/04/20 16:37:26 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.util.browser.plugins.fractal.context;
30
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33
34 import org.objectweb.fractal.api.Component;
35 import org.objectweb.fractal.api.Interface;
36 import org.objectweb.fractal.api.type.InterfaceType;
37 import org.objectweb.util.browser.api.Entry;
38 import org.objectweb.util.browser.core.api.ContextContainer;
39 import org.objectweb.util.browser.core.naming.AbstractContext;
40 import org.objectweb.util.browser.core.naming.DefaultEntry;
41 import org.objectweb.util.browser.core.naming.DefaultName;
42 import org.objectweb.util.browser.plugins.fractal.FcBrowser;
43
44 /**
45  * Component context for user role.
46  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
47  * @version 0.1
48  */

49 public class ComponentContextForService
50      extends AbstractContext
51 {
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57

58     /** The Component. */
59     protected Component ci_ = null;
60     
61     /** This Context Container contains the controller interfaces. */
62     protected ContextContainer controllers_ = null;
63     
64     // ==================================================================
65
//
66
// No Constructors.
67
//
68
// ==================================================================
69

70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     /**
77      * Return true if the given Interface is a Client interface.
78      */

79     protected boolean isClient(Interface ir) {
80         InterfaceType it = (InterfaceType) ir.getFcItfType();
81         return it.isFcClientItf();
82     }
83     
84     /**
85      * Return true if the given Interface is a Collection Client interface.
86      */

87     protected boolean isClientCollection(Interface ir) {
88         InterfaceType it = (InterfaceType)ir.getFcItfType();
89         return (it.isFcClientItf() && it.isFcCollectionItf());
90     }
91     
92     /**
93      * Return true if the given Interface is a Control interface.
94      */

95     protected boolean isController(Interface itf) {
96         return (itf.getFcItfName().endsWith("-controller")||itf.getFcItfName().endsWith("factory"));
97     }
98     
99     // ==================================================================
100
//
101
// Public methods for interface Context.
102
//
103
// ==================================================================
104

105     /**
106      * Returns an array containing the entries contained by the target context.
107      * @return A new array of entry.
108      */

109     public Entry[] getEntries() {
110         Hashtable JavaDoc collectionInterfaces = new Hashtable JavaDoc();
111         java.util.List JavaDoc values = new java.util.ArrayList JavaDoc();
112         
113         controllers_ = new ControllerContainer();
114         Object JavaDoc[] fcItfs = (Object JavaDoc[])ci_.getFcInterfaces();
115         
116         for (int i=0 ; i<fcItfs.length ; i++) {
117             if (!ci_.equals(fcItfs[i])) {
118                 Interface itf = (Interface)fcItfs[i];
119                 if (isController(itf)) {
120                     controllers_.addEntry(FcBrowser.getName(itf),itf);
121                 } else if (isClientCollection(itf)) {
122                     InterfaceType it = (InterfaceType)itf.getFcItfType();
123                     String JavaDoc name = FcBrowser.getName(itf);
124                     if(!collectionInterfaces.containsKey(it.getFcItfName())){
125                         ContextContainer cc = new ClientCollectionInterfaceContainer(itf);
126                         cc.addEntry(name,new ClientCollectionInterfaceWrapper(itf));
127                         collectionInterfaces.put(it.getFcItfName(),cc);
128                     } else {
129                         ((ContextContainer)collectionInterfaces.get(it.getFcItfName())).addEntry(name,
130                                                                                                  new ClientInterfaceWrapper(itf));
131                     }
132                 } else if(isClient(itf)) {
133                     values.add(new DefaultEntry(new ClientInterfaceWrapper(itf),
134                                                 new DefaultName(FcBrowser.getName(itf)),
135                                                 this));
136                 } else {
137                     values.add(new DefaultEntry(itf,
138                                                 new DefaultName(FcBrowser.getName(itf)),
139                                                 this));
140                 }
141             }
142         }
143         // Add the collection interfaces
144
Enumeration JavaDoc keys,elements;
145         keys = collectionInterfaces.keys();
146         elements = collectionInterfaces.elements();
147         for (int i = 0 ; i < collectionInterfaces.size() ; i++) {
148             values.add(createEntry(elements.nextElement(),(String JavaDoc) keys.nextElement()));
149         }
150         
151         return (Entry[])values.toArray(new Entry[0]);
152     }
153     
154     // ==================================================================
155
//
156
// Additional public methods for Wrapper interface.
157
//
158
// ==================================================================
159

160     /**
161      * Fix the wrapped object.
162      * @param object The object to wrap.
163      */

164     public void setWrapped(Object JavaDoc object) {
165         ci_ = (Component) object;
166     }
167     
168     /**
169      * Gets the wrapped object.
170      * @return The wrapped object.
171      */

172     public Object JavaDoc getWrapped() {
173         return ci_;
174     }
175     
176 }
177
178
179
180
181
182
183
Popular Tags