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 javax.swing.tree.*; 28 import org.omg.CosNaming.*; 29 import org.omg.CosNaming.NamingContextPackage.*; 30 import org.omg.CORBA.*; 31 32 public class NameNode extends DefaultMutableTreeNode { 33 private static org.omg.CORBA.ORB orb; 34 private boolean explored = false; 35 private Binding binding; 36 private NamingContext context; 37 private org.omg.CORBA.Object obj; 38 39 public NameNode(Binding bi, NamingContext nc) { 40 binding = bi; 41 context = nc; 42 setUserObject(this); 43 } 44 45 public static void setOrb(org.omg.CORBA.ORB o) { 46 orb = o; 47 } 48 49 public static org.omg.CORBA.ORB getOrb() { 50 return orb; 51 } 52 53 public boolean getAllowsChildren() { 54 return isContext(); 55 } 56 57 public boolean isLeaf() { 58 return !isContext(); 59 } 60 61 public NamingContext getNamingContext() { 62 return context; 63 } 64 65 public void explore() { 66 explore(false); 67 } 68 69 public boolean isExplored() { 70 return explored; 71 } 72 73 public boolean isContext() { 74 return context != null; 75 } 76 77 public String toString() { 78 return binding.binding_name[0].id + " " + binding.binding_name[0].kind; 79 } 80 81 public String getIor() { 82 String ior = "context!"; 83 org.omg.CORBA.Object obj = getObject(); 84 if (obj != null) { 85 try { 86 ior = orb.object_to_string(obj); 87 } catch (Exception e) { 88 e.printStackTrace(); 89 } 90 } 91 return ior; 92 } 93 94 public org.omg.CORBA.Object getObject() { 95 if (obj != null) { 96 return obj; 97 } 98 if (!isContext()) { 99 try { 100 NameNode p = (NameNode)getParent(); 101 NamingContext ctx = p.getNamingContext(); 102 obj = ctx.resolve(binding.binding_name); 103 return obj; 104 } catch (Exception e) { 105 e.printStackTrace(); 106 } 107 } 108 return null; 109 } 110 111 public boolean ping() { 112 if (!isContext()) { 113 String ior = getIor(); 114 org.omg.CORBA.Object obj = orb.string_to_object(ior); 115 if (obj != null) { 116 try { 117 obj._is_a("dummy"); 118 } catch (Exception e) { 119 return false; 120 } 121 return true; 122 } 123 } 124 return false; 125 } 126 127 public void explore(boolean force) { 128 if(!isExplored() || force) { 129 removeAllChildren(); 130 BindingListHolder blHolder = new BindingListHolder(); 131 BindingIteratorHolder biHolder = new BindingIteratorHolder(); 132 133 context.list(1000, blHolder, biHolder); 134 135 Binding[] children = blHolder.value; 136 137 NamingContext nc; 138 try { 139 for(int i=0; i < children.length; i++) { 140 if (children[i].binding_type == BindingType.ncontext) { 141 nc = NamingContextHelper.narrow(context.resolve(children[i].binding_name)); 142 } else { 143 nc = null; 144 } 145 add(new NameNode(children[i], nc)); 146 } 147 } catch (Exception e) { 148 e.printStackTrace(); 149 } 150 151 explored = true; 152 } 153 } 154 155 private void removeAllBindings() { 156 int cnt = getChildCount() - 1; 157 for (int i = 0; i < cnt; i++) { 158 removeBinding(i); 159 } 160 } 161 162 public void removeBinding(int n) { 163 NameNode child = (NameNode)getChildAt(n); 164 child.removeBinding(); 165 } 166 167 public void removeBinding() { 168 try { 169 NamingContext ctx = ((NameNode)getParent()).getNamingContext(); 170 ctx.unbind(binding.binding_name); 171 removeFromParent(); 172 } catch (Exception e) { 173 e.printStackTrace(); 174 } 175 } 176 177 private void printPath(NameComponent[] nc) { 178 System.out.print("path:"); 179 for (int i = 0; i < nc.length; i++) { 180 System.out.print(nc[i].id); 181 } 182 } 183 } 184 | Popular Tags |