KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > panel > ComponentTable


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: ComponentTable.java,v 1.1 2004/04/20 16:37:27 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.util.browser.plugins.fractal.panel;
30
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Vector JavaDoc;
34
35 import org.objectweb.fractal.api.Component;
36 import org.objectweb.fractal.api.Interface;
37 import org.objectweb.fractal.api.NoSuchInterfaceException;
38 import org.objectweb.fractal.api.control.BindingController;
39 import org.objectweb.fractal.api.type.InterfaceType;
40 import org.objectweb.util.browser.api.Entry;
41 import org.objectweb.util.browser.api.Table;
42 import org.objectweb.util.browser.api.TreeView;
43 import org.objectweb.util.browser.core.api.ContextContainer;
44 import org.objectweb.util.browser.core.naming.DefaultEntry;
45 import org.objectweb.util.browser.core.naming.DefaultName;
46 import org.objectweb.util.browser.plugins.fractal.FcBrowser;
47 import org.objectweb.util.browser.plugins.fractal.context.ClientCollectionInterfaceContainer;
48 import org.objectweb.util.browser.plugins.fractal.context.ClientInterfaceWrapper;
49 import org.objectweb.util.browser.plugins.fractal.lib.SignatureWrapper;
50
51 /**
52  * Displays the available business interfaces of a component.
53  *
54  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
55  *
56  * @version 0.1
57  */

58 public class ComponentTable
59   implements Table
60 {
61     
62     //==================================================================
63
//
64
// Internal states.
65
//
66
//==================================================================
67

68     //==================================================================
69
//
70
// No constructor.
71
//
72
//==================================================================
73

74     // ==================================================================
75
//
76
// Internal methods.
77
//
78
// ==================================================================
79

80     /**
81      * Return true if the given Interface is a Client interface.
82      */

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

91     protected boolean isClientCollectionType(Interface ir) {
92         InterfaceType it = (InterfaceType)ir.getFcItfType();
93         return (it.isFcClientItf() && it.isFcCollectionItf());
94     }
95     
96     /**
97      * Return true if the given Interface is a Control interface.
98      */

99     protected boolean isControlInterface(Interface itf) {
100         return itf.getFcItfName().endsWith("-controller");
101     }
102     
103     /**
104      * Provides the bound interface of the given client interface.
105      */

106     protected Entry getBoundInterface(Interface itf, BindingController bc){
107         if(bc!=null) {
108             try {
109                 Interface bindInterface = (Interface)bc.lookupFc(itf.getFcItfName());
110                 if(bindInterface!=null)
111                     return new DefaultEntry(bindInterface,
112                                             new DefaultName(FcBrowser.getPrefixedName(bindInterface)));
113             } catch(NoSuchInterfaceException e) {
114                 return null;
115             }
116         }
117         return null;
118     }
119     
120     //==================================================================
121
//
122
// Public methods for Table interface.
123
//
124
//==================================================================
125

126     /**
127      * Overriding methods
128      * @see org.objectweb.util.browser.api.Table#getHeaders()
129      */

130     public String JavaDoc[] getHeaders(TreeView treeView) {
131         return new String JavaDoc[] {"Interface", "Type", "Connected"};
132     }
133     
134     /**
135      * Overriding methods
136      * @see org.objectweb.util.browser.api.Table#getRows(org.objectweb.util.browser.api.TreeView)
137      */

138     public Object JavaDoc[][] getRows(TreeView treeView) {
139         Hashtable JavaDoc collectionInterfaces = new Hashtable JavaDoc();
140         Vector JavaDoc values = new Vector JavaDoc();
141         
142         Component comp = (Component)treeView.getSelectedObject();
143         BindingController bc = null;
144         try{
145             bc = FcBrowser.getBindingController(comp);
146         } catch(Exception JavaDoc e) {
147             System.err.println("Client interface Error : " + e.getMessage());
148         }
149         
150         Object JavaDoc[] objects = (Object JavaDoc[])comp.getFcInterfaces();
151         for (int i = 0; i < objects.length; i++){
152             if(!comp.equals(objects[i])){
153                 Interface itf = (Interface)objects[i];
154                 if (!isControlInterface(itf)) {
155                     String JavaDoc sign = ((InterfaceType)itf.getFcItfType()).getFcItfSignature();
156                     InterfaceType it = (InterfaceType)itf.getFcItfType();
157                     if (isClientCollectionType(itf)) {
158                         String JavaDoc name = FcBrowser.getName(it);
159                         if(!collectionInterfaces.containsKey(it.getFcItfName())){
160                             ContextContainer cc = new ClientCollectionInterfaceContainer(itf);
161                             cc.addEntry(name,new TableClientCollectionWrapper(itf));
162                             collectionInterfaces.put(it.getFcItfName(),cc);
163                         } else {
164                             ((ContextContainer)collectionInterfaces.get(it.getFcItfName())).addEntry(name,new TableClientCollectionWrapper(itf));
165                         }
166                     } else if(isClientType(itf)) {
167                         values.add(new Object JavaDoc[] {new DefaultEntry(new ClientInterfaceWrapper(itf),
168                                                                   new DefaultName(FcBrowser.getName(it))),
169                                                  new DefaultEntry(new SignatureWrapper(sign),
170                                                                   new DefaultName(sign)),
171                                                  getBoundInterface(itf,bc)});
172                     } else {
173                         values.add(new Object JavaDoc[] {new DefaultEntry(itf,
174                                                                   new DefaultName(FcBrowser.getName(it))),
175                                                  new DefaultEntry(new SignatureWrapper(sign),
176                                                                   new DefaultName(sign)),
177                                                  null});
178                     }
179                 }
180             }
181         }
182         // Add the collection interfaces
183
Enumeration JavaDoc keys,elements;
184         keys = collectionInterfaces.keys();
185         elements = collectionInterfaces.elements();
186         for (int i = 0 ; i < collectionInterfaces.size() ; i++) {
187             ClientCollectionInterfaceContainer itfcc = (ClientCollectionInterfaceContainer)elements.nextElement();
188             Entry[] entries = itfcc.getEntries();
189             for(int j = 0 ; j < entries.length ; j++) {
190                 Interface itf = ((TableClientCollectionWrapper)entries[j].getValue()).getItf();
191                 String JavaDoc sign = ((InterfaceType)itfcc.getItf().getFcItfType()).getFcItfSignature();
192                 values.add(new Object JavaDoc[]{entries[j],
193                         new DefaultEntry(new SignatureWrapper(sign),
194                                 new DefaultName(sign)),
195                                 getBoundInterface(itf,bc)});
196             }
197         }
198         
199         Object JavaDoc[][] contenu = new Object JavaDoc[values.size()][2];
200         for(int i=0 ; i<values.size() ; i++)
201             contenu[i] = (Object JavaDoc[])values.get(i);
202         return contenu;
203     }
204 }
205
Popular Tags