1 20 21 package org.apache.directory.ldapstudio.browser.core.jobs; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.LinkedHashSet ; 27 import java.util.List ; 28 29 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages; 30 import org.apache.directory.ldapstudio.browser.core.events.AttributesInitializedEvent; 31 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 32 import org.apache.directory.ldapstudio.browser.core.internal.model.RootDSE; 33 import org.apache.directory.ldapstudio.browser.core.internal.model.Search; 34 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 35 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 36 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 37 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 38 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; 39 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils; 40 41 42 public class InitializeAttributesJob extends AbstractAsyncBulkJob 43 { 44 45 private IEntry[] entries; 46 47 private boolean initOperationalAttributes; 48 49 50 public InitializeAttributesJob( IEntry[] entries, boolean initOperationalAttributes ) 51 { 52 this.entries = entries; 53 this.initOperationalAttributes = initOperationalAttributes; 54 setName( BrowserCoreMessages.jobs__init_entries_title_attonly ); 55 } 56 57 58 protected IConnection[] getConnections() 59 { 60 IConnection[] connections = new IConnection[entries.length]; 61 for ( int i = 0; i < connections.length; i++ ) 62 { 63 connections[i] = entries[i].getConnection(); 64 } 65 return connections; 66 } 67 68 69 protected Object [] getLockedObjects() 70 { 71 List l = new ArrayList (); 72 l.addAll( Arrays.asList( entries ) ); 73 return l.toArray(); 74 } 75 76 77 protected String getErrorMessage() 78 { 79 return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1 80 : BrowserCoreMessages.jobs__init_entries_error_n; 81 } 82 83 84 protected void executeBulkJob( ExtendedProgressMonitor monitor ) 85 { 86 monitor.beginTask( " ", entries.length + 2 ); monitor.reportProgress( " " ); 89 for ( int pi = 0; pi < entries.length && !monitor.isCanceled(); pi++ ) 90 { 91 monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_task, new String [] 92 { this.entries[pi].getDn().toString() } ) ); 93 monitor.worked( 1 ); 94 if ( entries[pi].getConnection() != null && entries[pi].getConnection().isOpened() 95 && entries[pi].isDirectoryEntry() ) 96 { 97 initializeAttributes( entries[pi], initOperationalAttributes, monitor ); 98 } 99 } 100 } 101 102 103 protected void runNotification() 104 { 105 for ( int pi = 0; pi < entries.length; pi++ ) 106 { 107 IEntry parent = entries[pi]; 108 if ( parent.getConnection() != null && entries[pi].getConnection().isOpened() && parent.isDirectoryEntry() ) 109 { 110 EventRegistry.fireEntryUpdated( new AttributesInitializedEvent( parent ), this ); 111 } 112 } 113 } 114 115 116 public static void initializeAttributes( IEntry entry, boolean initOperationalAttributes, 117 ExtendedProgressMonitor monitor ) 118 { 119 120 String [] returningAttributes = null; 122 LinkedHashSet raSet = new LinkedHashSet (); 123 raSet.add( ISearch.ALL_USER_ATTRIBUTES ); 124 if ( initOperationalAttributes ) 125 { 126 AttributeTypeDescription[] opAtds = SchemaUtils.getOperationalAttributeDescriptions( entry.getConnection() 127 .getSchema() ); 128 String [] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( opAtds ); 129 raSet.addAll( Arrays.asList( attributeTypeDescriptionNames ) ); 130 raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES ); 131 } 132 if ( entry instanceof RootDSE ) 133 { 134 raSet.add( ISearch.ALL_USER_ATTRIBUTES ); 135 raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES ); 136 } 137 if ( entry.isReferral() ) 138 { 139 raSet.add( IAttribute.REFERRAL_ATTRIBUTE ); 140 } 141 returningAttributes = ( String [] ) raSet.toArray( new String [raSet.size()] ); 142 143 initializeAttributes( entry, returningAttributes, monitor ); 144 } 145 146 147 public static void initializeAttributes( IEntry entry, String [] attributes, ExtendedProgressMonitor monitor ) 148 { 149 150 monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_att, 151 new String [] 152 { entry.getDn().toString() } ) ); 153 154 156 ISearch search = new Search( null, entry.getConnection(), entry.getDn(), ISearch.FILTER_TRUE, attributes, 158 ISearch.SCOPE_OBJECT, 0, 0, IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE, 159 false, false, null ); 160 entry.getConnection().search( search, monitor ); 161 162 entry.setAttributesInitialized( true ); 164 } 165 166 } 167 | Popular Tags |