You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/10/21 20:41:08 UTC
svn commit: r586929 [2/3] - in /directory/studio/trunk:
studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/
studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/
studio-l...
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportLdifJob.java Sun Oct 21 11:41:06 2007
@@ -28,15 +28,23 @@
import java.util.Arrays;
import java.util.List;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.SearchResult;
+
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.StudioProgressMonitor;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.ldapbrowser.core.internal.model.AttributeComparator;
import org.apache.directory.studio.ldapbrowser.core.internal.model.ConnectionException;
+import org.apache.directory.studio.ldapbrowser.core.internal.model.JNDIUtils;
import org.apache.directory.studio.ldapbrowser.core.internal.model.ReferralException;
+import org.apache.directory.studio.ldapbrowser.core.model.DN;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.NameException;
import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
@@ -46,44 +54,68 @@
import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifSepLine;
+/**
+ * Job to export directory content to an LDIF file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class ExportLdifJob extends AbstractEclipseJob
{
+ /** The filename of the LDIF file. */
private String exportLdifFilename;
- private IBrowserConnection connection;
+ /** The browser connection. */
+ private IBrowserConnection browserConnection;
+ /** The search parameter. */
private SearchParameter searchParameter;
- public ExportLdifJob( String exportLdifFilename, IBrowserConnection connection, SearchParameter searchParameter )
+ /**
+ * Creates a new instance of ExportLdifJob.
+ *
+ * @param exportLdifFilename the filename of the LDIF file
+ * @param browserConnection the browser connection
+ * @param searchParameter the search parameter
+ */
+ public ExportLdifJob( String exportLdifFilename, IBrowserConnection browserConnection, SearchParameter searchParameter )
{
this.exportLdifFilename = exportLdifFilename;
- this.connection = connection;
+ this.browserConnection = browserConnection;
this.searchParameter = searchParameter;
setName( BrowserCoreMessages.jobs__export_ldif_name );
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+ */
protected Connection[] getConnections()
{
return new Connection[]
- { connection.getConnection() };
+ { browserConnection.getConnection() };
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+ */
protected Object[] getLockedObjects()
{
- List l = new ArrayList();
- l.add( connection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
+ List<Object> l = new ArrayList<Object>();
+ l.add( browserConnection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
return l.toArray();
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+ */
protected void executeAsyncJob( StudioProgressMonitor monitor )
{
-
monitor.beginTask( BrowserCoreMessages.jobs__export_ldif_task, 2 );
monitor.reportProgress( " " ); //$NON-NLS-1$
monitor.worked( 1 );
@@ -96,7 +128,7 @@
// export
int count = 0;
- export( connection, searchParameter, bufferedWriter, count, monitor );
+ export( browserConnection, searchParameter, bufferedWriter, count, monitor );
// close file
bufferedWriter.close();
@@ -107,18 +139,18 @@
{
monitor.reportError( e );
}
-
}
- private static void export( IBrowserConnection connection, SearchParameter searchParameter, BufferedWriter bufferedWriter,
+
+ private static void export( IBrowserConnection browserConnection, SearchParameter searchParameter, BufferedWriter bufferedWriter,
int count, StudioProgressMonitor monitor ) throws IOException, ConnectionException
{
try
{
-
- AttributeComparator comparator = new AttributeComparator( connection );
- LdifEnumeration enumeration = connection.exportLdif( searchParameter, monitor );
+ AttributeComparator comparator = new AttributeComparator( browserConnection );
+ LdifEnumeration enumeration = search( browserConnection, searchParameter, monitor );
+
while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
{
LdifContainer container = enumeration.next( monitor );
@@ -147,24 +179,21 @@
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
new String[]
{ Integer.toString( count ) } ) );
-
}
-
}
}
catch ( ConnectionException ce )
{
-
- if ( ce.getLdapStatusCode() == 3 || ce.getLdapStatusCode() == 4 || ce.getLdapStatusCode() == 11 )
+ if ( ce.getLdapStatusCode() == ConnectionException.STAUS_CODE_TIMELIMIT_EXCEEDED
+ || ce.getLdapStatusCode() == ConnectionException.STAUS_CODE_SIZELIMIT_EXCEEDED
+ || ce.getLdapStatusCode() == ConnectionException.STAUS_CODE_ADMINLIMIT_EXCEEDED )
{
- // nothing
+ // ignore
}
else if ( ce instanceof ReferralException )
{
-
if ( searchParameter.getReferralsHandlingMethod() == IBrowserConnection.HANDLE_REFERRALS_FOLLOW )
{
-
ReferralException re = ( ReferralException ) ce;
ISearch[] referralSearches = re.getReferralSearches();
for ( int i = 0; i < referralSearches.length; i++ )
@@ -182,7 +211,6 @@
monitor.reportError( ce );
}
}
-
}
@@ -191,4 +219,93 @@
return BrowserCoreMessages.jobs__export_ldif_error;
}
+
+ static LdifEnumeration search( IBrowserConnection browserConnection, SearchParameter parameter, StudioProgressMonitor monitor )
+ throws ConnectionException
+ {
+ NamingEnumeration<SearchResult> result = SearchJob.search( browserConnection, parameter, monitor );
+
+ if(monitor.errorsReported())
+ {
+ throw JNDIUtils.createConnectionException( null, monitor.getException() );
+ }
+ return new JndiLdifEnumeration( result, parameter );
+ }
+
+ static class JndiLdifEnumeration implements LdifEnumeration
+ {
+
+ private NamingEnumeration<SearchResult> enumeration;
+
+ private SearchParameter parameter;
+
+
+ public JndiLdifEnumeration( NamingEnumeration<SearchResult> enumeration, SearchParameter parameter )
+ {
+ this.enumeration = enumeration;
+ this.parameter = parameter;
+ }
+
+
+ public boolean hasNext( StudioProgressMonitor monitor ) throws ConnectionException
+ {
+ try
+ {
+ return enumeration != null && enumeration.hasMore();
+ }
+ catch ( NamingException e )
+ {
+ throw JNDIUtils.createConnectionException( parameter, e );
+ }
+ }
+
+
+ public LdifContainer next( StudioProgressMonitor monitor ) throws ConnectionException
+ {
+ try
+ {
+ SearchResult sr = enumeration.next();
+ DN dn = JNDIUtils.getDn( sr );
+ LdifContentRecord record = LdifContentRecord.create( dn.toString() );
+
+ NamingEnumeration<? extends Attribute> attributeEnumeration = sr.getAttributes().getAll();
+ while ( attributeEnumeration.hasMore() )
+ {
+ Attribute attribute = attributeEnumeration.next();
+ String attributeName = attribute.getID();
+ NamingEnumeration<?> valueEnumeration = attribute.getAll();
+ while ( valueEnumeration.hasMore() )
+ {
+ Object o = valueEnumeration.next();
+ if ( o instanceof String )
+ {
+ record.addAttrVal( LdifAttrValLine.create( attributeName, ( String ) o ) );
+ }
+ if ( o instanceof byte[] )
+ {
+ record.addAttrVal( LdifAttrValLine.create( attributeName, ( byte[] ) o ) );
+ }
+ }
+ }
+
+ record.finish( LdifSepLine.create() );
+
+ return record;
+
+ }
+ catch ( NamingException e )
+ {
+ throw JNDIUtils.createConnectionException( parameter, e );
+ }
+ catch ( NameException e )
+ {
+ throw new ConnectionException( e );
+ }
+ catch ( NoSuchFieldException e )
+ {
+ throw new ConnectionException( e );
+ }
+ }
+ }
+
}
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportXlsJob.java Sun Oct 21 11:41:06 2007
@@ -23,10 +23,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import org.apache.commons.codec.digest.DigestUtils;
@@ -50,25 +47,44 @@
import org.eclipse.core.runtime.Preferences;
+/**
+ * Job to export directory content to an XLS file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class ExportXlsJob extends AbstractEclipseJob
{
+ /** The maximum count limit */
public static final int MAX_COUNT_LIMIT = 65000;
- private String exportLdifFilename;
+ /** The filename of the XLS file. */
+ private String exportXlsFilename;
- private IBrowserConnection connection;
+ /** The browser connection. */
+ private IBrowserConnection browserConnection;
+ /** The search parameter. */
private SearchParameter searchParameter;
+ /** The export dn flag. */
private boolean exportDn;
- public ExportXlsJob( String exportLdifFilename, IBrowserConnection connection, SearchParameter searchParameter,
- boolean exportDn )
+ /**
+ * Creates a new instance of ExportXlsJob.
+ *
+ * @param exportLdifFilename the export ldif filename
+ * @param browserConnection the browser connection
+ * @param searchParameter the search parameter
+ * @param exportDn true to export the DN
+ */
+ public ExportXlsJob( String exportLdifFilename, IBrowserConnection browserConnection,
+ SearchParameter searchParameter, boolean exportDn )
{
- this.exportLdifFilename = exportLdifFilename;
- this.connection = connection;
+ this.exportXlsFilename = exportLdifFilename;
+ this.browserConnection = browserConnection;
this.searchParameter = searchParameter;
this.exportDn = exportDn;
@@ -76,24 +92,31 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+ */
protected Connection[] getConnections()
{
return new Connection[]
- { connection.getConnection() };
+ { browserConnection.getConnection() };
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+ */
protected Object[] getLockedObjects()
{
- List l = new ArrayList();
- l.add( connection.getUrl() + "_" + DigestUtils.shaHex( exportLdifFilename ) );
- return l.toArray();
+ return new Object[]
+ { browserConnection.getUrl() + "_" + DigestUtils.shaHex( exportXlsFilename ) };
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#executeAsyncJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+ */
protected void executeAsyncJob( StudioProgressMonitor monitor )
{
-
monitor.beginTask( BrowserCoreMessages.jobs__export_xls_task, 2 );
monitor.reportProgress( " " ); //$NON-NLS-1$
monitor.worked( 1 );
@@ -107,7 +130,7 @@
// header
HSSFRow headerRow = sheet.createRow( 0 );
- LinkedHashMap attributeNameMap = new LinkedHashMap();
+ LinkedHashMap<String, Short> attributeNameMap = new LinkedHashMap<String, Short>();
if ( this.exportDn )
{
short cellNum = ( short ) 0;
@@ -134,10 +157,9 @@
// export
try
{
-
int count = 0;
- export( connection, searchParameter, sheet, headerRow, count, monitor, attributeNameMap, valueDelimiter,
- binaryEncoding, this.exportDn );
+ exportToXls( browserConnection, searchParameter, sheet, headerRow, count, monitor, attributeNameMap,
+ valueDelimiter, binaryEncoding, this.exportDn );
}
catch ( Exception e )
{
@@ -165,7 +187,7 @@
try
{
- FileOutputStream fileOut = new FileOutputStream( exportLdifFilename );
+ FileOutputStream fileOut = new FileOutputStream( exportXlsFilename );
wb.write( fileOut );
fileOut.close();
}
@@ -176,14 +198,31 @@
}
- private static void export( IBrowserConnection connection, SearchParameter searchParameter, HSSFSheet sheet,
- HSSFRow headerRow, int count, StudioProgressMonitor monitor, LinkedHashMap attributeNameMap,
- String valueDelimiter, int binaryEncoding, boolean exportDn ) throws IOException, ConnectionException
+ /**
+ * Exports to XLS.
+ *
+ * @param browserConnection the browser connection
+ * @param searchParameter the search parameter
+ * @param sheet the sheet
+ * @param headerRow the header row
+ * @param count the count
+ * @param monitor the monitor
+ * @param attributeNameMap the attribute name map
+ * @param valueDelimiter the value delimiter
+ * @param binaryEncoding the binary encoding
+ * @param exportDn the export dn
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws ConnectionException the connection exception
+ */
+ private static void exportToXls( IBrowserConnection browserConnection, SearchParameter searchParameter,
+ HSSFSheet sheet, HSSFRow headerRow, int count, StudioProgressMonitor monitor,
+ LinkedHashMap<String, Short> attributeNameMap, String valueDelimiter, int binaryEncoding, boolean exportDn )
+ throws IOException, ConnectionException
{
try
{
-
- LdifEnumeration enumeration = connection.exportLdif( searchParameter, monitor );
+ LdifEnumeration enumeration = ExportLdifJob.search( browserConnection, searchParameter, monitor );
while ( !monitor.isCanceled() && enumeration.hasNext( monitor ) )
{
LdifContainer container = enumeration.next( monitor );
@@ -191,8 +230,8 @@
if ( container instanceof LdifContentRecord )
{
LdifContentRecord record = ( LdifContentRecord ) container;
- recordToHSSFRow( connection, record, sheet, headerRow, attributeNameMap, valueDelimiter, binaryEncoding,
- exportDn );
+ recordToHSSFRow( browserConnection, record, sheet, headerRow, attributeNameMap, valueDelimiter,
+ binaryEncoding, exportDn );
count++;
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__export_progress,
@@ -211,19 +250,15 @@
}
else if ( ce instanceof ReferralException )
{
-
if ( searchParameter.getReferralsHandlingMethod() == IBrowserConnection.HANDLE_REFERRALS_FOLLOW )
{
-
ReferralException re = ( ReferralException ) ce;
ISearch[] referralSearches = re.getReferralSearches();
- for ( int i = 0; i < referralSearches.length; i++ )
+ for ( ISearch referralSearch : referralSearches )
{
- ISearch referralSearch = referralSearches[i];
-
// export recursive
- export( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(), sheet, headerRow,
- count, monitor, attributeNameMap, valueDelimiter, binaryEncoding, exportDn );
+ exportToXls( referralSearch.getBrowserConnection(), referralSearch.getSearchParameter(), sheet,
+ headerRow, count, monitor, attributeNameMap, valueDelimiter, binaryEncoding, exportDn );
}
}
}
@@ -232,16 +267,28 @@
monitor.reportError( ce );
}
}
-
}
- private static void recordToHSSFRow( IBrowserConnection connection, LdifContentRecord record, HSSFSheet sheet, HSSFRow headerRow,
- Map headerRowAttributeNameMap, String valueDelimiter, int binaryEncoding, boolean exportDn )
+ /**
+ * Transforms an LDIF record to an HSSF row.
+ *
+ * @param browserConnection the browser connection
+ * @param record the record
+ * @param sheet the sheet
+ * @param headerRow the header row
+ * @param headerRowAttributeNameMap the header row attribute name map
+ * @param valueDelimiter the value delimiter
+ * @param binaryEncoding the binary encoding
+ * @param exportDn the export dn
+ */
+ private static void recordToHSSFRow( IBrowserConnection browserConnection, LdifContentRecord record,
+ HSSFSheet sheet, HSSFRow headerRow, Map<String, Short> headerRowAttributeNameMap, String valueDelimiter,
+ int binaryEncoding, boolean exportDn )
{
-
// group multi-valued attributes
- Map attributeMap = ExportCsvJob.getAttributeMap( null, record, valueDelimiter, "UTF-16", binaryEncoding );
+ Map<String, String> attributeMap = ExportCsvJob.getAttributeMap( null, record, valueDelimiter, "UTF-16",
+ binaryEncoding );
// output attributes
HSSFRow row = sheet.createRow( sheet.getLastRowNum() + 1 );
@@ -251,9 +298,8 @@
cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
cell.setCellValue( record.getDnLine().getValueAsString() );
}
- for ( Iterator it = attributeMap.keySet().iterator(); it.hasNext(); )
+ for ( String attributeName : attributeMap.keySet() )
{
- String attributeName = ( String ) it.next();
String value = ( String ) attributeMap.get( attributeName );
if ( !headerRowAttributeNameMap.containsKey( attributeName ) )
@@ -287,6 +333,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+ */
protected String getErrorMessage()
{
return BrowserCoreMessages.jobs__export_xls_error;
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesJob.java Sun Oct 21 11:41:06 2007
@@ -23,33 +23,53 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.StudioProgressMonitor;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent;
import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
-import org.apache.directory.studio.ldapbrowser.core.internal.model.RootDSE;
+import org.apache.directory.studio.ldapbrowser.core.internal.model.BaseDNEntry;
+import org.apache.directory.studio.ldapbrowser.core.internal.model.DirectoryMetadataEntry;
import org.apache.directory.studio.ldapbrowser.core.internal.model.Search;
+import org.apache.directory.studio.ldapbrowser.core.model.DN;
import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.core.model.NameException;
import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeTypeDescription;
import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
+/**
+ * Job to initialize the attributes of an entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class InitializeAttributesJob extends AbstractNotificationJob
{
+ /** The entries. */
private IEntry[] entries;
+ /** The flag if operational attributes should be initialized. */
private boolean initOperationalAttributes;
+ /**
+ * Creates a new instance of InitializeAttributesJob.
+ *
+ * @param entries the entries
+ * @param initOperationalAttributes true if operational attributes should be initialized
+ */
public InitializeAttributesJob( IEntry[] entries, boolean initOperationalAttributes )
{
this.entries = entries;
@@ -58,6 +78,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+ */
protected Connection[] getConnections()
{
Connection[] connections = new Connection[entries.length];
@@ -69,14 +92,20 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+ */
protected Object[] getLockedObjects()
{
- List l = new ArrayList();
+ List<Object> l = new ArrayList<Object>();
l.addAll( Arrays.asList( entries ) );
return l.toArray();
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+ */
protected String getErrorMessage()
{
return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1
@@ -84,6 +113,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+ */
protected void executeNotificationJob( StudioProgressMonitor monitor )
{
monitor.beginTask( " ", entries.length + 2 ); //$NON-NLS-1$
@@ -102,6 +134,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+ */
protected void runNotification()
{
for ( int pi = 0; pi < entries.length; pi++ )
@@ -115,27 +150,33 @@
}
+ /**
+ * Initializes the attributes.
+ *
+ * @param entry the entry
+ * @param initOperationalAttributes true if operational attributes should be initialized
+ * @param monitor the progress monitor
+ */
public static void initializeAttributes( IEntry entry, boolean initOperationalAttributes,
StudioProgressMonitor monitor )
{
-
// get user attributes or both user and operational attributes
String[] returningAttributes = null;
- LinkedHashSet raSet = new LinkedHashSet();
+ LinkedHashSet<String> raSet = new LinkedHashSet<String>();
raSet.add( ISearch.ALL_USER_ATTRIBUTES );
if ( initOperationalAttributes )
{
- AttributeTypeDescription[] opAtds = SchemaUtils.getOperationalAttributeDescriptions( entry.getBrowserConnection()
- .getSchema() );
+ AttributeTypeDescription[] opAtds = SchemaUtils.getOperationalAttributeDescriptions( entry
+ .getBrowserConnection().getSchema() );
String[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( opAtds );
raSet.addAll( Arrays.asList( attributeTypeDescriptionNames ) );
raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
}
- if ( entry instanceof RootDSE )
- {
- raSet.add( ISearch.ALL_USER_ATTRIBUTES );
- raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
- }
+// if ( entry instanceof RootDSE )
+// {
+// raSet.add( ISearch.ALL_USER_ATTRIBUTES );
+// raSet.add( ISearch.ALL_OPERATIONAL_ATTRIBUTES );
+// }
if ( entry.isReferral() )
{
raSet.add( IAttribute.REFERRAL_ATTRIBUTE );
@@ -146,9 +187,15 @@
}
+ /**
+ * Initializes the attributes.
+ *
+ * @param entry the entry
+ * @param attributes the returning attributes
+ * @param monitor the progress monitor
+ */
public static void initializeAttributes( IEntry entry, String[] attributes, StudioProgressMonitor monitor )
{
-
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_att,
new String[]
{ entry.getDn().toString() } ) );
@@ -157,18 +204,39 @@
if ( entry instanceof IRootDSE )
{
- IEntry[] oldChildren = entry.getChildren();
- for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
- {
- if ( oldChildren[i] != null )
- {
- entry.deleteChild( oldChildren[i] );
- }
- }
- entry.setChildrenInitialized( false );
+// IEntry[] oldChildren = entry.getChildren();
+// for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
+// {
+// if ( oldChildren[i] != null )
+// {
+// entry.deleteChild( oldChildren[i] );
+// }
+// }
+// entry.setChildrenInitialized( false );
// special handling for Root DSE
- entry.getBrowserConnection().fetchRootDSE( monitor );
+ loadRootDSE( entry.getBrowserConnection(), monitor );
+
+// if ( !monitor.errorsReported() )
+// {
+// try
+// {
+// monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
+// loadRootDSE( entry.getBrowserConnection(), monitor );
+// monitor.worked( 1 );
+// }
+// catch ( Exception e )
+// {
+// monitor.reportError( BrowserCoreMessages.model__error_loading_rootdse );
+// rootDSE = null;
+// }
+//
+// if ( monitor.errorsReported() )
+// {
+// close();
+// }
+// }
+
entry.setAttributesInitialized( true );
entry.setChildrenInitialized( true );
}
@@ -178,11 +246,163 @@
ISearch search = new Search( null, entry.getBrowserConnection(), entry.getDn(), entry.isSubentry()?ISearch.FILTER_SUBENTRY:ISearch.FILTER_TRUE, attributes,
ISearch.SCOPE_OBJECT, 0, 0, IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE,
false, false, null );
- entry.getBrowserConnection().search( search, monitor );
+ SearchJob.searchAndUpdateModel( entry.getBrowserConnection(), search, monitor );
// set initialized state
entry.setAttributesInitialized( true );
}
}
+
+ /**
+ * Loads the Root DSE.
+ *
+ * @param browserConnection the browser connection
+ * @param monitor the progress monitor
+ *
+ * @throws Exception the exception
+ */
+ static void loadRootDSE( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
+ {
+// if(rootDSE == null)
+// {
+// rootDSE = new RootDSE( this );
+// cacheEntry( rootDSE );
+// }
+
+ // delete old children
+ IEntry[] oldChildren = browserConnection.getRootDSE().getChildren();
+ for ( int i = 0; oldChildren != null && i < oldChildren.length; i++ )
+ {
+ if ( oldChildren[i] != null )
+ {
+ browserConnection.getRootDSE().deleteChild( oldChildren[i] );
+ }
+ }
+ browserConnection.getRootDSE().setChildrenInitialized( false );
+
+ // get well-known root DSE attributes, includes + and *
+ ISearch search = new Search( null, browserConnection, new DN(), ISearch.FILTER_TRUE,
+ IBrowserConnection.ROOT_DSE_ATTRIBUTES, ISearch.SCOPE_OBJECT, 0, 0,
+ IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE, false, false,
+ null );
+ SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+
+ // get base DNs
+ if( !browserConnection.isFetchBaseDNs() && browserConnection.getBaseDN() != null && !"".equals( browserConnection.getBaseDN().toString() ))
+ {
+ // only add the specified base DN
+ DN dn = browserConnection.getBaseDN();
+ IEntry entry = new BaseDNEntry( new DN( dn ), browserConnection );
+ browserConnection.cacheEntry( entry );
+ browserConnection.getRootDSE().addChild( entry );
+
+ // check if entry exists
+ // TODO: use browserConnection.getEntry( dn, monitor ) ??
+ search = new Search( null, browserConnection, dn, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, ISearch.SCOPE_OBJECT, 1, 0,
+ IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE, true, true, null );
+ SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+ }
+ else
+ {
+ // get naming contexts
+ Set<String> namingContextSet = new HashSet<String>();
+ IAttribute attribute = browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS );
+ if ( attribute != null )
+ {
+ String[] values = attribute.getStringValues();
+ for ( int i = 0; i < values.length; i++ )
+ {
+ namingContextSet.add( values[i] );
+ }
+ }
+ for ( String namingContext : namingContextSet )
+ {
+ if ( !"".equals( namingContext ) ) { //$NON-NLS-1$
+ try
+ {
+ IEntry entry = new BaseDNEntry( new DN( namingContext ), browserConnection );
+ browserConnection.getRootDSE().addChild( entry );
+ browserConnection.cacheEntry( entry );
+ }
+ catch ( Exception e )
+ {
+ monitor.reportError( BrowserCoreMessages.model__error_setting_base_dn, e );
+ }
+ }
+ else
+ {
+ // special handling of empty namingContext: perform a one-level search and add all result DNs to the set
+ search = new Search( null, browserConnection, new DN(), ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, ISearch.SCOPE_ONELEVEL, 0,
+ 0, IBrowserConnection.DEREFERENCE_ALIASES_NEVER, IBrowserConnection.HANDLE_REFERRALS_IGNORE, false, false, null );
+ SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+ ISearchResult[] results = search.getSearchResults();
+ for ( int k = 0; results != null && k < results.length; k++ )
+ {
+ ISearchResult result = results[k];
+ IEntry entry = result.getEntry();
+ browserConnection.getRootDSE().addChild( entry );
+ }
+ }
+ }
+ }
+
+ // get schema sub-entry
+ DirectoryMetadataEntry[] schemaEntries = getDirectoryMetadataEntries( browserConnection, IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY );
+ for ( int i = 0; i < schemaEntries.length; i++ )
+ {
+ schemaEntries[i].setSchemaEntry( true );
+ browserConnection.getRootDSE().addChild( ( IEntry ) schemaEntries[i] );
+ }
+
+ // get other metadata entries
+ String[] metadataAttributeNames = new String[]
+ { IRootDSE.ROOTDSE_ATTRIBUTE_MONITORCONTEXT, IRootDSE.ROOTDSE_ATTRIBUTE_CONFIGCONTEXT,
+ IRootDSE.ROOTDSE_ATTRIBUTE_DSANAME };
+ for ( int x = 0; x < metadataAttributeNames.length; x++ )
+ {
+ DirectoryMetadataEntry[] metadataEntries = getDirectoryMetadataEntries( browserConnection, metadataAttributeNames[x] );
+ for ( int i = 0; i < metadataEntries.length; i++ )
+ {
+ browserConnection.getRootDSE().addChild( ( IEntry ) metadataEntries[i] );
+ }
+ }
+
+ // set flags
+ browserConnection.getRootDSE().setHasMoreChildren( false );
+ browserConnection.getRootDSE().setAttributesInitialized( true );
+ browserConnection.getRootDSE().setChildrenInitialized( true );
+ browserConnection.getRootDSE().setHasChildrenHint( true );
+ browserConnection.getRootDSE().setDirectoryEntry( true );
+ }
+
+
+ private static DirectoryMetadataEntry[] getDirectoryMetadataEntries( IBrowserConnection browserConnection, String metadataAttributeName )
+ {
+ List<DN> metadataEntryList = new ArrayList<DN>();
+ IAttribute attribute = browserConnection.getRootDSE().getAttribute( metadataAttributeName );
+ if ( attribute != null )
+ {
+ String[] values = attribute.getStringValues();
+ for ( int i = 0; i < values.length; i++ )
+ {
+ try
+ {
+ metadataEntryList.add( new DN( values[i] ) );
+ }
+ catch ( NameException e )
+ {
+ }
+ }
+ }
+
+ DirectoryMetadataEntry[] metadataEntries = new DirectoryMetadataEntry[metadataEntryList.size()];
+ for ( int i = 0; i < metadataEntryList.size(); i++ )
+ {
+ metadataEntries[i] = new DirectoryMetadataEntry( metadataEntryList.get( i ), browserConnection );
+ metadataEntries[i].setDirectoryEntry( true );
+ browserConnection.cacheEntry( metadataEntries[i] );
+ }
+ return metadataEntries;
+ }
}
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenJob.java Sun Oct 21 11:41:06 2007
@@ -43,12 +43,24 @@
import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+/**
+ * Job to initialize the child entries of an entry
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class InitializeChildrenJob extends AbstractNotificationJob
{
+ /** The entries. */
private IEntry[] entries;
+ /**
+ * Creates a new instance of InitializeChildrenJob.
+ *
+ * @param entries the entries
+ */
public InitializeChildrenJob( IEntry[] entries )
{
this.entries = entries;
@@ -56,6 +68,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+ */
protected Connection[] getConnections()
{
Connection[] connections = new Connection[entries.length];
@@ -67,14 +82,20 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+ */
protected Object[] getLockedObjects()
{
- List l = new ArrayList();
+ List<Object> l = new ArrayList<Object>();
l.addAll( Arrays.asList( entries ) );
return l.toArray();
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+ */
protected String getErrorMessage()
{
return entries.length == 1 ? BrowserCoreMessages.jobs__init_entries_error_1
@@ -82,6 +103,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+ */
protected void executeNotificationJob( StudioProgressMonitor monitor )
{
monitor.beginTask( " ", entries.length + 2 ); //$NON-NLS-1$
@@ -102,6 +126,9 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+ */
protected void runNotification()
{
for ( int pi = 0; pi < entries.length; pi++ )
@@ -115,9 +142,14 @@
}
+ /**
+ * Initializes the child entries.
+ *
+ * @param parent the parent
+ * @param monitor the progress monitor
+ */
public static void initializeChildren( IEntry parent, StudioProgressMonitor monitor )
{
-
if ( parent instanceof IRootDSE )
{
// special handling for Root DSE
@@ -161,7 +193,7 @@
.getDefault().getPluginPreferences().getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ),
BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ), null );
- parent.getBrowserConnection().search( search, monitor );
+ SearchJob.searchAndUpdateModel( parent.getBrowserConnection(), search, monitor );
ISearchResult[] srs = search.getSearchResults();
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_subcount,
new String[]
@@ -225,7 +257,7 @@
if ( BrowserCorePlugin.getDefault().getPluginPreferences().getBoolean(
BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) )
{
- parent.getBrowserConnection().search( subSearch, monitor );
+ SearchJob.searchAndUpdateModel( parent.getBrowserConnection(), subSearch, monitor );
ISearchResult[] subSrs = subSearch.getSearchResults();
monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_subcount,
new String[]
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/MoveEntriesJob.java Sun Oct 21 11:41:06 2007
@@ -131,8 +131,7 @@
DN newDn = new DN( oldEntry.getRdn(), newParent.getDn() );
// move in directory
- // TODO: use manual/simulated move, if move of subtree is not
- // supported
+ // TODO: use manual/simulated move, if move of subtree is not supported (JNDI)
int errorStatusSize1 = monitor.getErrorStatus( "" ).getChildren().length; //$NON-NLS-1$
moveEntry( browserConnection, oldEntry, newDn.toString(), monitor );
//connection.move( oldEntry, newParent.getDn(), monitor );
@@ -142,7 +141,7 @@
{
// move in parent
oldParent.deleteChild( oldEntry );
- IEntry newEntry = browserConnection.getEntry( newDn, monitor );
+ IEntry newEntry = ReadEntryJob.getEntry( browserConnection, newDn, monitor );
newEntries[i] = newEntry;
newParent.addChild( newEntry );
newParent.setHasMoreChildren( false );
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReadEntryJob.java Sun Oct 21 11:41:06 2007
@@ -21,31 +21,46 @@
package org.apache.directory.studio.ldapbrowser.core.jobs;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.StudioProgressMonitor;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
+import org.apache.directory.studio.ldapbrowser.core.internal.model.Search;
import org.apache.directory.studio.ldapbrowser.core.model.DN;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
import org.apache.directory.studio.ldapbrowser.core.model.ModelModificationException;
+/**
+ * Job to read a single entry from directory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class ReadEntryJob extends AbstractNotificationJob
{
- private IBrowserConnection connection;
+ /** The browser connection. */
+ private IBrowserConnection browserConnection;
+ /** The DN of the entry. */
private DN dn;
+ /** The entry read from directory. */
private IEntry readEntry;
- public ReadEntryJob( IBrowserConnection connection, DN dn )
+ /**
+ * Creates a new instance of ReadEntryJob.
+ *
+ * @param browserConnection the browser connection
+ * @param dn the DN of the entry
+ */
+ public ReadEntryJob( IBrowserConnection browserConnection, DN dn )
{
- this.connection = connection;
+ this.browserConnection = browserConnection;
this.dn = dn;
this.readEntry = null;
@@ -53,36 +68,52 @@
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+ */
protected Connection[] getConnections()
{
return new Connection[]
- { connection.getConnection() };
+ { browserConnection.getConnection() };
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+ */
protected Object[] getLockedObjects()
{
- List l = new ArrayList();
- l.add( connection );
- return l.toArray();
+ return new Object[]
+ { browserConnection };
}
+ /**
+ * Gets the read entry.
+ *
+ * @return the read entry
+ */
public IEntry getReadEntry()
{
return readEntry;
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+ */
protected String getErrorMessage()
{
return BrowserCoreMessages.jobs__read_entry_error;
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+ */
protected void executeNotificationJob( StudioProgressMonitor pm ) throws ModelModificationException
{
- readEntry = connection.getEntryFromCache( dn );
+ readEntry = browserConnection.getEntryFromCache( dn );
if ( readEntry == null )
{
@@ -91,13 +122,60 @@
pm.reportProgress( " " ); //$NON-NLS-1$
pm.worked( 1 );
- readEntry = connection.getEntry( dn, pm );
+ readEntry = getEntry( browserConnection, dn, pm );
}
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+ */
protected void runNotification()
{
+ }
+
+
+ /**
+ * Gets the entry, either from the BrowserConnection's cache or from the directory.
+ *
+ * @param browserConnection the browser connection
+ * @param dn the DN of the entry
+ * @param monitor the progress monitor
+ *
+ * @return the read entry
+ */
+ static IEntry getEntry( IBrowserConnection browserConnection, DN dn, StudioProgressMonitor monitor )
+ {
+ try
+ {
+ // first check cache
+ IEntry entry = browserConnection.getEntryFromCache( dn );
+ if ( entry != null )
+ {
+ return entry;
+ }
+
+ // search in directory
+ ISearch search = new Search( null, browserConnection, dn, null, ISearch.NO_ATTRIBUTES,
+ ISearch.SCOPE_OBJECT, 1, 0, IBrowserConnection.DEREFERENCE_ALIASES_NEVER,
+ IBrowserConnection.HANDLE_REFERRALS_IGNORE, true, true, null );
+ SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
+ ISearchResult[] srs = search.getSearchResults();
+ if ( srs.length > 0 )
+ {
+ return srs[0].getEntry();
+ }
+ else
+ {
+ monitor.reportError( BrowserCoreMessages.bind( BrowserCoreMessages.model__no_such_entry, dn ) );
+ return null;
+ }
+ }
+ catch ( Exception e )
+ {
+ monitor.reportError( e.getMessage(), e );
+ return null;
+ }
}
}
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java Sun Oct 21 11:41:06 2007
@@ -21,82 +21,161 @@
package org.apache.directory.studio.ldapbrowser.core.jobs;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.StudioProgressMonitor;
-import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.ldapbrowser.core.events.BrowserConnectionUpdateEvent;
import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.model.DN;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+/**
+ * Job to reload the schema.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class ReloadSchemasJob extends AbstractNotificationJob
{
- private IBrowserConnection[] browserConnections;
+ /** The browser connection. */
+ private IBrowserConnection browserConnection;
- public ReloadSchemasJob( IBrowserConnection[] connections )
+ /**
+ * Creates a new instance of ReloadSchemasJob.
+ *
+ * @param browserConnection the browser connection
+ */
+ public ReloadSchemasJob( IBrowserConnection browserConnection )
{
- this.browserConnections = connections;
- setName( connections.length == 1 ? BrowserCoreMessages.jobs__reload_schemas_name_1
- : BrowserCoreMessages.jobs__reload_schemas_name_n );
+ this.browserConnection = browserConnection;
+ setName( BrowserCoreMessages.jobs__reload_schemas_name_1 );
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getConnections()
+ */
protected Connection[] getConnections()
{
- Connection[] connections = new Connection[browserConnections.length];
- for ( int i = 0; i < browserConnections.length; i++ )
- {
- connections[i] = browserConnections[i].getConnection();
- }
- return connections;
+ return new Connection[]
+ { browserConnection.getConnection() };
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getLockedObjects()
+ */
protected Object[] getLockedObjects()
{
- List l = new ArrayList();
- l.addAll( Arrays.asList( browserConnections ) );
- return l.toArray();
+ return new IBrowserConnection[]
+ { browserConnection };
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#executeNotificationJob(org.apache.directory.studio.connection.core.StudioProgressMonitor)
+ */
protected void executeNotificationJob( StudioProgressMonitor monitor )
{
- monitor.beginTask( " ", browserConnections.length + 1 ); //$NON-NLS-1$
+ monitor.beginTask( " ", 3 ); //$NON-NLS-1$
monitor.reportProgress( " " ); //$NON-NLS-1$
- for ( int i = 0; i < browserConnections.length; i++ )
- {
- monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__reload_schemas_task, new String[]
- { browserConnections[i].getConnection().getName() } ) );
- monitor.worked( 1 );
-
- browserConnections[i].reloadSchema( monitor );
- }
+ monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__reload_schemas_task, new String[]
+ { browserConnection.getConnection().getName() } ) );
+ monitor.worked( 1 );
+
+ // load root DSE
+ monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
+ InitializeAttributesJob.initializeAttributes( browserConnection.getRootDSE(), true, monitor );
+ monitor.worked( 1 );
+
+ // load schema
+ monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
+ reloadSchema( browserConnection, monitor );
+ monitor.worked( 1 );
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractNotificationJob#runNotification()
+ */
protected void runNotification()
{
- for ( IBrowserConnection browserConnection : browserConnections )
- {
- BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
- browserConnection, BrowserConnectionUpdateEvent.Detail.SCHEMA_UPDATED );
- EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent, this );
- }
+ BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
+ browserConnection, BrowserConnectionUpdateEvent.Detail.SCHEMA_UPDATED );
+ EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent, this );
}
+ /**
+ * @see org.apache.directory.studio.ldapbrowser.core.jobs.AbstractEclipseJob#getErrorMessage()
+ */
protected String getErrorMessage()
{
- return browserConnections.length == 1 ? BrowserCoreMessages.jobs__reload_schemas_error_1
- : BrowserCoreMessages.jobs__reload_schemas_error_n;
+ return BrowserCoreMessages.jobs__reload_schemas_error_1;
+ }
+
+
+ /**
+ * Reloads the schema.
+ *
+ * @param browserConnection the browser connection
+ * @param monitor the progress monitor
+ */
+ public static void reloadSchema( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
+ {
+ browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+
+ try
+ {
+ if ( browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
+ {
+ SearchParameter sp = new SearchParameter();
+ sp.setSearchBase( new DN( browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
+ .getStringValue() ) );
+ sp.setFilter( Schema.SCHEMA_FILTER );
+ sp.setScope( ISearch.SCOPE_OBJECT );
+ sp.setReturningAttributes( new String[]
+ { Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES, Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES,
+ Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES,
+ Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE, IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
+ IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
+
+ LdifEnumeration le = ExportLdifJob.search( browserConnection, sp, monitor );
+ if ( le.hasNext( monitor ) )
+ {
+ LdifContentRecord schemaRecord = ( LdifContentRecord ) le.next( monitor );
+ Schema schema = new Schema();
+ schema.loadFromRecord( schemaRecord );
+ browserConnection.setSchema( schema );
+ // TODO: Schema update event
+// EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
+// ConnectionUpdateEvent.EventDetail.SCHEMA_LOADED ), this );
+ }
+ else
+ {
+ monitor.reportError( BrowserCoreMessages.model__no_schema_information );
+ }
+ }
+ else
+ {
+ monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
+ }
+ }
+ catch ( Exception e )
+ {
+ monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
+ e.printStackTrace();
+ }
}
}
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameEntryJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameEntryJob.java?rev=586929&r1=586928&r2=586929&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameEntryJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/RenameEntryJob.java Sun Oct 21 11:41:06 2007
@@ -136,7 +136,7 @@
// rename in parent
parent.deleteChild( oldEntry );
- newEntry = browserConnection.getEntry( newDn, monitor );
+ newEntry = ReadEntryJob.getEntry( browserConnection, newDn, monitor );
parent.addChild( newEntry );
parent.setHasMoreChildren( false );