KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > actor > namingBrowser > NameModel


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.actor.namingBrowser;
26
27 import org.omg.CosNaming.*;
28 import org.omg.CosNaming.NamingContextPackage.*;
29 import org.omg.CORBA.*;
30 import javax.swing.*;
31 import javax.swing.event.*;
32 import javax.swing.tree.*;
33 import java.io.*;
34
35 public class NameModel extends DefaultTreeModel {
36     private TreePath selection;
37     private NameNode nodeRoot;
38
39     public NameModel(ORB orb) {
40         super(null);
41         try {
42             NamingContext rootCtx = null;
43             String JavaDoc iorFile = System.getProperty("ior.file");
44             if (iorFile != null) {
45                 try {
46                     BufferedReader file = new BufferedReader(new FileReader(iorFile));
47                     rootCtx = NamingContextExtHelper.narrow(orb.string_to_object(file.readLine()));
48                 } catch (Exception JavaDoc e) {
49                 }
50             }
51             if (rootCtx == null) {
52                 rootCtx = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
53             }
54             NameComponent ncmp = new NameComponent("root", "context");
55             NameComponent[] path = {ncmp};
56             Binding bi = new Binding(path, BindingType.ncontext);
57
58             NameNode.setOrb(orb);
59             nodeRoot = new NameNode(bi, rootCtx);
60             refresh();
61         } catch (Exception JavaDoc e) {
62             e.printStackTrace();
63         }
64     }
65
66     public NameModel(NameNode root) {
67         super(root);
68         nodeRoot = root;
69         refresh();
70     }
71
72     public TreePath getSelection() {
73         return selection;
74     }
75
76     public void setSelection(TreePath s) {
77         selection = s;
78     }
79
80     public void refresh() {
81         NameNode newRoot = (NameNode)nodeRoot.clone();
82         newRoot.explore();
83         setRoot(newRoot);
84     }
85 }
Popular Tags