KickJava   Java API By Example, From Geeks To Geeks.

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

28
29 package org.objectweb.fractal.explorer.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.fractal.explorer.FcExplorer;
41 import org.objectweb.fractal.explorer.context.ClientCollectionInterfaceContainer;
42 import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper;
43 import org.objectweb.fractal.explorer.lib.SignatureWrapper;
44 import org.objectweb.util.explorer.api.Entry;
45 import org.objectweb.util.explorer.api.Table;
46 import org.objectweb.util.explorer.api.TreeView;
47 import org.objectweb.util.explorer.core.common.api.ContextContainer;
48 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry;
49
50 /**
51  * Displays the available business interfaces of a component.
52  *
53  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
54  *
55  * @version 0.1
56  */

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

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

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

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

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

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

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

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

124     /* (non-Javadoc)
125      * @see org.objectweb.util.explorer.api.Table#getHeaders(org.objectweb.util.explorer.api.TreeView)
126      */

127     public String JavaDoc[] getHeaders(TreeView treeView) {
128         return new String JavaDoc[] {"Interface", "Type", "Connected"};
129     }
130     
131     /* (non-Javadoc)
132      * @see org.objectweb.util.explorer.api.Table#getRows(org.objectweb.util.explorer.api.TreeView)
133      */

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