1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 25 import org.apache.directory.ldapstudio.browser.core.events.AttributeAddedEvent; 26 import org.apache.directory.ldapstudio.browser.core.events.AttributeDeletedEvent; 27 import org.apache.directory.ldapstudio.browser.core.events.AttributesInitializedEvent; 28 import org.apache.directory.ldapstudio.browser.core.events.ChildrenInitializedEvent; 29 import org.apache.directory.ldapstudio.browser.core.events.EmptyValueAddedEvent; 30 import org.apache.directory.ldapstudio.browser.core.events.EmptyValueDeletedEvent; 31 import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent; 32 import org.apache.directory.ldapstudio.browser.core.events.EntryUpdateListener; 33 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 34 import org.apache.directory.ldapstudio.browser.core.events.ValueAddedEvent; 35 import org.apache.directory.ldapstudio.browser.core.events.ValueDeletedEvent; 36 import org.apache.directory.ldapstudio.browser.core.events.ValueModifiedEvent; 37 import org.apache.directory.ldapstudio.browser.core.events.ValueRenamedEvent; 38 import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer; 39 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy; 40 import org.apache.directory.ldapstudio.browser.core.model.DN; 41 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 42 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 43 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 44 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException; 45 import org.apache.directory.ldapstudio.browser.core.model.RDN; 46 import org.apache.directory.ldapstudio.browser.core.model.URL; 47 import org.apache.directory.ldapstudio.browser.core.model.schema.Subschema; 48 import org.eclipse.search.ui.ISearchPageScoreComputer; 49 50 51 public class DelegateEntry implements IEntry, EntryUpdateListener 52 { 53 54 private static final long serialVersionUID = -4488685394817691963L; 55 56 private String connectionName; 58 59 private DN dn; 60 61 private boolean entryDoesNotExist; 62 63 private IEntry delegate; 64 65 66 protected DelegateEntry() 67 { 68 } 69 70 71 public DelegateEntry( IConnection connection, DN dn ) 72 { 73 this.connectionName = connection.getName(); 74 this.dn = dn; 75 this.entryDoesNotExist = false; 76 this.delegate = null; 77 EventRegistry.addEntryUpdateListener( this, BrowserCorePlugin.getDefault().getEventRunner() ); 78 } 79 80 81 protected IEntry getDelegate() 82 { 83 if ( this.delegate != null && !this.delegate.getConnection().isOpened() ) 84 { 85 this.entryDoesNotExist = false; 86 this.delegate = null; 87 } 88 return delegate; 89 } 90 91 92 protected void setDelegate( IEntry delegate ) 93 { 94 this.delegate = delegate; 95 } 96 97 98 public IConnection getConnection() 99 { 100 if ( this.getDelegate() != null ) 101 return getDelegate().getConnection(); 102 else 103 return BrowserCorePlugin.getDefault().getConnectionManager().getConnection( this.connectionName ); 104 } 106 107 108 public DN getDn() 109 { 110 if ( this.getDelegate() != null ) 111 return getDelegate().getDn(); 112 else 113 return dn; 114 } 115 116 117 public URL getUrl() 118 { 119 if ( this.getDelegate() != null ) 120 return getDelegate().getUrl(); 121 else 122 return new URL( getConnection(), getDn() ); 123 } 124 125 126 public boolean isAttributesInitialized() 127 { 128 if ( this.getDelegate() != null ) 129 return getDelegate().isAttributesInitialized(); 130 else if ( this.entryDoesNotExist ) 131 return true; 132 else 133 return false; 134 } 135 136 137 public boolean isChildrenInitialized() 138 { 139 if ( this.getDelegate() != null ) 140 return getDelegate().isChildrenInitialized(); 141 else if ( this.entryDoesNotExist ) 142 return true; 143 else 144 return false; 145 } 146 147 148 public boolean isDirectoryEntry() 149 { 150 if ( this.getDelegate() != null ) 151 return getDelegate().isDirectoryEntry(); 152 else 153 return true; 154 } 155 156 157 public void addAttribute( IAttribute attributeToAdd ) throws ModelModificationException 158 { 159 if ( this.getDelegate() != null ) 160 getDelegate().addAttribute( attributeToAdd ); 161 } 162 163 164 public void addChild( IEntry childrenToAdd ) 165 { 166 if ( this.getDelegate() != null ) 167 getDelegate().addChild( childrenToAdd ); 168 } 169 170 171 public void deleteAttribute( IAttribute attributeToDelete ) throws ModelModificationException 172 { 173 if ( this.getDelegate() != null ) 174 getDelegate().deleteAttribute( attributeToDelete ); 175 } 176 177 178 public void deleteChild( IEntry childrenToDelete ) 179 { 180 if ( this.getDelegate() != null ) 181 getDelegate().deleteChild( childrenToDelete ); 182 } 183 184 185 public IAttribute getAttribute( String attributeDescription ) 186 { 187 if ( this.getDelegate() != null ) 188 return getDelegate().getAttribute( attributeDescription ); 189 else 190 return null; 191 } 192 193 194 public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) 195 { 196 if ( this.getDelegate() != null ) 197 return getDelegate().getAttributeWithSubtypes( attributeDescription ); 198 else 199 return null; 200 } 201 202 203 public IAttribute[] getAttributes() 204 { 205 if ( this.getDelegate() != null ) 206 return getDelegate().getAttributes(); 207 else 208 return null; 209 } 210 211 212 public IEntry getParententry() 213 { 214 if ( this.getDelegate() != null ) 215 return getDelegate().getParententry(); 216 else 217 return null; 218 } 219 220 221 public RDN getRdn() 222 { 223 if ( this.getDelegate() != null ) 224 return getDelegate().getRdn(); 225 else 226 return this.dn.getRdn(); 227 } 228 229 230 public IEntry[] getChildren() 231 { 232 if ( this.getDelegate() != null ) 233 return getDelegate().getChildren(); 234 else 235 return null; 236 } 237 238 239 public int getChildrenCount() 240 { 241 if ( this.getDelegate() != null ) 242 return getDelegate().getChildrenCount(); 243 else 244 return -1; 245 } 246 247 248 public String getChildrenFilter() 249 { 250 if ( this.getDelegate() != null ) 251 return getDelegate().getChildrenFilter(); 252 else 253 return null; 254 } 255 256 257 public Subschema getSubschema() 258 { 259 if ( this.getDelegate() != null ) 260 return getDelegate().getSubschema(); 261 else 262 return null; 263 } 264 265 266 public boolean hasMoreChildren() 267 { 268 if ( this.getDelegate() != null ) 269 return getDelegate().hasMoreChildren(); 270 else 271 return false; 272 } 273 274 275 public boolean hasParententry() 276 { 277 if ( this.getDelegate() != null ) 278 return getDelegate().hasParententry(); 279 else 280 return false; 281 } 282 283 284 public boolean hasChildren() 285 { 286 if ( this.getDelegate() != null ) 287 return getDelegate().hasChildren(); 288 else 289 return true; 290 } 291 292 293 public boolean isConsistent() 294 { 295 if ( this.getDelegate() != null ) 296 return getDelegate().isConsistent(); 297 else 298 return true; 299 } 300 301 302 public void setAttributesInitialized( boolean b ) 303 { 304 305 if ( !b ) 306 { 307 if ( this.getDelegate() != null ) 308 { 309 getDelegate().setAttributesInitialized( b ); 310 } 311 setDelegate( null ); 312 this.entryDoesNotExist = false; 313 } 314 else 315 { 316 if ( this.getDelegate() == null ) 317 { 318 setDelegate( this.getConnection().getEntryFromCache( this.dn ) ); 319 if ( this.getDelegate() == null ) 320 { 321 this.entryDoesNotExist = true; 323 } 324 } 325 if ( this.getDelegate() != null ) 326 { 327 getDelegate().setAttributesInitialized( b ); 328 } 329 } 330 } 331 332 333 public void setDirectoryEntry( boolean b ) 334 { 335 if ( this.getDelegate() != null ) 336 getDelegate().setDirectoryEntry( b ); 337 } 338 339 340 public void setHasMoreChildren( boolean b ) 341 { 342 if ( this.getDelegate() != null ) 343 getDelegate().setHasMoreChildren( b ); 344 } 345 346 347 public void setHasChildrenHint( boolean b ) 348 { 349 if ( this.getDelegate() != null ) 350 getDelegate().setHasChildrenHint( b ); 351 } 352 353 354 public void setChildrenFilter( String filter ) 355 { 356 if ( this.getDelegate() != null ) 357 getDelegate().setChildrenFilter( filter ); 358 } 359 360 361 public void setChildrenInitialized( boolean b ) 362 { 363 364 if ( !b ) 365 { 366 if ( this.getDelegate() != null ) 367 { 368 getDelegate().setChildrenInitialized( b ); 369 } 370 this.entryDoesNotExist = false; 372 } 373 else 374 { 375 if ( this.getDelegate() == null ) 376 { 377 setDelegate( this.getConnection().getEntryFromCache( this.dn ) ); 378 if ( this.getDelegate() == null ) 379 { 380 this.entryDoesNotExist = true; 382 } 383 } 384 if ( this.getDelegate() != null ) 385 { 386 getDelegate().setChildrenInitialized( b ); 387 } 388 } 389 } 390 391 392 public boolean isAlias() 393 { 394 if ( this.getDelegate() != null ) 395 return getDelegate().isAlias(); 396 else 397 return false; 398 } 399 400 401 public void setAlias( boolean b ) 402 { 403 if ( this.getDelegate() != null ) 404 getDelegate().setAlias( b ); 405 } 406 407 408 public boolean isReferral() 409 { 410 if ( this.getDelegate() != null ) 411 return getDelegate().isReferral(); 412 else 413 return false; 414 } 415 416 417 public void setReferral( boolean b ) 418 { 419 if ( this.getDelegate() != null ) 420 getDelegate().setReferral( b ); 421 } 422 423 424 public boolean isSubentry() 425 { 426 if ( this.getDelegate() != null ) 427 return getDelegate().isSubentry(); 428 else 429 return false; 430 } 431 432 433 public void setSubentry( boolean b ) 434 { 435 if ( this.getDelegate() != null ) 436 getDelegate().setSubentry( b ); 437 } 438 439 440 public void entryUpdated( EntryModificationEvent event ) 441 { 442 443 if ( event.getModifiedEntry() == this.getDelegate() ) 444 { 445 446 if ( event instanceof AttributeAddedEvent ) 447 { 448 AttributeAddedEvent e = ( AttributeAddedEvent ) event; 449 AttributeAddedEvent delegateEvent = new AttributeAddedEvent( e.getConnection(), this, e 450 .getAddedAttribute() ); 451 EventRegistry.fireEntryUpdated( delegateEvent, this ); 452 } 453 else if ( event instanceof AttributeDeletedEvent ) 454 { 455 AttributeDeletedEvent e = ( AttributeDeletedEvent ) event; 456 AttributeDeletedEvent delegateEvent = new AttributeDeletedEvent( e.getConnection(), this, e 457 .getDeletedAttribute() ); 458 EventRegistry.fireEntryUpdated( delegateEvent, this ); 459 } 460 else if ( event instanceof AttributesInitializedEvent ) 461 { 462 AttributesInitializedEvent e = ( AttributesInitializedEvent ) event; 463 AttributesInitializedEvent delegateEvent = new AttributesInitializedEvent( this ); 464 EventRegistry.fireEntryUpdated( delegateEvent, this ); 465 } 466 else if ( event instanceof EmptyValueAddedEvent ) 467 { 468 EmptyValueAddedEvent e = ( EmptyValueAddedEvent ) event; 469 EmptyValueAddedEvent delegateEvent = new EmptyValueAddedEvent( e.getConnection(), this, e 470 .getModifiedAttribute(), e.getAddedValue() ); 471 EventRegistry.fireEntryUpdated( delegateEvent, this ); 472 } 473 else if ( event instanceof EmptyValueDeletedEvent ) 474 { 475 EmptyValueDeletedEvent e = ( EmptyValueDeletedEvent ) event; 476 EmptyValueDeletedEvent delegateEvent = new EmptyValueDeletedEvent( e.getConnection(), this, e 477 .getModifiedAttribute(), e.getDeletedValue() ); 478 EventRegistry.fireEntryUpdated( delegateEvent, this ); 479 } 480 else if ( event instanceof ChildrenInitializedEvent ) 485 { 486 ChildrenInitializedEvent e = ( ChildrenInitializedEvent ) event; 487 ChildrenInitializedEvent delegateEvent = new ChildrenInitializedEvent( this ); 488 EventRegistry.fireEntryUpdated( delegateEvent, this ); 489 } 490 else if ( event instanceof ValueAddedEvent ) 491 { 492 ValueAddedEvent e = ( ValueAddedEvent ) event; 493 ValueAddedEvent delegateEvent = new ValueAddedEvent( e.getConnection(), this, e 494 .getModifiedAttribute(), e.getAddedValue() ); 495 EventRegistry.fireEntryUpdated( delegateEvent, this ); 496 } 497 else if ( event instanceof ValueDeletedEvent ) 498 { 499 ValueDeletedEvent e = ( ValueDeletedEvent ) event; 500 ValueDeletedEvent delegateEvent = new ValueDeletedEvent( e.getConnection(), this, e 501 .getModifiedAttribute(), e.getDeletedValue() ); 502 EventRegistry.fireEntryUpdated( delegateEvent, this ); 503 } 504 else if ( event instanceof ValueModifiedEvent ) 505 { 506 ValueModifiedEvent e = ( ValueModifiedEvent ) event; 507 ValueModifiedEvent delegateEvent = new ValueModifiedEvent( e.getConnection(), this, e 508 .getModifiedAttribute(), e.getOldValue(), e.getNewValue() ); 509 EventRegistry.fireEntryUpdated( delegateEvent, this ); 510 } 511 else if ( event instanceof ValueRenamedEvent ) 512 { 513 ValueRenamedEvent e = ( ValueRenamedEvent ) event; 514 ValueRenamedEvent delegateEvent = new ValueRenamedEvent( e.getConnection(), this, e 515 .getOldValue(), e.getNewValue() ); 516 EventRegistry.fireEntryUpdated( delegateEvent, this ); 517 } 518 520 } 521 } 522 523 524 public Object getAdapter( Class adapter ) 525 { 526 527 if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) ) 528 { 529 return new LdapSearchPageScoreComputer(); 530 } 531 if ( adapter == IConnection.class ) 532 { 533 return this.getConnection(); 534 } 535 if ( adapter == IEntry.class ) 536 { 537 return this; 538 } 539 return null; 540 } 541 542 } 543 | Popular Tags |