1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.Iterator ; 27 import java.util.LinkedHashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 32 import org.apache.directory.ldapstudio.browser.core.events.AttributeAddedEvent; 33 import org.apache.directory.ldapstudio.browser.core.events.AttributeDeletedEvent; 34 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 35 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy; 36 import org.apache.directory.ldapstudio.browser.core.model.DN; 37 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 38 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 39 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 40 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException; 41 import org.apache.directory.ldapstudio.browser.core.model.RDN; 42 import org.apache.directory.ldapstudio.browser.core.model.URL; 43 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription; 44 import org.apache.directory.ldapstudio.browser.core.model.schema.Subschema; 45 46 47 public class DummyEntry implements IEntry 48 { 49 50 private static final long serialVersionUID = 4833907766031149971L; 51 52 private DN dn; 53 54 private DummyConnection dummyConnection; 55 56 private String connectionName; 57 58 private Map attributeMap; 59 60 61 protected DummyEntry() 62 { 63 } 64 65 66 public DummyEntry( DN dn, IConnection connection ) 67 { 68 if ( connection instanceof DummyConnection ) 69 { 70 this.dummyConnection = ( DummyConnection ) connection; 71 } 72 else 73 { 74 this.connectionName = connection.getName(); 75 } 76 77 this.dn = dn; 78 attributeMap = new LinkedHashMap (); 79 } 80 81 82 public void setDn( DN dn ) 83 { 84 this.dn = dn; 85 } 86 87 88 public void addAttribute( IAttribute attributeToAdd ) throws ModelModificationException 89 { 90 attributeMap.put( attributeToAdd.getDescription().toLowerCase(), attributeToAdd ); 91 EventRegistry.fireEntryUpdated( new AttributeAddedEvent( attributeToAdd.getEntry().getConnection(), this, 92 attributeToAdd ), this ); 93 } 94 95 96 public void addChild( IEntry childrenToAdd ) 97 { 98 } 99 100 101 public void deleteAttribute( IAttribute attributeToDelete ) throws ModelModificationException 102 { 103 attributeMap.remove( attributeToDelete.getDescription().toLowerCase() ); 104 EventRegistry.fireEntryUpdated( new AttributeDeletedEvent( attributeToDelete.getEntry().getConnection(), this, 105 attributeToDelete ), this ); 106 } 107 108 109 public void deleteChild( IEntry childrenToDelete ) 110 { 111 } 112 113 114 public IAttribute getAttribute( String attributeDescription ) 115 { 116 return ( IAttribute ) attributeMap.get( attributeDescription.toLowerCase() ); 117 } 118 119 120 public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) 121 { 122 123 AttributeDescription ad = new AttributeDescription( attributeDescription ); 124 125 List attributeList = new ArrayList (); 126 Iterator iterator = attributeMap.values().iterator(); 127 while ( iterator.hasNext() ) 128 { 129 IAttribute attribute = ( IAttribute ) iterator.next(); 130 131 AttributeDescription other = new AttributeDescription( attributeDescription ); 132 if ( other.isSubtypeOf( ad, getConnection().getSchema() ) ) 133 { 134 attributeList.add( attribute ); 135 } 136 } 137 138 if ( attributeList.isEmpty() ) 139 { 140 return null; 141 } 142 else 143 { 144 AttributeHierarchy ah = new AttributeHierarchy( this, attributeDescription, ( IAttribute[] ) attributeList 145 .toArray( new IAttribute[attributeList.size()] ) ); 146 return ah; 147 } 148 } 149 150 151 public IAttribute[] getAttributes() 152 { 153 return ( IAttribute[] ) attributeMap.values().toArray( new IAttribute[attributeMap.size()] ); 154 } 155 156 157 public IConnection getConnection() 158 { 159 return dummyConnection != null ? dummyConnection : BrowserCorePlugin.getDefault().getConnectionManager() 160 .getConnection( this.connectionName ); 161 } 162 163 164 public DN getDn() 165 { 166 return dn; 167 } 168 169 170 public URL getUrl() 171 { 172 return new URL( getConnection(), getDn() ); 173 } 174 175 176 public IEntry getParententry() 177 { 178 return null; 179 } 180 181 182 public RDN getRdn() 183 { 184 return dn.getRdn(); 185 } 186 187 188 public IEntry[] getChildren() 189 { 190 return null; 191 } 192 193 194 public int getChildrenCount() 195 { 196 return -1; 197 } 198 199 200 public String getChildrenFilter() 201 { 202 return ""; } 204 205 206 public Subschema getSubschema() 207 { 208 return new Subschema( this ); 209 } 210 211 212 public boolean hasMoreChildren() 213 { 214 return false; 215 } 216 217 218 public boolean hasParententry() 219 { 220 return false; 221 } 222 223 224 public boolean hasChildren() 225 { 226 return false; 227 } 228 229 230 public boolean isAlias() 231 { 232 return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_ALIAS ); 233 } 234 235 236 public boolean isAttributesInitialized() 237 { 238 return true; 239 } 240 241 242 public boolean isConsistent() 243 { 244 Iterator attributeIterator = attributeMap.values().iterator(); 246 while ( attributeIterator.hasNext() ) 247 { 248 IAttribute attribute = ( IAttribute ) attributeIterator.next(); 249 if ( !attribute.isConsistent() ) 250 return false; 251 } 252 253 if ( !attributeMap.containsKey( IAttribute.OBJECTCLASS_ATTRIBUTE.toLowerCase() ) ) 255 { 256 return false; 257 } 258 IAttribute ocAttribute = ( IAttribute ) attributeMap.get( IAttribute.OBJECTCLASS_ATTRIBUTE.toLowerCase() ); 259 String [] ocValues = ocAttribute.getStringValues(); 260 boolean structuralObjectClassAvailable = false; 261 for ( int i = 0; i < ocValues.length; i++ ) 262 { 263 ObjectClassDescription ocd = this.getConnection().getSchema().getObjectClassDescription( ocValues[i] ); 264 if ( ocd.isStructural() ) 265 { 266 structuralObjectClassAvailable = true; 267 break; 268 } 269 } 270 if ( !structuralObjectClassAvailable ) 271 { 272 return false; 273 } 274 275 String [] mustAttributeNames = this.getSubschema().getMustAttributeNames(); 277 for ( int i = 0; i < mustAttributeNames.length; i++ ) 278 { 279 if ( !attributeMap.containsKey( mustAttributeNames[i].toLowerCase() ) ) 280 return false; 281 } 282 283 return true; 284 } 285 286 287 public boolean isDirectoryEntry() 288 { 289 return false; 290 } 291 292 293 public boolean isReferral() 294 { 295 return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_REFERRAL ); 296 } 297 298 299 public boolean isSubentry() 300 { 301 return Arrays.asList( this.getSubschema().getObjectClassNames() ).contains( ObjectClassDescription.OC_SUBENTRY ); 302 } 303 304 305 public boolean isChildrenInitialized() 306 { 307 return false; 308 } 309 310 311 public void moveTo( IEntry newParent ) throws ModelModificationException 312 { 313 } 314 315 316 public void rename( RDN newRdn, boolean deleteOldRdn ) throws ModelModificationException 317 { 318 319 } 320 321 322 public void setAlias( boolean b ) 323 { 324 } 325 326 327 public void setAttributesInitialized( boolean b ) 328 { 329 } 330 331 332 public void setDirectoryEntry( boolean isDirectoryEntry ) 333 { 334 } 335 336 337 public void setHasMoreChildren( boolean b ) 338 { 339 } 340 341 342 public void setHasChildrenHint( boolean b ) 343 { 344 } 345 346 347 public void setReferral( boolean b ) 348 { 349 } 350 351 352 public void setSubentry( boolean b ) 353 { 354 } 355 356 357 public void setChildrenFilter( String filter ) 358 { 359 } 360 361 362 public void setChildrenInitialized( boolean b ) 363 { 364 } 365 366 367 public Object getAdapter( Class adapter ) 368 { 369 return null; 370 } 371 372 } 373 | Popular Tags |