1 package org.jacorb.naming.namemanager; 2 3 22 23 import org.omg.CosNaming.*; 24 import org.jacorb.naming.*; 25 import org.jacorb.orb.*; 26 import org.jacorb.orb.iiop.*; 27 28 import java.util.*; 29 import javax.swing.tree.*; 30 31 35 36 public class ContextNode 37 { 38 protected Binding[] contents; 39 public boolean matched; 40 public boolean used; 41 42 public NamingContextExt context; 43 private DefaultMutableTreeNode myDefaultNode; 44 private DefaultTreeModel model; 45 private Binding binding; 46 private Vector bindingData; 47 private String myName; 48 49 public ContextNode( NamingContextExt context, DefaultTreeModel model ) 50 { 51 used = false; 52 this.model = model; 53 this.context = context; 54 } 55 56 public ContextNode( NamingContextExt context, 57 Binding b, 58 DefaultTreeModel model) 59 { 60 used = false; 61 this.model = model; 62 this.context = context; 63 binding = b; 64 } 65 66 69 70 public void display() 71 { 72 update(); 73 if( bindingData != null ) 74 NSTree.nsTable.setData( bindingData, this ); 75 } 76 77 public boolean equals(ContextNode bnode) 78 { 79 return toString().equals(bnode.toString()); 80 } 81 82 public NameComponent[] getName() 83 { 84 return binding.binding_name; 85 } 86 87 91 92 public void setNode(DefaultMutableTreeNode node) 93 { 94 this.myDefaultNode = node; 95 } 96 97 98 public String toString() 99 { 100 if( binding == null ) 101 return "RootContext"; 102 else 103 { 104 if (myName == null ) 105 { 106 NameComponent[] name = binding.binding_name; 107 String kind = name[name.length-1].kind; 108 myName = name[name.length-1].id + 109 ( kind != null && kind.length() > 0 ? "." + kind : ""); 110 } 111 return myName; 112 } 113 } 114 115 119 120 public void unbind(NameComponent [] nc) 121 throws org.omg.CosNaming.NamingContextPackage.NotFound , 122 org.omg.CosNaming.NamingContextPackage.CannotProceed , 123 org.omg.CosNaming.NamingContextPackage.InvalidName 124 { 125 context.unbind(nc); 126 } 127 128 131 132 public synchronized void update() 133 { 134 try 135 { 136 BindingListHolder blsoh = new BindingListHolder(); 137 BindingIteratorHolder bioh = new BindingIteratorHolder(); 138 ContextNode context_node; 139 140 context.list( NSTree.MAX_BIND, blsoh, bioh); 141 Binding[] bindings = blsoh.value; 142 143 int childCount = myDefaultNode.getChildCount(); 144 145 147 int context_count = 0; 148 int object_count = 0; 149 150 for( int i = 0; i < bindings.length; i++ ) 151 { 152 if( bindings[i].binding_type == BindingType.ncontext ) 153 context_count++; 154 else 155 object_count++; 156 } 157 158 ContextNode[] contexts = new ContextNode[context_count]; 159 Binding[] objects = new Binding[object_count]; 160 161 for( int i = 0; i < bindings.length; i++ ) 162 { 163 if( bindings[i].binding_type == BindingType.ncontext) 164 contexts[ --context_count ] = 165 new ContextNode( NamingContextExtHelper.narrow( context.resolve(bindings[i].binding_name)), bindings[i], model ); 166 else 167 objects[ --object_count ] = bindings[i]; 168 } 169 170 173 for( int i = 0; i < childCount; i++ ) 174 { 175 DefaultMutableTreeNode dmtn = 176 (DefaultMutableTreeNode)myDefaultNode.getChildAt(i); 177 context_node = (ContextNode)dmtn.getUserObject(); 178 for (int j = 0; j < contexts.length; j++) 179 { 180 if (context_node.equals(contexts[j])) 181 { 182 context_node.matched = true; 183 contexts[j].matched = true; 184 } 185 } 186 } 187 188 191 Vector removeList = new Vector(); 192 for (int i = 0; i < childCount; i++) 193 { 194 DefaultMutableTreeNode node = 195 (DefaultMutableTreeNode)myDefaultNode.getChildAt(i); 196 context_node = (ContextNode)node.getUserObject(); 197 if (!context_node.matched) 198 { 199 removeList.addElement(node); 200 } 201 else 202 context_node.matched=false; 203 } 204 205 int rsize = removeList.size(); 206 for(int i = 0; i < rsize; i++) 207 { 208 model.removeNodeFromParent((DefaultMutableTreeNode)removeList.elementAt(i)); 209 } 210 211 bindingData = new Vector(); 212 213 216 for (int i = 0; i < contexts.length; i++) 217 { 218 if (!contexts[i].matched) 219 { 220 contexts[i].used=true; 221 222 DefaultMutableTreeNode node = new DefaultMutableTreeNode(); 223 224 contexts[i].setNode(node); 226 node.setUserObject(contexts[i]); 227 node.setAllowsChildren(true); 228 model.insertNodeInto(node,myDefaultNode,0); 229 } 230 NameComponent last = 231 contexts[i].binding.binding_name[ contexts[i].binding.binding_name.length-1]; 232 NameComponent[] ncs = {last}; 233 234 org.jacorb.orb.ParsedIOR pior = null; 235 try 236 { 237 pior = 238 ((org.jacorb.orb.Delegate)((org.omg.CORBA.portable.ObjectImpl )context.resolve( 239 ncs ))._get_delegate()).getParsedIOR(); 240 } 241 catch( org.omg.CosNaming.NamingContextPackage.NotFound nf ) 242 { 243 continue; 247 } 248 Vector row = new Vector(); 249 250 row.addElement( last.id ); 251 row.addElement( last.kind); 252 row.addElement( pior.getTypeId() ); 253 IIOPProfile p = (IIOPProfile)pior.getEffectiveProfile(); 254 row.addElement( p.getAddress().getIP() ); 255 256 bindingData.addElement( row ); 257 258 } 259 260 261 for( int i = 0; i < objects.length; i++ ) 262 { 263 NameComponent last = 264 objects[i].binding_name[ objects[i].binding_name.length-1]; 265 NameComponent[] ncs = {last}; 266 org.jacorb.orb.ParsedIOR pior = null; 267 try 268 { 269 pior = 270 ((org.jacorb.orb.Delegate)((org.omg.CORBA.portable.ObjectImpl )context.resolve( 271 ncs ))._get_delegate()).getParsedIOR(); 272 } 273 catch( org.omg.CosNaming.NamingContextPackage.NotFound nf ) 274 { 275 continue; 279 } 280 Vector row = new Vector(); 281 282 row.addElement( last.id ); 283 row.addElement( last.kind); 284 row.addElement( pior.getTypeId() ); 285 IIOPProfile p = (IIOPProfile)pior.getEffectiveProfile(); 286 row.addElement( p.getAddress().getIP() ); 287 288 bindingData.addElement( row ); 289 } 290 291 293 childCount = myDefaultNode.getChildCount(); 294 for (int i = 0; i < childCount; i++ ) 295 { 296 DefaultMutableTreeNode dmtn = 297 (DefaultMutableTreeNode)myDefaultNode.getChildAt(i); 298 context_node = (ContextNode)dmtn.getUserObject(); 299 context_node.update(); 301 } 302 } 303 catch (Exception e) 304 { 305 e.printStackTrace(); 306 } 307 } 308 } 309 310 | Popular Tags |