KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosNaming > CosNamingPanel


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 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.CosNaming;
28
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.openccm.explorer.CORBA.ConsoleFactory;
34 import org.objectweb.openccm.explorer.util.ior.IorPrinter;
35 import org.objectweb.util.explorer.api.Table;
36 import org.objectweb.util.explorer.api.TreeView;
37 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry;
38 import org.omg.CosNaming.NamingContextExt JavaDoc;
39
40 /**
41  * Displays objects bound into the given <code>CosNaming</code> object.
42  *
43  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
44  *
45  * @version 0.1
46  */

47 public class CosNamingPanel
48     implements Table {
49
50     //==================================================================
51
//
52
// Internal states.
53
//
54
//==================================================================
55

56     //==================================================================
57
//
58
// No constructor.
59
//
60
//==================================================================
61

62     //==================================================================
63
//
64
// Internal methods.
65
//
66
//==================================================================
67

68     //==================================================================
69
//
70
// Public methods for CosNamingPanel interface.
71
//
72
//==================================================================
73

74     /* (non-Javadoc)
75      * @see org.objectweb.util.explorer.api.Table#getHeaders(org.objectweb.util.explorer.api.TreeView)
76      */

77     public String JavaDoc[] getHeaders(TreeView treeView) {
78         return new String JavaDoc[]{"ID","Kind","Value"};
79     }
80     
81     /* (non-Javadoc)
82      * @see org.objectweb.util.explorer.api.Table#getRows(org.objectweb.util.explorer.api.TreeView)
83      */

84     public Object JavaDoc[][] getRows(TreeView treeView) {
85         NamingContextExt JavaDoc naming = (NamingContextExt JavaDoc)treeView.getSelectedObject();
86         org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.corba.TheORB.getORB();
87         IorPrinter iorPrinter = null;
88         List JavaDoc l = new Vector JavaDoc();
89         try{
90             org.omg.CosNaming.BindingListHolder JavaDoc bindingList = new org.omg.CosNaming.BindingListHolder JavaDoc();
91             org.omg.CosNaming.BindingIteratorHolder JavaDoc bindingIterator = new org.omg.CosNaming.BindingIteratorHolder JavaDoc();
92
93             naming.list(100, bindingList, bindingIterator);
94             while(true){
95                 for(int i = 0; i< bindingList.value.length ; i++){
96                     try{
97                         org.omg.CosNaming.NameComponent JavaDoc[] nameComponent = bindingList.value[i].binding_name;
98                         org.omg.CORBA.Object JavaDoc object = naming.resolve(nameComponent);
99                         iorPrinter = new IorPrinter(orb.object_to_string(object));
100
101                         String JavaDoc id="",kind="";
102                         id = nameComponent[nameComponent.length-1].id;
103                         kind = nameComponent[nameComponent.length-1].kind;
104
105                         l.add(new Object JavaDoc[]{id,kind,new DefaultEntry(iorPrinter.getTypeId(), object)});
106                      } catch (org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc e) {
107                         System.out.println(getClass().getName() + " : Object Not Found Exception !");
108                      } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc e) {
109                         System.out.println(getClass().getName() + " : CannotProceed Exception");
110                      } catch (org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc e) {
111                         System.out.println(getClass().getName() + " : InvalidName Exception");
112                      }
113                 }
114                 if(!bindingIterator.value.next_n(100, bindingList)) break;
115             }
116         } catch(Exception JavaDoc e) {
117             ConsoleFactory.getDebugConsole().add(e.getMessage()+ "\n");
118         }
119
120         Object JavaDoc[][] contenu = new Object JavaDoc[l.size()][2];
121         Iterator JavaDoc it = l.iterator();
122         int cpt = 0;
123         while(it.hasNext()){
124             contenu[cpt] = (Object JavaDoc[])it.next();
125             cpt++;
126         }
127
128         return contenu;
129     }
130 }
131
Popular Tags