1 2 package com.ca.directory.jxplorer.broker; 3 4 import javax.naming.*; 5 import javax.naming.directory.*; 6 7 import java.util.*; 8 import java.util.logging.Logger ; 9 import java.util.logging.Level ; 10 11 import com.ca.directory.jxplorer.*; 12 import com.ca.commons.naming.*; 13 import com.ca.commons.jndi.SchemaOps; 14 15 import java.awt.Component ; 16 17 22 23 public class OfflineBroker extends Broker 24 { 25 Hashtable nodes; Component display; 27 28 private static Logger log = Logger.getLogger(OfflineBroker.class.getName()); 29 30 34 35 class Node 36 { 37 DXEntry entry; 38 39 Vector children; 41 DN dn; 42 NameClassPair namePair; 43 44 47 public Node(DXEntry entry) 48 { 49 this.entry = entry; 50 dn = entry.getDN(); 51 children = new Vector(10); 52 namePair = new NameClassPair(dn.getLowestRDN().toString(), dn.getLowestRDN().getAtt()); 53 } 54 55 public void addChild(Node n) { children.add(n); } 56 57 public void removeChild(Node n) { children.remove(n); } 58 59 public void updateAttributes(DXAttributes a) 60 { 61 try 62 { 63 NamingEnumeration attset = a.getAll(); 64 while (attset.hasMore()) 65 entry.put((Attribute)attset.next()); 66 } 67 catch (NamingException e) 68 { 69 log.log(Level.WARNING, "unusual error in OfflineBroker::updateAttributes", e); 70 } 71 } 72 73 76 77 public DXNamingEnumeration getChildren() 78 { 79 DXNamingEnumeration result = new DXNamingEnumeration(); 80 for (int i=0; i<children.size(); i++) 81 result.add(((Node)children.elementAt(i)).getNameClassPair()); 82 return result; 83 } 84 85 88 89 public NamingEnumeration getChildNodes() 90 { 91 DXNamingEnumeration result = new DXNamingEnumeration(); 92 for (int i=0; i<children.size(); i++) 93 result.add(children.elementAt(i)); 94 return result; 95 } 96 97 101 public NameClassPair getNameClassPair() { return namePair; } 102 103 106 public DXEntry getEntry() { return entry; } 107 108 111 public DN getDN() { return dn; } 112 113 118 119 public Node getParent() 120 { 121 DN parentDN = dn.parentDN(); 122 if (parentDN == null) return null; 123 Node Parent = (Node)nodes.get(parentDN.toString()); 124 return Parent; 125 } 126 127 public String toString() { return dn.toString(); } 128 } 129 130 135 public OfflineBroker(Component graphicsDisplay) 136 { 137 display = graphicsDisplay; 138 nodes = new Hashtable(1000); 139 } 140 141 145 146 public void clear() 147 { 148 nodes.clear(); 149 } 150 151 159 160 public DXNamingEnumeration children(DN nodeDN) 161 { 162 Node N = (Node)nodes.get(nodeDN.toString()); 163 return (N==null)? null : N.getChildren() ; 164 } 165 166 167 171 172 public boolean isActive() { return true; } 173 174 178 public boolean hasData() { return !nodes.isEmpty(); } 179 180 186 public Vector objectClasses() { return null; } 187 188 195 196 public Vector recommendedObjectClasses(DN dn) { return null; } 197 198 204 205 public SchemaOps getSchemaOps() { return null; } 206 207 212 213 protected boolean addNode(DXEntry entry) 214 { 215 DN nodeDN = entry.getDN(); 216 217 log.fine("adding node " + nodeDN); 218 219 Node N = new Node(entry); 220 nodes.put(nodeDN.toString(), N); 221 Node P = N.getParent(); 222 223 if (P==null) 224 { 225 if (nodeDN.size()>1) { 227 addNode(new DXEntry(new DXAttributes(new DXAttribute("structuralTreeNode", "true")), nodeDN.parentDN())); P = (Node)nodes.get(nodeDN.parentDN().toString()); 229 } 230 } 231 log.fine("parent = " + ((P==null)?"null":P.toString())); 232 if (P != null) P.addChild(N); 233 return true; } 235 236 242 243 public boolean updateNode(DXEntry oldSet, DXEntry newSet) 244 { 245 log.fine("offline cache updating " + oldSet.getDN().toString()); 246 Node N = (Node)nodes.get(oldSet.getDN().toString()); 247 if (N==null) return false; 248 N.updateAttributes(newSet); 249 return true; 250 } 251 252 259 260 public boolean deleteTree(DN nodeDN) { 262 log.fine("offline cache deleting " + nodeDN.toString()); 263 Node N = (Node)nodes.get(nodeDN.toString()); 264 265 if (N==null) return false; 266 267 Enumeration children = N.getChildNodes(); 268 while (children.hasMoreElements()) 269 deleteTree(((Node)children.nextElement()).getDN()); 270 271 nodes.remove(nodeDN.toString()); 272 Node parent = N.getParent(); if (parent != null) parent.removeChild(N); return true; 275 } 276 277 286 287 public void move(DN oldNodeDN, DN newNodeDN) throws NamingException 289 { 290 unthreadedCopy(oldNodeDN, newNodeDN); deleteTree(oldNodeDN); } 293 294 295 296 297 306 307 public boolean isModifiable() { return true; } 308 309 310 311 314 315 public DirContext getDirContext() { return null; } 316 317 318 319 323 324 public DataQuery doListQuery(DataQuery request) 325 { 326 request.setEnum(children(request.requestDN())); 327 return request; 328 } 329 330 334 335 public DataQuery doSearchQuery(DataQuery request) 336 { 337 request.setException(new Exception ("offline searches not allowed")); 338 return request; 339 } 340 341 342 346 347 public DataQuery doGetAllOCsQuery(DataQuery request) 348 { 349 request.setException(new Exception ("offline object class list not implemented")); 350 return request; 351 } 352 353 357 358 public DataQuery doGetRecOCsQuery(DataQuery request) 359 { 360 request.setException(new Exception ("offline object class list not implemented")); 361 return request; 362 } 363 364 371 372 public DXNamingEnumeration unthreadedList(DN searchbase) 373 { 374 return children(searchbase); 375 } 376 377 386 387 public DXNamingEnumeration unthreadedSearch(DN dn, String filter, int search_level, String [] returnAttributes) 388 { 389 return null; 390 } 391 392 400 401 public void unthreadedCopy(DN oldNodeDN, DN newNodeDN) 402 throws NamingException 403 { 404 Node Old = (Node)nodes.get(oldNodeDN.toString()); if (Old==null) 406 throw new NamingException("null old dn passed to unthreaded copy"); 408 addNode(new DXEntry(Old.getEntry(), newNodeDN)); Node New = (Node)nodes.get(newNodeDN.toString()); Enumeration children = Old.getChildNodes(); while (children.hasMoreElements()) { 413 Node child = (Node)children.nextElement(); DN NewChildDN = new DN(New.getDN()); NewChildDN.addChildRDN(child.getDN().getLowestRDN().toString()); unthreadedCopy(child.getDN(),NewChildDN); } 418 } 419 420 421 422 428 429 public boolean unthreadedExists(DN nodeDN) 430 { 431 return nodes.containsKey(nodeDN.toString()); 432 } 433 434 437 438 public Vector unthreadedGetAllOCs() { return null; } 439 440 447 448 public DXEntry unthreadedReadEntry(DN entryDN, String [] returnAttributes) 449 { 450 if (returnAttributes != null) 451 log.info("warning: att list read entries not implemented in offline broker"); 452 453 Node N = (Node)nodes.get(entryDN.toString()); 454 return (N==null)? new DXEntry(entryDN) : N.getEntry(); 455 } 456 457 458 463 464 public void unthreadedModify(DXEntry oldEntry, DXEntry newEntry) 465 throws NamingException 466 { 467 if (oldEntry == null && newEntry == null) 468 { 469 } 471 else if (oldEntry == null) { 473 addNode(newEntry); 474 } 475 else if (newEntry == null) { 477 deleteTree(oldEntry.getDN()); 478 } 479 else 480 { 481 482 485 RDN singleValRDN = oldEntry.getDN().getLowestRDN(); 486 String namingAtt = singleValRDN.getAtt(); 487 String namingVal = singleValRDN.getRawVal(); 488 oldEntry.remove(namingAtt); 489 newEntry.remove(namingAtt); 490 newEntry.put(new DXAttribute(namingAtt, namingVal)); 491 492 if (oldEntry.getDN().equals(newEntry.getDN()) == false) 493 { 494 move(oldEntry.getDN(), newEntry.getDN()); 495 oldEntry.putDN(newEntry.getDN()); 496 } 497 498 500 updateNode(oldEntry, newEntry); 501 } 502 } 503 504 510 511 public ArrayList unthreadedGetRecOCs(DN dn) { return null; } 512 513 } | Popular Tags |