You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/08/05 19:52:13 UTC
svn commit: r801337 - in /directory/apacheds/trunk:
server-jndi/src/main/java/org/apache/directory/server/configuration/
xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/
xdbm-base/src/main/java/org/apache/directory/server/...
Author: elecharny
Date: Wed Aug 5 17:52:12 2009
New Revision: 801337
URL: http://svn.apache.org/viewvc?rev=801337&view=rev
Log:
Removed ^M in files
Modified:
directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
Modified: directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java?rev=801337&r1=801336&r2=801337&view=diff
==============================================================================
--- directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java (original)
+++ directory/apacheds/trunk/server-jndi/src/main/java/org/apache/directory/server/configuration/ApacheDS.java Wed Aug 5 17:52:12 2009
@@ -1,414 +1,414 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.directory.server.configuration;
-
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.directory.server.constants.ApacheSchemaConstants;
-import org.apache.directory.server.constants.ServerDNConstants;
-import org.apache.directory.server.core.DefaultDirectoryService;
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.entry.ClonedServerEntry;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.ldap.LdapServer;
-import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
-import org.apache.directory.server.protocol.shared.store.LdifLoadFilter;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * Apache Directory Server top level.
- *
- * @org.apache.xbean.XBean
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ApacheDS
-{
- private static final Logger LOG = LoggerFactory.getLogger( ApacheDS.class.getName() );
-
- /** Default delay between two flushes to the backend */
- private static final long DEFAULT_SYNC_PERIOD_MILLIS = 20000;
-
- /** Wainting period between two flushes to the backend */
- private long synchPeriodMillis = DEFAULT_SYNC_PERIOD_MILLIS;
-
- /** Directory where are stored the LDIF files to be loaded at startup */
- private File ldifDirectory;
-
- private final List<LdifLoadFilter> ldifFilters = new ArrayList<LdifLoadFilter>();
-
- /** The LDAP server protocol handler */
- private final LdapServer ldapServer;
-
- /** The directory service */
- private DirectoryService directoryService;
-
-
- /**
- * Creates a new instance of the ApacheDS server
- *
- * @param directoryService
- * @param ldapServer
- */
- public ApacheDS( LdapServer ldapServer )
- {
- LOG.info( "Starting the Apache Directory Server" );
-
- this.ldapServer = ldapServer;
-
- directoryService = ldapServer.getDirectoryService();
-
- if ( directoryService == null )
- {
- directoryService = new DefaultDirectoryService();
- }
- }
-
-
- /**
- * Start the server :
- * <li>initialize the DirectoryService</li>
- * <li>start the LDAP server</li>
- * <li>start the LDAPS server</li>
- *
- * @throws NamingException If the server cannot be started
- * @throws IOException If an IO error occured while reading some file
- */
- public void startup() throws Exception
- {
- LOG.debug( "Starting the server" );
-
- // Start the directory service if not started yet
- if ( ! directoryService.isStarted() )
- {
- LOG.debug( "1. Starting the DirectoryService" );
- directoryService.startup();
- }
-
- // Load the LDIF files - if any - into the server
- loadLdifs();
-
- // Start the LDAP server
- if ( ldapServer != null && ! ldapServer.isStarted() )
- {
- LOG.debug( "3. Starting the LDAP server" );
- ldapServer.start();
- }
-
- LOG.debug( "Server successfully started" );
- }
-
-
- public boolean isStarted()
- {
- if ( ldapServer != null )
- {
- return ( ldapServer.isStarted() );
- }
-
- return directoryService.isStarted();
- }
-
-
- public void shutdown() throws Exception
- {
- if ( ldapServer != null && ldapServer.isStarted() )
- {
- ldapServer.stop();
- }
-
- directoryService.shutdown();
- }
-
-
- public LdapServer getLdapServer()
- {
- return ldapServer;
- }
-
-
- public DirectoryService getDirectoryService()
- {
- return directoryService;
- }
-
-
- public long getSynchPeriodMillis()
- {
- return synchPeriodMillis;
- }
-
-
- public void setSynchPeriodMillis( long synchPeriodMillis )
- {
- LOG.info( "Set the synchPeriodMillis to {}", synchPeriodMillis );
- this.synchPeriodMillis = synchPeriodMillis;
- }
-
-
- /**
- * Get the directory where
- * @return
- */
- public File getLdifDirectory()
- {
- return ldifDirectory;
- }
-
-
- public void setLdifDirectory( File ldifDirectory )
- {
- LOG.info( "The LDIF directory file is {}", ldifDirectory.getAbsolutePath() );
- this.ldifDirectory = ldifDirectory;
- }
-
-
- // ----------------------------------------------------------------------
- // From CoreContextFactory: presently in intermediate step but these
- // methods will be moved to the appropriate protocol service eventually.
- // This is here simply to start to remove the JNDI dependency then further
- // refactoring will be needed to place these where they belong.
- // ----------------------------------------------------------------------
-
-
- /**
- * Check that the entry where are stored the loaded Ldif files is created.
- *
- * If not, create it.
- *
- * The files are stored in ou=loadedLdifFiles,ou=configuration,ou=system
- */
- private void ensureLdifFileBase() throws Exception
- {
- LdapDN dn = new LdapDN( ServerDNConstants.LDIF_FILES_DN );
- ServerEntry entry = null;
-
- try
- {
- entry = directoryService.getAdminSession().lookup( dn );
- }
- catch( Exception e )
- {
- LOG.info( "Failure while looking up {}. The entry will be created now.", ServerDNConstants.LDIF_FILES_DN, e );
- }
-
- if ( entry == null )
- {
- entry = directoryService.newEntry( new LdapDN( ServerDNConstants.LDIF_FILES_DN ) );
- entry.add( SchemaConstants.OU_AT, "loadedLdifFiles" );
- entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-
- directoryService.getAdminSession().add( entry );
- }
- }
-
-
- /**
- * Create a string containing a hex dump of the loaded ldif file name.
- *
- * It is associated with the attributeType wrt to the underlying system.
- */
- private LdapDN buildProtectedFileEntryDn( File ldif ) throws Exception
- {
- String fileSep = File.separatorChar == '\\' ?
- ApacheSchemaConstants.WINDOWS_FILE_AT :
- ApacheSchemaConstants.UNIX_FILE_AT;
-
- return new LdapDN( fileSep +
- "=" +
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.configuration;
+
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
+import org.apache.directory.server.protocol.shared.store.LdifLoadFilter;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Apache Directory Server top level.
+ *
+ * @org.apache.xbean.XBean
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ApacheDS
+{
+ private static final Logger LOG = LoggerFactory.getLogger( ApacheDS.class.getName() );
+
+ /** Default delay between two flushes to the backend */
+ private static final long DEFAULT_SYNC_PERIOD_MILLIS = 20000;
+
+ /** Wainting period between two flushes to the backend */
+ private long synchPeriodMillis = DEFAULT_SYNC_PERIOD_MILLIS;
+
+ /** Directory where are stored the LDIF files to be loaded at startup */
+ private File ldifDirectory;
+
+ private final List<LdifLoadFilter> ldifFilters = new ArrayList<LdifLoadFilter>();
+
+ /** The LDAP server protocol handler */
+ private final LdapServer ldapServer;
+
+ /** The directory service */
+ private DirectoryService directoryService;
+
+
+ /**
+ * Creates a new instance of the ApacheDS server
+ *
+ * @param directoryService
+ * @param ldapServer
+ */
+ public ApacheDS( LdapServer ldapServer )
+ {
+ LOG.info( "Starting the Apache Directory Server" );
+
+ this.ldapServer = ldapServer;
+
+ directoryService = ldapServer.getDirectoryService();
+
+ if ( directoryService == null )
+ {
+ directoryService = new DefaultDirectoryService();
+ }
+ }
+
+
+ /**
+ * Start the server :
+ * <li>initialize the DirectoryService</li>
+ * <li>start the LDAP server</li>
+ * <li>start the LDAPS server</li>
+ *
+ * @throws NamingException If the server cannot be started
+ * @throws IOException If an IO error occured while reading some file
+ */
+ public void startup() throws Exception
+ {
+ LOG.debug( "Starting the server" );
+
+ // Start the directory service if not started yet
+ if ( ! directoryService.isStarted() )
+ {
+ LOG.debug( "1. Starting the DirectoryService" );
+ directoryService.startup();
+ }
+
+ // Load the LDIF files - if any - into the server
+ loadLdifs();
+
+ // Start the LDAP server
+ if ( ldapServer != null && ! ldapServer.isStarted() )
+ {
+ LOG.debug( "3. Starting the LDAP server" );
+ ldapServer.start();
+ }
+
+ LOG.debug( "Server successfully started" );
+ }
+
+
+ public boolean isStarted()
+ {
+ if ( ldapServer != null )
+ {
+ return ( ldapServer.isStarted() );
+ }
+
+ return directoryService.isStarted();
+ }
+
+
+ public void shutdown() throws Exception
+ {
+ if ( ldapServer != null && ldapServer.isStarted() )
+ {
+ ldapServer.stop();
+ }
+
+ directoryService.shutdown();
+ }
+
+
+ public LdapServer getLdapServer()
+ {
+ return ldapServer;
+ }
+
+
+ public DirectoryService getDirectoryService()
+ {
+ return directoryService;
+ }
+
+
+ public long getSynchPeriodMillis()
+ {
+ return synchPeriodMillis;
+ }
+
+
+ public void setSynchPeriodMillis( long synchPeriodMillis )
+ {
+ LOG.info( "Set the synchPeriodMillis to {}", synchPeriodMillis );
+ this.synchPeriodMillis = synchPeriodMillis;
+ }
+
+
+ /**
+ * Get the directory where
+ * @return
+ */
+ public File getLdifDirectory()
+ {
+ return ldifDirectory;
+ }
+
+
+ public void setLdifDirectory( File ldifDirectory )
+ {
+ LOG.info( "The LDIF directory file is {}", ldifDirectory.getAbsolutePath() );
+ this.ldifDirectory = ldifDirectory;
+ }
+
+
+ // ----------------------------------------------------------------------
+ // From CoreContextFactory: presently in intermediate step but these
+ // methods will be moved to the appropriate protocol service eventually.
+ // This is here simply to start to remove the JNDI dependency then further
+ // refactoring will be needed to place these where they belong.
+ // ----------------------------------------------------------------------
+
+
+ /**
+ * Check that the entry where are stored the loaded Ldif files is created.
+ *
+ * If not, create it.
+ *
+ * The files are stored in ou=loadedLdifFiles,ou=configuration,ou=system
+ */
+ private void ensureLdifFileBase() throws Exception
+ {
+ LdapDN dn = new LdapDN( ServerDNConstants.LDIF_FILES_DN );
+ ServerEntry entry = null;
+
+ try
+ {
+ entry = directoryService.getAdminSession().lookup( dn );
+ }
+ catch( Exception e )
+ {
+ LOG.info( "Failure while looking up {}. The entry will be created now.", ServerDNConstants.LDIF_FILES_DN, e );
+ }
+
+ if ( entry == null )
+ {
+ entry = directoryService.newEntry( new LdapDN( ServerDNConstants.LDIF_FILES_DN ) );
+ entry.add( SchemaConstants.OU_AT, "loadedLdifFiles" );
+ entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+
+ directoryService.getAdminSession().add( entry );
+ }
+ }
+
+
+ /**
+ * Create a string containing a hex dump of the loaded ldif file name.
+ *
+ * It is associated with the attributeType wrt to the underlying system.
+ */
+ private LdapDN buildProtectedFileEntryDn( File ldif ) throws Exception
+ {
+ String fileSep = File.separatorChar == '\\' ?
+ ApacheSchemaConstants.WINDOWS_FILE_AT :
+ ApacheSchemaConstants.UNIX_FILE_AT;
+
+ return new LdapDN( fileSep +
+ "=" +
StringTools.dumpHexPairs( StringTools.getBytesUtf8( getCanonical( ldif ) ) ) +
- "," +
- ServerDNConstants.LDIF_FILES_DN );
- }
-
-
- private void addFileEntry( File ldif ) throws Exception
- {
- String rdnAttr = File.separatorChar == '\\' ?
- ApacheSchemaConstants.WINDOWS_FILE_AT :
- ApacheSchemaConstants.UNIX_FILE_AT;
- String oc = File.separatorChar == '\\' ? ApacheSchemaConstants.WINDOWS_FILE_OC : ApacheSchemaConstants.UNIX_FILE_OC;
-
- ServerEntry entry = directoryService.newEntry( buildProtectedFileEntryDn( ldif ) );
- entry.add( rdnAttr, getCanonical( ldif ) );
- entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, oc );
- directoryService.getAdminSession().add( entry );
- }
-
-
- private String getCanonical( File file )
- {
- String canonical;
-
- try
- {
- canonical = file.getCanonicalPath();
- }
- catch ( IOException e )
- {
- LOG.error( "could not get canonical path", e );
- return null;
- }
-
- return StringUtils.replace( canonical, "\\", "\\\\" );
- }
-
-
- /**
- * Load a ldif into the directory.
- *
- * @param root The context in which we will inject the entries
- * @param ldifFile The ldif file to read
- * @throws NamingException If something went wrong while loading the entries
- */
- private void loadLdif( File ldifFile ) throws Exception
- {
- ClonedServerEntry fileEntry = null;
- try
- {
- fileEntry = directoryService.getAdminSession().lookup( buildProtectedFileEntryDn( ldifFile ) );
- }
- catch( Exception e )
- {
- // if does not exist
- }
-
- if ( fileEntry != null )
- {
- String time = ((ClonedServerEntry)fileEntry).getOriginalEntry().get( SchemaConstants.CREATE_TIMESTAMP_AT ).getString();
- LOG.info( "Load of LDIF file '" + getCanonical( ldifFile )
- + "' skipped. It has already been loaded on " + time + "." );
- }
- else
- {
- LdifFileLoader loader = new LdifFileLoader( directoryService.getAdminSession(), ldifFile, ldifFilters );
- int count = loader.execute();
- LOG.info( "Loaded " + count + " entries from LDIF file '" + getCanonical( ldifFile ) + "'" );
- addFileEntry( ldifFile );
- }
- }
-
-
- /**
- * Load the ldif files if there are some
- */
- public void loadLdifs() throws Exception
- {
- // LOG and bail if property not set
- if ( ldifDirectory == null )
- {
- LOG.info( "LDIF load directory not specified. No LDIF files will be loaded." );
- return;
- }
-
- // LOG and bail if LDIF directory does not exists
- if ( ! ldifDirectory.exists() )
- {
- LOG.warn( "LDIF load directory '{}' does not exist. No LDIF files will be loaded.",
- getCanonical( ldifDirectory ) );
- return;
- }
-
-
- LdapDN dn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN );
-
- // Must normalize the dn or - IllegalStateException!
- AttributeTypeRegistry reg = directoryService.getRegistries().getAttributeTypeRegistry();
- dn.normalize( reg.getNormalizerMapping() );
-
- ensureLdifFileBase();
-
- // if ldif directory is a file try to load it
- if ( ldifDirectory.isFile() )
- {
- if ( LOG.isInfoEnabled() )
- {
- LOG.info( "LDIF load directory '{}' is a file. Will attempt to load as LDIF.",
- getCanonical( ldifDirectory ) );
- }
-
- try
- {
- loadLdif( ldifDirectory );
- }
- catch ( Exception ne )
- {
- // If the file can't be read, log the error, and stop
- // loading LDIFs.
- LOG.error( "Cannot load the ldif file '{}', error : ",
- ldifDirectory.getAbsolutePath(),
- ne.getMessage() );
- throw ne;
- }
- }
- else
- {
- // get all the ldif files within the directory (should be sorted alphabetically)
- File[] ldifFiles = ldifDirectory.listFiles( new FileFilter()
- {
- public boolean accept( File pathname )
- {
- boolean isLdif = pathname.getName().toLowerCase().endsWith( ".ldif" );
- return pathname.isFile() && pathname.canRead() && isLdif;
- }
- } );
-
- // LOG and bail if we could not find any LDIF files
- if ( ( ldifFiles == null ) || ( ldifFiles.length == 0 ) )
- {
- LOG.warn( "LDIF load directory '{}' does not contain any LDIF files. No LDIF files will be loaded.",
- getCanonical( ldifDirectory ) );
- return;
- }
-
- // load all the ldif files and load each one that is loaded
- for ( File ldifFile : ldifFiles )
- {
- try
- {
- LOG.info( "Loading LDIF file '{}'", ldifFile.getName() );
- loadLdif( ldifFile );
- }
- catch ( Exception ne )
- {
- // If the file can't be read, log the error, and stop
- // loading LDIFs.
- LOG.error( "Cannot load the ldif file '{}', error : {}",
- ldifFile.getAbsolutePath(),
- ne.getMessage() );
- throw ne;
- }
- }
- }
- }
-}
+ "," +
+ ServerDNConstants.LDIF_FILES_DN );
+ }
+
+
+ private void addFileEntry( File ldif ) throws Exception
+ {
+ String rdnAttr = File.separatorChar == '\\' ?
+ ApacheSchemaConstants.WINDOWS_FILE_AT :
+ ApacheSchemaConstants.UNIX_FILE_AT;
+ String oc = File.separatorChar == '\\' ? ApacheSchemaConstants.WINDOWS_FILE_OC : ApacheSchemaConstants.UNIX_FILE_OC;
+
+ ServerEntry entry = directoryService.newEntry( buildProtectedFileEntryDn( ldif ) );
+ entry.add( rdnAttr, getCanonical( ldif ) );
+ entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, oc );
+ directoryService.getAdminSession().add( entry );
+ }
+
+
+ private String getCanonical( File file )
+ {
+ String canonical;
+
+ try
+ {
+ canonical = file.getCanonicalPath();
+ }
+ catch ( IOException e )
+ {
+ LOG.error( "could not get canonical path", e );
+ return null;
+ }
+
+ return StringUtils.replace( canonical, "\\", "\\\\" );
+ }
+
+
+ /**
+ * Load a ldif into the directory.
+ *
+ * @param root The context in which we will inject the entries
+ * @param ldifFile The ldif file to read
+ * @throws NamingException If something went wrong while loading the entries
+ */
+ private void loadLdif( File ldifFile ) throws Exception
+ {
+ ClonedServerEntry fileEntry = null;
+ try
+ {
+ fileEntry = directoryService.getAdminSession().lookup( buildProtectedFileEntryDn( ldifFile ) );
+ }
+ catch( Exception e )
+ {
+ // if does not exist
+ }
+
+ if ( fileEntry != null )
+ {
+ String time = ((ClonedServerEntry)fileEntry).getOriginalEntry().get( SchemaConstants.CREATE_TIMESTAMP_AT ).getString();
+ LOG.info( "Load of LDIF file '" + getCanonical( ldifFile )
+ + "' skipped. It has already been loaded on " + time + "." );
+ }
+ else
+ {
+ LdifFileLoader loader = new LdifFileLoader( directoryService.getAdminSession(), ldifFile, ldifFilters );
+ int count = loader.execute();
+ LOG.info( "Loaded " + count + " entries from LDIF file '" + getCanonical( ldifFile ) + "'" );
+ addFileEntry( ldifFile );
+ }
+ }
+
+
+ /**
+ * Load the ldif files if there are some
+ */
+ public void loadLdifs() throws Exception
+ {
+ // LOG and bail if property not set
+ if ( ldifDirectory == null )
+ {
+ LOG.info( "LDIF load directory not specified. No LDIF files will be loaded." );
+ return;
+ }
+
+ // LOG and bail if LDIF directory does not exists
+ if ( ! ldifDirectory.exists() )
+ {
+ LOG.warn( "LDIF load directory '{}' does not exist. No LDIF files will be loaded.",
+ getCanonical( ldifDirectory ) );
+ return;
+ }
+
+
+ LdapDN dn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN );
+
+ // Must normalize the dn or - IllegalStateException!
+ AttributeTypeRegistry reg = directoryService.getRegistries().getAttributeTypeRegistry();
+ dn.normalize( reg.getNormalizerMapping() );
+
+ ensureLdifFileBase();
+
+ // if ldif directory is a file try to load it
+ if ( ldifDirectory.isFile() )
+ {
+ if ( LOG.isInfoEnabled() )
+ {
+ LOG.info( "LDIF load directory '{}' is a file. Will attempt to load as LDIF.",
+ getCanonical( ldifDirectory ) );
+ }
+
+ try
+ {
+ loadLdif( ldifDirectory );
+ }
+ catch ( Exception ne )
+ {
+ // If the file can't be read, log the error, and stop
+ // loading LDIFs.
+ LOG.error( "Cannot load the ldif file '{}', error : ",
+ ldifDirectory.getAbsolutePath(),
+ ne.getMessage() );
+ throw ne;
+ }
+ }
+ else
+ {
+ // get all the ldif files within the directory (should be sorted alphabetically)
+ File[] ldifFiles = ldifDirectory.listFiles( new FileFilter()
+ {
+ public boolean accept( File pathname )
+ {
+ boolean isLdif = pathname.getName().toLowerCase().endsWith( ".ldif" );
+ return pathname.isFile() && pathname.canRead() && isLdif;
+ }
+ } );
+
+ // LOG and bail if we could not find any LDIF files
+ if ( ( ldifFiles == null ) || ( ldifFiles.length == 0 ) )
+ {
+ LOG.warn( "LDIF load directory '{}' does not contain any LDIF files. No LDIF files will be loaded.",
+ getCanonical( ldifDirectory ) );
+ return;
+ }
+
+ // load all the ldif files and load each one that is loaded
+ for ( File ldifFile : ldifFiles )
+ {
+ try
+ {
+ LOG.info( "Loading LDIF file '{}'", ldifFile.getName() );
+ loadLdif( ldifFile );
+ }
+ catch ( Exception ne )
+ {
+ // If the file can't be read, log the error, and stop
+ // loading LDIFs.
+ LOG.error( "Cannot load the ldif file '{}', error : {}",
+ ldifFile.getAbsolutePath(),
+ ne.getMessage() );
+ throw ne;
+ }
+ }
+ }
+ }
+}
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java?rev=801337&r1=801336&r2=801337&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/DefaultTupleComparator.java Wed Aug 5 17:52:12 2009
@@ -1,67 +1,67 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.core.partition.impl.btree;
-
-
-import org.apache.directory.server.schema.SerializableComparator;
-
-
-/**
- * The default implementation of a pair of comparators which compares both
- * keys and values of a Tuple.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class DefaultTupleComparator<K,V> implements TupleComparator<K,V>
-{
- SerializableComparator<K> keyComparator;
- SerializableComparator<V> valueComparator;
-
-
- public DefaultTupleComparator( SerializableComparator<K> keyComparator, SerializableComparator<V> valueComparator )
- {
- this.keyComparator = keyComparator;
- this.valueComparator = valueComparator;
- }
-
-
- public SerializableComparator<K> getKeyComparator()
- {
- return keyComparator;
- }
-
-
- public SerializableComparator<V> getValueComparator()
- {
- return valueComparator;
- }
-
-
- public int compareKey( K key1, K key2 )
- {
- return keyComparator.compare( key1, key2 );
- }
-
-
- public int compareValue( V value1, V value2 )
- {
- return valueComparator.compare( value1, value2 );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.partition.impl.btree;
+
+
+import org.apache.directory.server.schema.SerializableComparator;
+
+
+/**
+ * The default implementation of a pair of comparators which compares both
+ * keys and values of a Tuple.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DefaultTupleComparator<K,V> implements TupleComparator<K,V>
+{
+ SerializableComparator<K> keyComparator;
+ SerializableComparator<V> valueComparator;
+
+
+ public DefaultTupleComparator( SerializableComparator<K> keyComparator, SerializableComparator<V> valueComparator )
+ {
+ this.keyComparator = keyComparator;
+ this.valueComparator = valueComparator;
+ }
+
+
+ public SerializableComparator<K> getKeyComparator()
+ {
+ return keyComparator;
+ }
+
+
+ public SerializableComparator<V> getValueComparator()
+ {
+ return valueComparator;
+ }
+
+
+ public int compareKey( K key1, K key2 )
+ {
+ return keyComparator.compare( key1, key2 );
+ }
+
+
+ public int compareValue( V value1, V value2 )
+ {
+ return valueComparator.compare( value1, value2 );
+ }
+}
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java?rev=801337&r1=801336&r2=801337&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/LongComparator.java Wed Aug 5 17:52:12 2009
@@ -1,47 +1,47 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.core.partition.impl.btree;
-
-
-import org.apache.directory.server.schema.SerializableComparator;
-
-
-/**
- * A serializable comparator for long values.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class LongComparator extends SerializableComparator<Long>
-{
- public static final LongComparator INSTANCE = new LongComparator();
- private static final long serialVersionUID = 3690478030414165816L;
-
-
- public LongComparator()
- {
- super( "1.3.6.1.4.1.18060.0.4.1.1.2" );
- }
-
-
- public int compare( Long l1, Long l2 )
- {
- return ( l1 < l2 ? -1 : ( l1.equals( l2 ) ? 0 : 1 ) );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.partition.impl.btree;
+
+
+import org.apache.directory.server.schema.SerializableComparator;
+
+
+/**
+ * A serializable comparator for long values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LongComparator extends SerializableComparator<Long>
+{
+ public static final LongComparator INSTANCE = new LongComparator();
+ private static final long serialVersionUID = 3690478030414165816L;
+
+
+ public LongComparator()
+ {
+ super( "1.3.6.1.4.1.18060.0.4.1.1.2" );
+ }
+
+
+ public int compare( Long l1, Long l2 )
+ {
+ return ( l1 < l2 ? -1 : ( l1.equals( l2 ) ? 0 : 1 ) );
+ }
+}
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java?rev=801337&r1=801336&r2=801337&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java Wed Aug 5 17:52:12 2009
@@ -1,209 +1,209 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.core.partition.impl.btree;
-
-
-import org.apache.directory.server.xdbm.Tuple;
-import org.apache.directory.shared.ldap.NotImplementedException;
-import org.apache.directory.shared.ldap.cursor.AbstractCursor;
-import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
-
-import java.util.Arrays;
-import java.util.List;
-
-
-/**
- * A Cursor which returns the values of a single key as Tuples.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class ValueArrayCursor<K,V> extends AbstractCursor<Tuple>
-{
- private static final int BEFORE_FIRST = -1;
-
- private final K key;
- private final List<V> values;
- private final Tuple<K,V> tuple = new Tuple<K,V>();
-
- private int pos = BEFORE_FIRST;
-
-
- public ValueArrayCursor( final K key, final V[] values )
- {
- this.key = key;
- this.tuple.setKey( key );
- this.values = Arrays.asList( values );
- }
-
-
- public ValueArrayCursor( final K key, final List<V> values )
- {
- this.key = key;
- this.tuple.setKey( key );
- this.values = values;
- }
-
-
- public boolean available()
- {
- return inRangeOnValue();
- }
-
-
- public void before( Tuple element ) throws Exception
- {
- throw new NotImplementedException();
- }
-
-
- public void after( Tuple element ) throws Exception
- {
- throw new NotImplementedException();
- }
-
-
- public void beforeFirst() throws Exception
- {
- checkNotClosed( "beforeFirst()" );
- pos = BEFORE_FIRST;
- }
-
-
- public void afterLast() throws Exception
- {
- checkNotClosed( "afterLast()" );
- pos = values.size();
- }
-
-
- public boolean absolute( int absolutePosition ) throws Exception
- {
- checkNotClosed( "absolute()" );
- if ( absolutePosition >= values.size() )
- {
- pos = values.size();
- return false;
- }
-
- if ( absolutePosition < 0 )
- {
- pos = BEFORE_FIRST;
- return false;
- }
-
- pos = absolutePosition;
- return true;
- }
-
-
- public boolean first() throws Exception
- {
- checkNotClosed( "first()" );
- pos = 0;
- return true;
- }
-
-
- public boolean last() throws Exception
- {
- checkNotClosed( "last()" );
- pos = values.size() - 1;
- return true;
- }
-
-
- public boolean isFirst() throws Exception
- {
- checkNotClosed( "isFirst()" );
- return pos == 0;
- }
-
-
- public boolean isLast() throws Exception
- {
- checkNotClosed( "isLast()" );
- return pos == values.size() - 1;
- }
-
-
- public boolean isAfterLast() throws Exception
- {
- checkNotClosed( "isAfterLast()" );
- return pos == values.size();
- }
-
-
- public boolean isBeforeFirst() throws Exception
- {
- checkNotClosed( "isBeforeFirst()" );
- return pos == BEFORE_FIRST;
- }
-
-
- public boolean previous() throws Exception
- {
- checkNotClosed( "previous()" );
- if ( pos <= BEFORE_FIRST )
- {
- return false;
- }
-
- pos--;
- return inRangeOnValue();
- }
-
-
- private boolean inRangeOnValue()
- {
- return pos > BEFORE_FIRST && pos < values.size();
- }
-
-
- public boolean next() throws Exception
- {
- checkNotClosed( "next()" );
- if ( pos >= values.size() )
- {
- return false;
- }
-
- pos++;
- return inRangeOnValue();
- }
-
-
- public Tuple get() throws Exception
- {
- checkNotClosed( "get()" );
- if ( inRangeOnValue() )
- {
- return tuple.setBoth( key, values.get( pos ) );
- }
-
- throw new InvalidCursorPositionException( "Cursor pos (" + pos
- + ") not in value range [0-" + ( values.size() - 1 )+ "]" );
- }
-
-
- public boolean isElementReused()
- {
- return true;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.partition.impl.btree;
+
+
+import org.apache.directory.server.xdbm.Tuple;
+import org.apache.directory.shared.ldap.NotImplementedException;
+import org.apache.directory.shared.ldap.cursor.AbstractCursor;
+import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
+
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * A Cursor which returns the values of a single key as Tuples.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ValueArrayCursor<K,V> extends AbstractCursor<Tuple>
+{
+ private static final int BEFORE_FIRST = -1;
+
+ private final K key;
+ private final List<V> values;
+ private final Tuple<K,V> tuple = new Tuple<K,V>();
+
+ private int pos = BEFORE_FIRST;
+
+
+ public ValueArrayCursor( final K key, final V[] values )
+ {
+ this.key = key;
+ this.tuple.setKey( key );
+ this.values = Arrays.asList( values );
+ }
+
+
+ public ValueArrayCursor( final K key, final List<V> values )
+ {
+ this.key = key;
+ this.tuple.setKey( key );
+ this.values = values;
+ }
+
+
+ public boolean available()
+ {
+ return inRangeOnValue();
+ }
+
+
+ public void before( Tuple element ) throws Exception
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public void after( Tuple element ) throws Exception
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public void beforeFirst() throws Exception
+ {
+ checkNotClosed( "beforeFirst()" );
+ pos = BEFORE_FIRST;
+ }
+
+
+ public void afterLast() throws Exception
+ {
+ checkNotClosed( "afterLast()" );
+ pos = values.size();
+ }
+
+
+ public boolean absolute( int absolutePosition ) throws Exception
+ {
+ checkNotClosed( "absolute()" );
+ if ( absolutePosition >= values.size() )
+ {
+ pos = values.size();
+ return false;
+ }
+
+ if ( absolutePosition < 0 )
+ {
+ pos = BEFORE_FIRST;
+ return false;
+ }
+
+ pos = absolutePosition;
+ return true;
+ }
+
+
+ public boolean first() throws Exception
+ {
+ checkNotClosed( "first()" );
+ pos = 0;
+ return true;
+ }
+
+
+ public boolean last() throws Exception
+ {
+ checkNotClosed( "last()" );
+ pos = values.size() - 1;
+ return true;
+ }
+
+
+ public boolean isFirst() throws Exception
+ {
+ checkNotClosed( "isFirst()" );
+ return pos == 0;
+ }
+
+
+ public boolean isLast() throws Exception
+ {
+ checkNotClosed( "isLast()" );
+ return pos == values.size() - 1;
+ }
+
+
+ public boolean isAfterLast() throws Exception
+ {
+ checkNotClosed( "isAfterLast()" );
+ return pos == values.size();
+ }
+
+
+ public boolean isBeforeFirst() throws Exception
+ {
+ checkNotClosed( "isBeforeFirst()" );
+ return pos == BEFORE_FIRST;
+ }
+
+
+ public boolean previous() throws Exception
+ {
+ checkNotClosed( "previous()" );
+ if ( pos <= BEFORE_FIRST )
+ {
+ return false;
+ }
+
+ pos--;
+ return inRangeOnValue();
+ }
+
+
+ private boolean inRangeOnValue()
+ {
+ return pos > BEFORE_FIRST && pos < values.size();
+ }
+
+
+ public boolean next() throws Exception
+ {
+ checkNotClosed( "next()" );
+ if ( pos >= values.size() )
+ {
+ return false;
+ }
+
+ pos++;
+ return inRangeOnValue();
+ }
+
+
+ public Tuple get() throws Exception
+ {
+ checkNotClosed( "get()" );
+ if ( inRangeOnValue() )
+ {
+ return tuple.setBoth( key, values.get( pos ) );
+ }
+
+ throw new InvalidCursorPositionException( "Cursor pos (" + pos
+ + ") not in value range [0-" + ( values.size() - 1 )+ "]" );
+ }
+
+
+ public boolean isElementReused()
+ {
+ return true;
+ }
+}
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java?rev=801337&r1=801336&r2=801337&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java Wed Aug 5 17:52:12 2009
@@ -1,111 +1,111 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.xdbm;
-
-import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
-
-
-
-/**
- * An empty Cursor implementation.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class EmptyIndexCursor<K,E> extends AbstractIndexCursor<K,E>
-{
- public boolean available()
- {
- return false;
- }
-
- public void before( IndexEntry<K,E> element ) throws Exception
- {
- checkNotClosed( "before()" );
- }
-
-
- public void after( IndexEntry<K,E> element ) throws Exception
- {
- checkNotClosed( "after()" );
- }
-
-
- public void beforeFirst() throws Exception
- {
- checkNotClosed( "beforeFirst()" );
- }
-
-
- public void afterLast() throws Exception
- {
- checkNotClosed( "afterLast()" );
- }
-
-
- public boolean first() throws Exception
- {
- checkNotClosed( "first()" );
- return false;
- }
-
-
- public boolean last() throws Exception
- {
- checkNotClosed( "last()" );
- return false;
- }
-
-
- public boolean previous() throws Exception
- {
- checkNotClosed( "previous()" );
- return false;
- }
-
-
- public boolean next() throws Exception
- {
- checkNotClosed( "next()" );
- return false;
- }
-
-
- public IndexEntry<K,E> get() throws Exception
- {
- checkNotClosed( "get()" );
- throw new InvalidCursorPositionException( "This cursor is empty and cannot return elements!" );
- }
-
-
- public boolean isElementReused()
- {
- return false;
- }
-
- public void afterValue( Long id, K indexValue ) throws Exception
- {
- checkNotClosed( "after()" );
- }
-
- public void beforeValue( Long id, K indexValue ) throws Exception
- {
- checkNotClosed( "after()" );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.xdbm;
+
+import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
+
+
+
+/**
+ * An empty Cursor implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EmptyIndexCursor<K,E> extends AbstractIndexCursor<K,E>
+{
+ public boolean available()
+ {
+ return false;
+ }
+
+ public void before( IndexEntry<K,E> element ) throws Exception
+ {
+ checkNotClosed( "before()" );
+ }
+
+
+ public void after( IndexEntry<K,E> element ) throws Exception
+ {
+ checkNotClosed( "after()" );
+ }
+
+
+ public void beforeFirst() throws Exception
+ {
+ checkNotClosed( "beforeFirst()" );
+ }
+
+
+ public void afterLast() throws Exception
+ {
+ checkNotClosed( "afterLast()" );
+ }
+
+
+ public boolean first() throws Exception
+ {
+ checkNotClosed( "first()" );
+ return false;
+ }
+
+
+ public boolean last() throws Exception
+ {
+ checkNotClosed( "last()" );
+ return false;
+ }
+
+
+ public boolean previous() throws Exception
+ {
+ checkNotClosed( "previous()" );
+ return false;
+ }
+
+
+ public boolean next() throws Exception
+ {
+ checkNotClosed( "next()" );
+ return false;
+ }
+
+
+ public IndexEntry<K,E> get() throws Exception
+ {
+ checkNotClosed( "get()" );
+ throw new InvalidCursorPositionException( "This cursor is empty and cannot return elements!" );
+ }
+
+
+ public boolean isElementReused()
+ {
+ return false;
+ }
+
+ public void afterValue( Long id, K indexValue ) throws Exception
+ {
+ checkNotClosed( "after()" );
+ }
+
+ public void beforeValue( Long id, K indexValue ) throws Exception
+ {
+ checkNotClosed( "after()" );
+ }
+}
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java?rev=801337&r1=801336&r2=801337&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java Wed Aug 5 17:52:12 2009
@@ -1,213 +1,213 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.xdbm;
-
-import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
-
-
-
-
-/**
- * A Cursor over a single element.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class SingletonIndexCursor<K, E> extends AbstractIndexCursor<K, E>
-{
- private boolean beforeFirst = true;
- private boolean afterLast;
- private boolean onSingleton;
- private final IndexEntry<K,E> singleton;
-
-
- public SingletonIndexCursor( IndexEntry<K,E> singleton )
- {
- this.singleton = singleton;
- }
-
-
- public boolean available()
- {
- return onSingleton;
- }
-
-
- public void before( IndexEntry<K,E> element ) throws Exception
- {
- throw new UnsupportedOperationException();
- }
-
-
- public void beforeValue( Long id, K value ) throws Exception
- {
- throw new UnsupportedOperationException();
- }
-
-
- public void afterValue( Long id, K value ) throws Exception
- {
- throw new UnsupportedOperationException();
- }
-
-
- public void after( IndexEntry<K,E> element ) throws Exception
- {
- throw new UnsupportedOperationException();
- }
-
-
- public void beforeFirst() throws Exception
- {
- checkNotClosed( "()" );
- beforeFirst = true;
- afterLast = false;
- onSingleton = false;
- }
-
-
- public void afterLast() throws Exception
- {
- checkNotClosed( "()" );
- beforeFirst = false;
- afterLast = true;
- onSingleton = false;
- }
-
-
- public boolean first() throws Exception
- {
- checkNotClosed( "()" );
- beforeFirst = false;
- onSingleton = true;
- afterLast = false;
- return true;
- }
-
-
- public boolean last() throws Exception
- {
- checkNotClosed( "()" );
- beforeFirst = false;
- onSingleton = true;
- afterLast = false;
- return true;
- }
-
-
- public boolean isFirst() throws Exception
- {
- checkNotClosed( "()" );
- return onSingleton;
- }
-
-
- public boolean isLast() throws Exception
- {
- checkNotClosed( "()" );
- return onSingleton;
- }
-
-
- public boolean isAfterLast() throws Exception
- {
- checkNotClosed( "()" );
- return afterLast;
- }
-
-
- public boolean isBeforeFirst() throws Exception
- {
- checkNotClosed( "()" );
- return beforeFirst;
- }
-
-
- public boolean previous() throws Exception
- {
- checkNotClosed( "()" );
- if ( beforeFirst )
- {
- return false;
- }
-
- if ( afterLast )
- {
- beforeFirst = false;
- onSingleton = true;
- afterLast = false;
- return true;
- }
-
- // must be on the singleton
- beforeFirst = true;
- onSingleton = false;
- afterLast = false;
- return false;
- }
-
-
- public boolean next() throws Exception
- {
- checkNotClosed( "()" );
- if ( beforeFirst )
- {
- beforeFirst = false;
- onSingleton = true;
- afterLast = false;
- return true;
- }
-
- if ( afterLast )
- {
- return false;
- }
-
- // must be on the singleton
- beforeFirst = false;
- onSingleton = false;
- afterLast = true;
- return false;
- }
-
-
- public IndexEntry<K,E> get() throws Exception
- {
- checkNotClosed( "()" );
- if ( onSingleton )
- {
- return singleton;
- }
-
- if ( beforeFirst )
- {
- throw new InvalidCursorPositionException( "Cannot access element if positioned before first." );
- }
- else
- {
- throw new InvalidCursorPositionException( "Cannot access element if positioned after last." );
- }
- }
-
-
- public boolean isElementReused()
- {
- return true;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.xdbm;
+
+import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
+
+
+
+
+/**
+ * A Cursor over a single element.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SingletonIndexCursor<K, E> extends AbstractIndexCursor<K, E>
+{
+ private boolean beforeFirst = true;
+ private boolean afterLast;
+ private boolean onSingleton;
+ private final IndexEntry<K,E> singleton;
+
+
+ public SingletonIndexCursor( IndexEntry<K,E> singleton )
+ {
+ this.singleton = singleton;
+ }
+
+
+ public boolean available()
+ {
+ return onSingleton;
+ }
+
+
+ public void before( IndexEntry<K,E> element ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void beforeValue( Long id, K value ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void afterValue( Long id, K value ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void after( IndexEntry<K,E> element ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public void beforeFirst() throws Exception
+ {
+ checkNotClosed( "()" );
+ beforeFirst = true;
+ afterLast = false;
+ onSingleton = false;
+ }
+
+
+ public void afterLast() throws Exception
+ {
+ checkNotClosed( "()" );
+ beforeFirst = false;
+ afterLast = true;
+ onSingleton = false;
+ }
+
+
+ public boolean first() throws Exception
+ {
+ checkNotClosed( "()" );
+ beforeFirst = false;
+ onSingleton = true;
+ afterLast = false;
+ return true;
+ }
+
+
+ public boolean last() throws Exception
+ {
+ checkNotClosed( "()" );
+ beforeFirst = false;
+ onSingleton = true;
+ afterLast = false;
+ return true;
+ }
+
+
+ public boolean isFirst() throws Exception
+ {
+ checkNotClosed( "()" );
+ return onSingleton;
+ }
+
+
+ public boolean isLast() throws Exception
+ {
+ checkNotClosed( "()" );
+ return onSingleton;
+ }
+
+
+ public boolean isAfterLast() throws Exception
+ {
+ checkNotClosed( "()" );
+ return afterLast;
+ }
+
+
+ public boolean isBeforeFirst() throws Exception
+ {
+ checkNotClosed( "()" );
+ return beforeFirst;
+ }
+
+
+ public boolean previous() throws Exception
+ {
+ checkNotClosed( "()" );
+ if ( beforeFirst )
+ {
+ return false;
+ }
+
+ if ( afterLast )
+ {
+ beforeFirst = false;
+ onSingleton = true;
+ afterLast = false;
+ return true;
+ }
+
+ // must be on the singleton
+ beforeFirst = true;
+ onSingleton = false;
+ afterLast = false;
+ return false;
+ }
+
+
+ public boolean next() throws Exception
+ {
+ checkNotClosed( "()" );
+ if ( beforeFirst )
+ {
+ beforeFirst = false;
+ onSingleton = true;
+ afterLast = false;
+ return true;
+ }
+
+ if ( afterLast )
+ {
+ return false;
+ }
+
+ // must be on the singleton
+ beforeFirst = false;
+ onSingleton = false;
+ afterLast = true;
+ return false;
+ }
+
+
+ public IndexEntry<K,E> get() throws Exception
+ {
+ checkNotClosed( "()" );
+ if ( onSingleton )
+ {
+ return singleton;
+ }
+
+ if ( beforeFirst )
+ {
+ throw new InvalidCursorPositionException( "Cannot access element if positioned before first." );
+ }
+ else
+ {
+ throw new InvalidCursorPositionException( "Cannot access element if positioned after last." );
+ }
+ }
+
+
+ public boolean isElementReused()
+ {
+ return true;
+ }
+}