Author: pamarcelot Date: Wed Apr 2 04:06:56 2008 New Revision: 643846 URL: http://svn.apache.org/viewvc?rev=643846&view=rev Log: Applied code formatter. Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/CapacityTestCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DisconnectNotificationCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/GracefulShutdownCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java Wed Apr 2 04:06:56 2008 @@ -19,6 +19,7 @@ */ package org.apache.directory.server.tools; + import java.io.IOException; import java.net.URL; import java.util.Properties; @@ -40,7 +41,7 @@ public static void main( String[] args ) throws Exception { BaseCommand tools = getInstance(); - + if ( !BaseCommand.hasBannerOption( args ) ) { tools.printBanner(); @@ -116,7 +117,8 @@ } - public static BaseCommand getInstance() throws InstantiationException, IllegalAccessException, ClassNotFoundException + public static BaseCommand getInstance() throws InstantiationException, IllegalAccessException, + ClassNotFoundException { Properties props = new Properties(); try @@ -134,7 +136,7 @@ String productCommand = props.getProperty( "product.command", "apacheds-tools" ); String productBanner = props.getProperty( "product.banner", BaseCommand.BANNER ); String productClass = props.getProperty( "product.class", "org.apache.directory.server.tools.BaseCommand" ); - + BaseCommand baseCommand = ( BaseCommand ) Class.forName( productClass ).newInstance(); baseCommand.setProductBanner( productBanner ); baseCommand.setProductDisplayName( productDisplayName ); Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java Wed Apr 2 04:06:56 2008 @@ -19,6 +19,7 @@ */ package org.apache.directory.server.tools; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -37,6 +38,7 @@ import org.apache.commons.cli.PosixParser; import org.apache.commons.cli.UnrecognizedOptionException; + /** * The primary command base class. * @@ -61,11 +63,13 @@ private String productBanner; + public BaseCommand() { init(); } + protected void init() { ToolCommand command; @@ -114,6 +118,7 @@ getGlobal().addOption( op ); } + public static boolean hasBannerOption( String[] args ) { for ( int ii = 0; ii < args.length; ii++ ) @@ -126,6 +131,7 @@ return false; } + public CommandLine getCommandLine( String command, String[] args ) { Options all = allOptions( command ); @@ -135,30 +141,31 @@ { cmdline = parser.parse( all, args ); } - catch (AlreadySelectedException ase) + catch ( AlreadySelectedException ase ) { System.err.println( "Command line parsing failed for " + command + ". Reason: already selected " - + ase.getMessage() ); + + ase.getMessage() ); System.exit( 1 ); } - catch (MissingArgumentException mae) + catch ( MissingArgumentException mae ) { System.err.println( "Command line parsing failed for " + command + ". Reason: missing argument " - + mae.getMessage() ); + + mae.getMessage() ); System.exit( 1 ); } - catch (MissingOptionException moe) + catch ( MissingOptionException moe ) { - System.err.println( "Command line parsing failed for " + command + ". Reason: missing option " + moe.getMessage() ); + System.err.println( "Command line parsing failed for " + command + ". Reason: missing option " + + moe.getMessage() ); System.exit( 1 ); } - catch (UnrecognizedOptionException uoe) + catch ( UnrecognizedOptionException uoe ) { System.err.println( "Command line parsing failed for " + command + ". Reason: unrecognized option" - + uoe.getMessage() ); + + uoe.getMessage() ); System.exit( 1 ); } - catch (ParseException pe) + catch ( ParseException pe ) { System.err.println( "Command line parsing failed for " + command + ". Reason: " + pe.getClass() ); System.exit( 1 ); @@ -167,6 +174,7 @@ return cmdline; } + public Options allOptions( String command ) { if ( command.equals( "help" ) ) @@ -175,20 +183,21 @@ } Options all = new Options(); - ToolCommand cmd = (ToolCommand) getCommands().get( command ); + ToolCommand cmd = ( ToolCommand ) getCommands().get( command ); for ( Iterator ii = getGlobal().getOptions().iterator(); ii.hasNext(); ) { - all.addOption( (Option) ii.next() ); + all.addOption( ( Option ) ii.next() ); } for ( Iterator ii = cmd.getOptions().getOptions().iterator(); ii.hasNext(); ) { - all.addOption( (Option) ii.next() ); + all.addOption( ( Option ) ii.next() ); } return all; } + public static void dumpArgs( String msg, String[] args ) { if ( args.length == 0 ) @@ -208,6 +217,7 @@ System.out.println( buf ); } + public void helpOnCommand( String command ) { if ( command.equals( "help" ) ) @@ -218,7 +228,7 @@ if ( getCommands().containsKey( command ) ) { - ToolCommand cmd = (ToolCommand) getCommands().get( command ); + ToolCommand cmd = ( ToolCommand ) getCommands().get( command ); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( getProductCommand() + " " + cmd + " [options]", cmd.getOptions() ); } @@ -229,11 +239,12 @@ } } + public void printUsage() { HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp( getProductCommand() + " [options]", "\nGlobal options:", getGlobal(), "\nType \"" - + getProductCommand() + " help \" for help on a command." ); + formatter.printHelp( getProductCommand() + " [options]", "\nGlobal options:", getGlobal(), + "\nType \"" + getProductCommand() + " help \" for help on a command." ); System.out.println( "\nAvailable commands:" ); Iterator it = commandsOrdered.iterator(); @@ -249,81 +260,96 @@ } static final String BANNER = " _ _ ____ ____ _____ _ \n" - + " / \\ _ __ __ _ ___| |__ ___| _ \\/ ___| |_ _|__ ___ | |___ \n" - + " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\ | |/ _ \\ / _ \\| / __| \n" - + " / ___ \\| |_) | (_| | (__| | | | __/ |_| |___) | | | (_) | (_) | \\__ \\ \n" - + " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/ |_|\\___/ \\___/|_|___/ \n" - + " |_| \n"; + + " / \\ _ __ __ _ ___| |__ ___| _ \\/ ___| |_ _|__ ___ | |___ \n" + + " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\ | |/ _ \\ / _ \\| / __| \n" + + " / ___ \\| |_) | (_| | (__| | | | __/ |_| |___) | | | (_) | (_) | \\__ \\ \n" + + " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/ |_|\\___/ \\___/|_|___/ \n" + + " |_| \n"; + public void printBanner() { System.out.println( getProductBanner() ); } + public void setProductCommand( String productCommand ) { this.productCommand = productCommand; } + public String getProductCommand() { return productCommand; } + public void setProductVersion( String productVersion ) { this.productVersion = productVersion; } + public String getProductVersion() { return productVersion; } + public void setProductDisplayName( String productDisplayName ) { this.productDisplayName = productDisplayName; } + public String getProductDisplayName() { return productDisplayName; } + public void setProductUrl( String productUrl ) { this.productUrl = productUrl; } + public String getProductUrl() { return productUrl; } + public void setProductBanner( String productBanner ) { this.productBanner = productBanner; } + public String getProductBanner() { return productBanner; } + public void setCommands( Map commands ) { this.commands = commands; } + public Map getCommands() { return commands; } + public void setGlobal( Options global ) { this.global = global; } + public Options getGlobal() { Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/CapacityTestCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/CapacityTestCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/CapacityTestCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/CapacityTestCommand.java Wed Apr 2 04:06:56 2008 @@ -39,7 +39,6 @@ import org.apache.directory.shared.ldap.message.AttributesImpl; - /** * A capacity testing tool. This command will generate bogus user * entries and add them under a base DN. It will output a table @@ -58,8 +57,8 @@ private String host = "localhost"; private String password = "secret"; private String baseDn = "ou=users,dc=example,dc=com"; - - + + public CapacityTestCommand() { super( "capacity" ); @@ -81,7 +80,7 @@ { out = new PrintWriter( new FileWriter( outputFile ) ); } - + if ( isDebugEnabled() ) { out.println( "Parameters for capacity extended request:" ); @@ -101,7 +100,7 @@ // create the base dn if it does not exist createBase( ctx ); - + StringBuffer dnBuf = new StringBuffer(); StringBuffer outBuf = new StringBuffer(); int counter = 0; @@ -114,36 +113,36 @@ { end = Integer.parseInt( cmdline.getOptionValue( 'e' ) ); } - + while ( counter < end ) { counter++; Attributes attrs = generateLdif( counter ); dnBuf.setLength( 0 ); dnBuf.append( "uid=user." ).append( counter ).append( "," ).append( baseDn ); - + long startTime = System.currentTimeMillis(); ctx.createSubcontext( dnBuf.toString(), attrs ); - + outBuf.setLength( 0 ); outBuf.append( counter ).append( " " ).append( System.currentTimeMillis() - startTime ); out.println( outBuf.toString() ); out.flush(); } } - - + + private boolean createBase( LdapContext ctx ) throws NamingException { Attributes attrs = new AttributesImpl( "objectClass", "organizationalUnit", true ); attrs.put( "ou", "users" ); - + try { ctx.createSubcontext( "ou=users,dc=example,dc=com", attrs ); return true; } - catch( NameAlreadyBoundException e ) + catch ( NameAlreadyBoundException e ) { return false; } @@ -157,7 +156,7 @@ oc.add( "person" ); oc.add( "organizationalPerson" ); oc.add( "inetOrgPerson" ); - + attrs.put( "givenName", RandomStringUtils.randomAlphabetic( 6 ) ); attrs.put( "sn", RandomStringUtils.randomAlphabetic( 9 ) ); attrs.put( "cn", RandomStringUtils.randomAlphabetic( 15 ) ); @@ -177,7 +176,7 @@ attrs.put( "description", RandomStringUtils.randomAlphabetic( 20 ) ); return attrs; } - + private void processOptions( CommandLine cmd ) { @@ -292,7 +291,6 @@ op.setRequired( false ); opts.addOption( op ); - op = new Option( "s", "start", true, "start on id: number to start on (user.start)" ); op.setRequired( false ); opts.addOption( op ); Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DisconnectNotificationCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DisconnectNotificationCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DisconnectNotificationCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DisconnectNotificationCommand.java Wed Apr 2 04:06:56 2008 @@ -68,7 +68,7 @@ } - public void notificationReceived( UnsolicitedNotificationEvent evt ) + public void notificationReceived( UnsolicitedNotificationEvent evt ) { notification = evt.getNotification(); @@ -82,17 +82,17 @@ { System.out.println( "Recieved GracefulDisconnect: " + GracefulDisconnect.EXTENSION_OID ); GracefulDisconnect gd = null; - + try { gd = new GracefulDisconnect( notification.getEncodedValue() ); } - catch ( DecoderException de ) + catch ( DecoderException de ) { - // TODO Auto-generated catch block - de.printStackTrace(); - } - + // TODO Auto-generated catch block + de.printStackTrace(); + } + System.out.println( "LDAP server will shutdown in " + gd.getDelay() + " seconds." ); System.out.println( "LDAP server will be back online in " + gd.getTimeOffline() + " minutes." ); @@ -122,7 +122,7 @@ int delay; - Counter(int delay) + Counter( int delay ) { this.delay = delay; } Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/DumpCommand.java Wed Apr 2 04:06:56 2008 @@ -85,8 +85,8 @@ */ public class DumpCommand extends ToolCommand { - private Registries bootstrapRegistries = new DefaultRegistries( "bootstrap", - new BootstrapSchemaLoader(), new DefaultOidRegistry() ); + private Registries bootstrapRegistries = new DefaultRegistries( "bootstrap", new BootstrapSchemaLoader(), + new DefaultOidRegistry() ); private Set exclusions = new HashSet(); private boolean includeOperational = false; @@ -95,8 +95,8 @@ { super( "dump" ); } - - + + private Registries loadRegistries() throws Exception { // -------------------------------------------------------------------- @@ -107,7 +107,7 @@ BootstrapSchemaLoader loader = new BootstrapSchemaLoader(); OidRegistry oidRegistry = new DefaultOidRegistry(); final Registries registries = new DefaultRegistries( "bootstrap", loader, oidRegistry ); - + // load essential bootstrap schemas Set bootstrapSchemas = new HashSet(); bootstrapSchemas.add( new ApachemetaSchema() ); @@ -118,56 +118,55 @@ // run referential integrity tests List errors = registries.checkRefInteg(); - + if ( !errors.isEmpty() ) { NamingException e = new NamingException(); e.setRootCause( ( Throwable ) errors.get( 0 ) ); throw e; } - + SerializableComparator.setRegistry( registries.getComparatorRegistry() ); - + // -------------------------------------------------------------------- // Initialize schema partition or bomb out if we cannot find it on disk // -------------------------------------------------------------------- - + // If not present then we need to abort File schemaDirectory = new File( getLayout().getPartitionsDirectory(), "schema" ); - if ( ! schemaDirectory.exists() ) + if ( !schemaDirectory.exists() ) { - throw new LdapConfigurationException( "The following schema directory from " + - "the installation layout could not be found:\n\t" + schemaDirectory ); + throw new LdapConfigurationException( "The following schema directory from " + + "the installation layout could not be found:\n\t" + schemaDirectory ); } - + JdbmPartition schemaPartition = new JdbmPartition(); schemaPartition.setId( "schema" ); schemaPartition.setCacheSize( 1000 ); - + DbFileListing listing; - try + try { listing = new DbFileListing(); } - catch( IOException e ) + catch ( IOException e ) { - throw new LdapNamingException( "Got IOException while trying to read DBFileListing: " + e.getMessage(), + throw new LdapNamingException( "Got IOException while trying to read DBFileListing: " + e.getMessage(), ResultCodeEnum.OTHER ); } Set indexedAttributes = new HashSet(); - + for ( String attributeId : listing.getIndexedAttributes() ) { indexedAttributes.add( new JdbmIndex( attributeId ) ); } - + schemaPartition.setIndexedAttributes( indexedAttributes ); schemaPartition.setSuffix( ServerDNConstants.OU_SCHEMA_DN ); - + ServerEntry systemEntry = new DefaultServerEntry( registries, new LdapDN( "ou=schema" ) ); - systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, - SchemaConstants.TOP_OC, + systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC ); systemEntry.put( SchemaConstants.OU_AT, "schema" ); schemaPartition.setContextEntry( systemEntry ); @@ -178,11 +177,11 @@ // -------------------------------------------------------------------- // Initialize schema subsystem and reset registries // -------------------------------------------------------------------- - + PartitionSchemaLoader schemaLoader = new PartitionSchemaLoader( schemaPartition, registries ); Registries globalRegistries = new DefaultRegistries( "global", schemaLoader, oidRegistry ); schemaLoader.loadEnabled( globalRegistries ); - SerializableComparator.setRegistry( globalRegistries.getComparatorRegistry() ); + SerializableComparator.setRegistry( globalRegistries.getComparatorRegistry() ); return globalRegistries; } @@ -268,7 +267,7 @@ buf.append( "# Entry: " ).append( id ).append( "\n#---------------------\n\n" ); if ( !LdifUtils.isLDIFSafe( dn ) ) { - // If the DN isn't LdifSafe, it needs to be Base64 encoded. + // If the DN isn't LdifSafe, it needs to be Base64 encoded. buf.append( "dn:: " ).append( new String( Base64.encode( dn.getBytes() ) ) ); } Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/GracefulShutdownCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/GracefulShutdownCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/GracefulShutdownCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/GracefulShutdownCommand.java Wed Apr 2 04:06:56 2008 @@ -117,7 +117,7 @@ isSuccess = false; System.err.print( "shutdown request failed with error: " + t.getMessage() ); } - catch( CommunicationException e ) + catch ( CommunicationException e ) { isSuccess = true; } Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java Wed Apr 2 04:06:56 2008 @@ -19,6 +19,7 @@ */ package org.apache.directory.server.tools; + import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; @@ -68,6 +69,7 @@ import org.apache.directory.shared.ldap.name.Rdn; import org.apache.directory.shared.ldap.util.StringTools; + /** * A command to import data into a server. The data to be imported must be * stored in a Ldif File, and they could be added entries or modified entries. @@ -78,7 +80,7 @@ public class ImportCommand extends ToolCommand { public static final String PORT_RANGE = "(" + AvailablePortFinder.MIN_PORT_NUMBER + ", " - + AvailablePortFinder.MAX_PORT_NUMBER + ")"; + + AvailablePortFinder.MAX_PORT_NUMBER + ")"; private int port = 10389; @@ -95,9 +97,9 @@ private String logs; private boolean ignoreErrors = false; - + private static final int IMPORT_ERROR = -1; - private static final int IMPORT_SUCCESS= 0; + private static final int IMPORT_SUCCESS = 0; /** * Socket used to connect to the server @@ -110,6 +112,7 @@ private Asn1Decoder ldapDecoder = new LdapDecoder(); + /** * The constructor save the command's name into it's super class * @@ -119,6 +122,7 @@ super( "import" ); } + /** * Connect to the LDAP server through a socket and establish the Input and * Output Streams. All the required information for the connection should be @@ -136,12 +140,14 @@ channel.configureBlocking( true ); } + private void sendMessage( ByteBuffer bb ) throws IOException { channel.write( bb ); bb.clear(); } + private LdapMessage readResponse( ByteBuffer bb ) throws IOException, DecoderException, NamingException { @@ -164,29 +170,30 @@ if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED ) { - messageResp = ( (LdapMessageContainer) ldapMessageContainer ).getLdapMessage(); + messageResp = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage(); if ( messageResp instanceof BindResponse ) { - BindResponse resp = ( (LdapMessageContainer) ldapMessageContainer ).getLdapMessage().getBindResponse(); + BindResponse resp = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage() + .getBindResponse(); - if ( resp.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS ) + if ( resp.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS ) { System.out.println( "Error : " + resp.getLdapResult().getErrorMessage() ); } } else if ( messageResp instanceof ExtendedResponse ) { - ExtendedResponse resp = ( (LdapMessageContainer) ldapMessageContainer ).getLdapMessage() - .getExtendedResponse(); + ExtendedResponse resp = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage() + .getExtendedResponse(); - if ( resp.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS ) + if ( resp.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS ) { System.out.println( "Error : " + resp.getLdapResult().getErrorMessage() ); } } - ( (LdapMessageContainer) ldapMessageContainer ).clean(); + ( ( LdapMessageContainer ) ldapMessageContainer ).clean(); break; } else @@ -200,6 +207,7 @@ } + /** * Send the entry to the encoder, then wait for a * reponse from the LDAP server on the results of the operation. @@ -210,7 +218,7 @@ * message id number */ private int addEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, InvalidNameException, - NamingException, EncoderException + NamingException, EncoderException { AddRequest addRequest = new AddRequest(); @@ -230,7 +238,7 @@ for ( NamingEnumeration attrs = attributes.getAll(); attrs.hasMoreElements(); ) { - Attribute attribute = (Attribute) attrs.nextElement(); + Attribute attribute = ( Attribute ) attrs.nextElement(); addRequest.addAttributeType( attribute.getID() ); @@ -245,7 +253,7 @@ message.setProtocolOP( addRequest ); message.setMessageId( messageId ); - + // Encode and send the addRequest message ByteBuffer bb = message.encode( null ); bb.flip(); @@ -265,18 +273,19 @@ { System.out.println( "Add of Entry " + entry.getDn() + " was successful" ); } - + return IMPORT_SUCCESS; } else { - System.err.println( "Add of entry " + entry.getDn() + " failed for the following reasons provided by the server:\n" - + result.getErrorMessage() ); - + System.err.println( "Add of entry " + entry.getDn() + + " failed for the following reasons provided by the server:\n" + result.getErrorMessage() ); + return IMPORT_ERROR; } } + /** * Send the entry to the encoder, then wait for a * reponse from the LDAP server on the results of the operation. @@ -286,8 +295,8 @@ * @param msgId * message id number */ - private int deleteEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, InvalidNameException, - NamingException, EncoderException + private int deleteEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, + InvalidNameException, NamingException, EncoderException { DelRequest delRequest = new DelRequest(); @@ -297,14 +306,14 @@ { System.out.println( "Deleting entry " + dn ); } - + delRequest.setEntry( new LdapDN( dn ) ); - + LdapMessage message = new LdapMessage(); message.setProtocolOP( delRequest ); message.setMessageId( messageId ); - + // Encode and send the delete request ByteBuffer bb = message.encode( null ); bb.flip(); @@ -324,17 +333,18 @@ { System.out.println( "Delete of Entry " + entry.getDn() + " was successful" ); } - + return IMPORT_SUCCESS; } else { - System.err.println( "Delete of entry " + entry.getDn() + " failed for the following reasons provided by the server:\n" - + result.getErrorMessage() ); + System.err.println( "Delete of entry " + entry.getDn() + + " failed for the following reasons provided by the server:\n" + result.getErrorMessage() ); return IMPORT_ERROR; } } + /** * Send the entry to the encoder, then wait for a * reponse from the LDAP server on the results of the operation. @@ -344,8 +354,8 @@ * @param msgId * message id number */ - private int changeModRDNEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, InvalidNameException, - NamingException, EncoderException + private int changeModRDNEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, + InvalidNameException, NamingException, EncoderException { ModifyDNRequest modifyDNRequest = new ModifyDNRequest(); @@ -355,21 +365,21 @@ { System.out.println( "Modify DN of entry " + dn ); } - + modifyDNRequest.setEntry( new LdapDN( dn ) ); modifyDNRequest.setDeleteOldRDN( entry.isDeleteOldRdn() ); modifyDNRequest.setNewRDN( new Rdn( entry.getNewRdn() ) ); - + if ( StringTools.isEmpty( entry.getNewSuperior() ) == false ) { modifyDNRequest.setNewSuperior( new LdapDN( entry.getNewSuperior() ) ); } - + LdapMessage message = new LdapMessage(); message.setProtocolOP( modifyDNRequest ); message.setMessageId( messageId ); - + // Encode and send the delete request ByteBuffer bb = message.encode( null ); bb.flip(); @@ -389,17 +399,18 @@ { System.out.println( "ModifyDn of Entry " + entry.getDn() + " was successful" ); } - + return IMPORT_SUCCESS; } else { - System.err.println( "ModifyDn of entry " + entry.getDn() + " failed for the following reasons provided by the server:\n" - + result.getErrorMessage() ); + System.err.println( "ModifyDn of entry " + entry.getDn() + + " failed for the following reasons provided by the server:\n" + result.getErrorMessage() ); return IMPORT_ERROR; } } - + + /** * Send the entry to the encoder, then wait for a * reponse from the LDAP server on the results of the operation. @@ -409,8 +420,8 @@ * @param msgId * message id number */ - private int changeModifyEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, InvalidNameException, - NamingException, EncoderException + private int changeModifyEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, + InvalidNameException, NamingException, EncoderException { ModifyRequest modifyRequest = new ModifyRequest(); @@ -420,36 +431,36 @@ { System.out.println( "Modify of entry " + dn ); } - + modifyRequest.setObject( new LdapDN( dn ) ); modifyRequest.initModifications(); - + Iterator modifications = entry.getModificationItems().iterator(); - + while ( modifications.hasNext() ) { - ModificationItemImpl modification = (ModificationItemImpl)modifications.next(); - + ModificationItemImpl modification = ( ModificationItemImpl ) modifications.next(); + switch ( modification.getModificationOp() ) { - case DirContext.ADD_ATTRIBUTE : - modifyRequest.setCurrentOperation( LdapConstants.OPERATION_ADD ); + case DirContext.ADD_ATTRIBUTE: + modifyRequest.setCurrentOperation( LdapConstants.OPERATION_ADD ); break; - - case DirContext.REMOVE_ATTRIBUTE : - modifyRequest.setCurrentOperation( LdapConstants.OPERATION_DELETE ); + + case DirContext.REMOVE_ATTRIBUTE: + modifyRequest.setCurrentOperation( LdapConstants.OPERATION_DELETE ); break; - case DirContext.REPLACE_ATTRIBUTE : - modifyRequest.setCurrentOperation( LdapConstants.OPERATION_REPLACE ); + case DirContext.REPLACE_ATTRIBUTE: + modifyRequest.setCurrentOperation( LdapConstants.OPERATION_REPLACE ); break; - - default : + + default: System.err.println( "Unknown modify operation for DN " + dn ); } - + modifyRequest.addAttributeTypeAndValues( modification.getAttribute().getID() ); - + for ( NamingEnumeration values = modification.getAttribute().getAll(); values.hasMoreElements(); ) { Object value = values.nextElement(); @@ -461,7 +472,7 @@ message.setProtocolOP( modifyRequest ); message.setMessageId( messageId ); - + // Encode and send the delete request ByteBuffer bb = message.encode( null ); bb.flip(); @@ -481,17 +492,18 @@ { System.out.println( "Modify of Entry " + entry.getDn() + " was successful" ); } - + return IMPORT_SUCCESS; } else { - System.err.println( "Modify of entry " + entry.getDn() + " failed for the following reasons provided by the server:\n" - + result.getErrorMessage() ); + System.err.println( "Modify of entry " + entry.getDn() + + " failed for the following reasons provided by the server:\n" + result.getErrorMessage() ); return IMPORT_ERROR; } } - + + /** * Send the change operation to the encoder, then wait for a * reponse from the LDAP server on the results of the operation. @@ -501,10 +513,10 @@ * @param msgId * message id number */ - private int changeEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, InvalidNameException, - NamingException, EncoderException + private int changeEntry( LdifEntry entry, int messageId ) throws IOException, DecoderException, + InvalidNameException, NamingException, EncoderException { - switch ( entry.getChangeType().getChangeType() ) + switch ( entry.getChangeType().getChangeType() ) { case ChangeType.ADD_ORDINAL: // No difference with the injection of new entries @@ -525,6 +537,7 @@ } } + /** * Bind to the ldap server * @@ -539,7 +552,7 @@ if ( "simple".equals( auth ) ) { authentication = new SimpleAuthentication(); - ( (SimpleAuthentication) authentication ).setSimple( StringTools.getBytesUtf8( password ) ); + ( ( SimpleAuthentication ) authentication ).setSimple( StringTools.getBytesUtf8( password ) ); } bindRequest.setAuthentication( authentication ); @@ -548,7 +561,7 @@ message.setProtocolOP( bindRequest ); message.setMessageId( messageId ); - + // Encode and send the bind request ByteBuffer bb = message.encode( null ); bb.flip(); @@ -572,12 +585,13 @@ } else { - System.err.println( "Binding of user " + user + " failed for the following reasons provided by the server:\n" - + result.getErrorMessage() ); + System.err.println( "Binding of user " + user + + " failed for the following reasons provided by the server:\n" + result.getErrorMessage() ); System.exit( 1 ); } } + /** * Unbind from the server * @@ -599,13 +613,14 @@ bb.flip(); sendMessage( bb ); - + if ( isDebugEnabled() ) { System.out.println( "Unbinding of user " + user + " was successful" ); } } + /** * Execute the command * @@ -648,31 +663,31 @@ while ( entries.hasNext() ) { - LdifEntry entry = entries.next(); + LdifEntry entry = entries.next(); // Check if we have had some error, has next() does not throw any exception if ( ldifReader.hasError() ) { - System.err.println( "Found an error while persing an entry : " + ldifReader.getError().getMessage() ); - + System.err + .println( "Found an error while persing an entry : " + ldifReader.getError().getMessage() ); + if ( ignoreErrors == false ) { - unbind( messageId ); - + unbind( messageId ); + System.err.println( "Import failed..." ); System.exit( 1 ); } } - - if ( ( addEntry( entry, messageId++ ) == IMPORT_ERROR ) && - ( ignoreErrors == false ) ) + + if ( ( addEntry( entry, messageId++ ) == IMPORT_ERROR ) && ( ignoreErrors == false ) ) { - unbind( messageId ); - + unbind( messageId ); + System.err.println( "Import failed..." ); System.exit( 1 ); } - + nbAdd++; if ( nbAdd % 10 == 0 ) @@ -701,26 +716,26 @@ while ( entries.hasNext() ) { LdifEntry entry = entries.next(); - + // Check if we have had some error, has next() does not throw any exception if ( ldifReader.hasError() ) { - System.err.println( "Found an error while persing an entry : " + ldifReader.getError().getMessage() ); - + System.err + .println( "Found an error while persing an entry : " + ldifReader.getError().getMessage() ); + if ( ignoreErrors == false ) { - unbind( messageId ); - + unbind( messageId ); + System.err.println( "Import failed..." ); System.exit( 1 ); } } - if ( ( changeEntry( entry, messageId++ ) == IMPORT_ERROR ) && - ( ignoreErrors == false ) ) + if ( ( changeEntry( entry, messageId++ ) == IMPORT_ERROR ) && ( ignoreErrors == false ) ) { - unbind( messageId ); - + unbind( messageId ); + System.err.println( "Import failed..." ); System.exit( 1 ); } @@ -749,6 +764,7 @@ } + /** * Read the command line and get the options : 'h' : host 'p' : port 'u' : * user 'w' : password 'a' : authentication type 'i' : ignore errors 'f' : @@ -787,7 +803,7 @@ // ------------------------------------------------------------------- if ( cmd.hasOption( 'p' ) ) // - user provided port w/ -p takes - // precedence + // precedence { String val = cmd.getOptionValue( 'p' ); @@ -795,7 +811,7 @@ { port = Integer.parseInt( val ); } - catch (NumberFormatException e) + catch ( NumberFormatException e ) { System.err.println( "port value of '" + val + "' is not a number" ); System.exit( 1 ); @@ -804,13 +820,13 @@ if ( port > AvailablePortFinder.MAX_PORT_NUMBER ) { System.err.println( "port value of '" + val + "' is larger than max port number: " - + AvailablePortFinder.MAX_PORT_NUMBER ); + + AvailablePortFinder.MAX_PORT_NUMBER ); System.exit( 1 ); } else if ( port < AvailablePortFinder.MIN_PORT_NUMBER ) { System.err.println( "port value of '" + val + "' is smaller than the minimum port number: " - + AvailablePortFinder.MIN_PORT_NUMBER ); + + AvailablePortFinder.MIN_PORT_NUMBER ); System.exit( 1 ); } @@ -933,7 +949,7 @@ { System.out.println( "ldif file to import: " + ldifFile.getCanonicalPath() ); } - catch (IOException ioe) + catch ( IOException ioe ) { System.out.println( "ldif file to import: " + ldifFileName ); } @@ -945,6 +961,7 @@ System.exit( 1 ); } } + public Options getOptions() { Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/IndexCommand.java Wed Apr 2 04:06:56 2008 @@ -79,8 +79,8 @@ */ public class IndexCommand extends ToolCommand { - private Registries bootstrapRegistries = new DefaultRegistries( "bootstrap", - new BootstrapSchemaLoader(), new DefaultOidRegistry() ); + private Registries bootstrapRegistries = new DefaultRegistries( "bootstrap", new BootstrapSchemaLoader(), + new DefaultOidRegistry() ); public IndexCommand() @@ -88,6 +88,7 @@ super( "index" ); } + private Registries loadRegistries() throws Exception { // -------------------------------------------------------------------- @@ -98,7 +99,7 @@ BootstrapSchemaLoader loader = new BootstrapSchemaLoader(); OidRegistry oidRegistry = new DefaultOidRegistry(); final Registries registries = new DefaultRegistries( "bootstrap", loader, oidRegistry ); - + // load essential bootstrap schemas Set bootstrapSchemas = new HashSet(); bootstrapSchemas.add( new ApachemetaSchema() ); @@ -109,56 +110,55 @@ // run referential integrity tests List errors = registries.checkRefInteg(); - + if ( !errors.isEmpty() ) { NamingException e = new NamingException(); e.setRootCause( ( Throwable ) errors.get( 0 ) ); throw e; } - + SerializableComparator.setRegistry( registries.getComparatorRegistry() ); - + // -------------------------------------------------------------------- // Initialize schema partition or bomb out if we cannot find it on disk // -------------------------------------------------------------------- - + // If not present then we need to abort File schemaDirectory = new File( getLayout().getPartitionsDirectory(), "schema" ); - if ( ! schemaDirectory.exists() ) + if ( !schemaDirectory.exists() ) { - throw new LdapConfigurationException( "The following schema directory from " + - "the installation layout could not be found:\n\t" + schemaDirectory ); + throw new LdapConfigurationException( "The following schema directory from " + + "the installation layout could not be found:\n\t" + schemaDirectory ); } - + JdbmPartition schemaPartition = new JdbmPartition(); schemaPartition.setId( "schema" ); schemaPartition.setCacheSize( 1000 ); - + DbFileListing listing; - try + try { listing = new DbFileListing(); } - catch( IOException e ) + catch ( IOException e ) { - throw new LdapNamingException( "Got IOException while trying to read DBFileListing: " + e.getMessage(), + throw new LdapNamingException( "Got IOException while trying to read DBFileListing: " + e.getMessage(), ResultCodeEnum.OTHER ); } Set indexedAttributes = new HashSet(); - + for ( String attributeId : listing.getIndexedAttributes() ) { indexedAttributes.add( new JdbmIndex( attributeId ) ); } - + schemaPartition.setIndexedAttributes( indexedAttributes ); schemaPartition.setSuffix( ServerDNConstants.OU_SCHEMA_DN ); - + ServerEntry systemEntry = new DefaultServerEntry( registries, new LdapDN( "ou=schema" ) ); - systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, - SchemaConstants.TOP_OC, + systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC ); systemEntry.put( SchemaConstants.OU_AT, "schema" ); schemaPartition.setContextEntry( systemEntry ); @@ -169,14 +169,15 @@ // -------------------------------------------------------------------- // Initialize schema subsystem and reset registries // -------------------------------------------------------------------- - + PartitionSchemaLoader schemaLoader = new PartitionSchemaLoader( schemaPartition, registries ); Registries globalRegistries = new DefaultRegistries( "global", schemaLoader, oidRegistry ); schemaLoader.loadEnabled( globalRegistries ); - SerializableComparator.setRegistry( globalRegistries.getComparatorRegistry() ); + SerializableComparator.setRegistry( globalRegistries.getComparatorRegistry() ); return globalRegistries; } + public void execute( CommandLine cmdline ) throws Exception { getLayout().verifyInstallation(); @@ -220,7 +221,7 @@ Tuple tuple = ( Tuple ) list.next(); BigInteger id = ( BigInteger ) tuple.getKey(); Attributes entry = ( Attributes ) tuple.getValue(); - + Attribute attr = AttributeUtils.getAttribute( entry, attributeType ); if ( attr == null ) { @@ -232,7 +233,7 @@ index.add( attr.get( ii ), id ); } } - + index.sync(); } Modified: directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java?rev=643846&r1=643845&r2=643846&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java (original) +++ directory/apacheds/branches/bigbang/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java Wed Apr 2 04:06:56 2008 @@ -45,7 +45,7 @@ private ApacheDS apacheDS; - protected ToolCommand(String name) + protected ToolCommand( String name ) { this.name = name; }