KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > 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.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.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.fractal.explorer.FcExplorer;
38 import org.objectweb.util.explorer.api.Context;
39 import org.objectweb.util.explorer.api.Entry;
40 import org.objectweb.util.explorer.core.common.api.ContextContainer;
41 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry;
42
43 /**
44  * Component context for user role.
45  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
46  * @version 0.1
47  */

48 public class ComponentContextForService
49   implements Context
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     /** This Context Container contains the controller interfaces. */
58     protected ContextContainer controllers_ = null;
59     
60     // ==================================================================
61
//
62
// No Constructors.
63
//
64
// ==================================================================
65

66     // ==================================================================
67
//
68
// Internal methods.
69
//
70
// ==================================================================
71

72     /**
73      * Return true if the given Interface is a Client interface.
74      */

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

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

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

101     /**
102      * Returns an array containing the entries contained by the target context.
103      * @return A new array of entry.
104      */

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