KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > Components > RequiredInterfacesTable


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
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
27 package org.objectweb.openccm.explorer.Components;
28
29 import java.util.List JavaDoc;
30 import java.util.Vector JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import org.omg.Components.CCMObject;
34 import org.omg.Components.ComponentPortDescription;
35 import org.omg.Components.ReceptacleDescription;
36 import org.omg.Components.EmitterDescription;
37 import org.omg.Components.PublisherDescription;
38 import org.omg.Components.ConnectionDescription;
39 import org.objectweb.openccm.explorer.CORBA.TypageCORBA;
40 import org.objectweb.openccm.explorer.util.ior.IorPrinter;
41 import org.objectweb.util.explorer.api.Entry;
42 import org.objectweb.util.explorer.api.Table;
43 import org.objectweb.util.explorer.api.TreeView;
44 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry;
45 import org.omg.Components.SubscriberDescription;
46
47 /**
48  * Displays ports of the given <code>CCMObject</code> component.
49  *
50  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
51  *
52  * @version 0.1
53  */

54 public class RequiredInterfacesTable
55     implements Table
56 {
57
58     //==================================================================
59
//
60
// Internal states.
61
//
62
//==================================================================
63

64     //==================================================================
65
//
66
// No constructor.
67
//
68
//==================================================================
69

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

76     protected String JavaDoc getName(org.omg.CORBA.Object JavaDoc o) {
77         TypageCORBA tc = new TypageCORBA(o, org.objectweb.openccm.corba.TheORB.getORB());
78         return tc.getTypeID();
79     }
80
81     //==================================================================
82
//
83
// Public methods for Table interface.
84
//
85
//==================================================================
86

87     /* (non-Javadoc)
88      * @see org.objectweb.util.explorer.api.Table#getHeaders(org.objectweb.util.explorer.api.TreeView)
89      */

90     public String JavaDoc[] getHeaders(TreeView treeView) {
91         return new String JavaDoc[]{"Port","Connection","Connected"};
92     }
93     
94     /* (non-Javadoc)
95      * @see org.objectweb.util.explorer.api.Table#getRows(org.objectweb.util.explorer.api.TreeView)
96      */

97     public Object JavaDoc[][] getRows(TreeView treeView) {
98         org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.corba.TheORB.getORB();
99         IorPrinter iorPrinter = null;
100         List JavaDoc l = new Vector JavaDoc();
101
102         CCMObject component = (CCMObject) treeView.getSelectedObject();
103         ComponentPortDescription cpd = component.get_all_ports();
104
105         // List of receptacles
106
ReceptacleDescription[] rd = cpd.receptacles;
107         for (int i = 0; i < rd.length; i++) {
108             ReceptacleContainer rc = new ReceptacleContainer();
109             rc.setComponent(component);
110             rc.setReceptacle(rd[i]);
111             Entry rdEntry = new DefaultEntry(rd[i].name, rc);
112
113             ConnectionDescription[] cd = rd[i].connections;
114             if(cd.length > 0){
115                 for (int j = 0; j < cd.length; j++) {
116                     ConnectionContainer cc = new ConnectionContainer();
117                     cc.setConnection(cd[j]);
118                     cc.setReceptacleContainer(rc);
119                     Entry ccEntry = new DefaultEntry("Connection (" + j + ")", cc);
120          
121                     Entry cEntry = new DefaultEntry(getName(cd[j].objref), cd[j].objref);
122            
123                     l.add(new Object JavaDoc[]{rdEntry, ccEntry, cEntry});
124                 }
125             } else {
126                 l.add(new Object JavaDoc[]{rdEntry, null, null});
127             }
128         }
129
130         // List of emitters
131
EmitterDescription[] ed = cpd.emitters;
132         for (int i = 0; i < ed.length; i++) {
133             EmitterContainer ec = new EmitterContainer();
134             ec.setComponent(component);
135             ec.setEmitter(ed[i]);
136             Entry edEntry = new DefaultEntry(ed[i].name, ec);
137
138             if(ed[i].consumer!=null){
139                 Entry cEntry = new DefaultEntry(getName(ed[i].consumer), ed[i].consumer);
140                 l.add(new Object JavaDoc[]{edEntry, null, cEntry});
141             } else {
142                 l.add(new Object JavaDoc[]{edEntry, null, null});
143             }
144         }
145
146         // List of publishers
147
PublisherDescription[] pd = cpd.publishers;
148         for (int i = 0; i < pd.length; i++) {
149             PublisherContainer pc = new PublisherContainer();
150             pc.setComponent(component);
151             pc.setPublisher(pd[i]);
152             Entry pdEntry = new DefaultEntry(pd[i].name, pc);
153
154             SubscriberDescription[] sd = pd[i].consumers;
155             if(sd.length > 0){
156                 for (int j = 0; j < sd.length; j++) {
157                     SubscriberContainer sc = new SubscriberContainer();
158                     sc.setSubscriber_(sd[j]);
159                     sc.setPublisherContainer_(pc);
160                     Entry scEntry = new DefaultEntry("Connection (" + j + ")", sc);
161
162                     Entry sEntry = new DefaultEntry(getName(sd[j].consumer), sd[j].consumer);
163                     
164                     l.add(new Object JavaDoc[]{pdEntry, scEntry, sEntry});
165                 }
166             } else {
167                 l.add(new Object JavaDoc[]{pdEntry, null, null});
168             }
169             
170         }
171
172         Object JavaDoc[][] contenu = new Object JavaDoc[l.size()][3];
173         Iterator JavaDoc it = l.iterator();
174         int cpt = 0;
175         while(it.hasNext()){
176             contenu[cpt] = (Object JavaDoc[])it.next();
177             cpt++;
178         }
179
180         return contenu;
181  
182    }
183 }
184
Popular Tags