1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 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 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 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 |