001 /* 002 * Copyright 2010-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2015 UnboundID Corp. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021 package com.unboundid.ldap.sdk.unboundidds; 022 023 024 025 import java.io.OutputStream; 026 import java.io.PrintStream; 027 028 import com.unboundid.ldap.listener.InMemoryDirectoryServerTool; 029 import com.unboundid.ldap.sdk.ResultCode; 030 import com.unboundid.ldap.sdk.Version; 031 import com.unboundid.ldap.sdk.examples.AuthRate; 032 import com.unboundid.ldap.sdk.examples.IdentifyReferencesToMissingEntries; 033 import com.unboundid.ldap.sdk.examples.IdentifyUniqueAttributeConflicts; 034 import com.unboundid.ldap.sdk.examples.LDAPCompare; 035 import com.unboundid.ldap.sdk.examples.LDAPDebugger; 036 import com.unboundid.ldap.sdk.examples.LDAPModify; 037 import com.unboundid.ldap.sdk.examples.LDAPSearch; 038 import com.unboundid.ldap.sdk.examples.ModRate; 039 import com.unboundid.ldap.sdk.examples.SearchRate; 040 import com.unboundid.ldap.sdk.examples.SearchAndModRate; 041 import com.unboundid.ldap.sdk.examples.ValidateLDIF; 042 import com.unboundid.ldap.sdk.persist.GenerateSchemaFromSource; 043 import com.unboundid.ldap.sdk.persist.GenerateSourceFromSchema; 044 import com.unboundid.ldap.sdk.unboundidds.examples.DumpDNs; 045 import com.unboundid.ldap.sdk.unboundidds.examples.SubtreeAccessibility; 046 import com.unboundid.ldap.sdk.unboundidds.examples.SummarizeAccessLog; 047 import com.unboundid.util.StaticUtils; 048 import com.unboundid.util.ThreadSafety; 049 import com.unboundid.util.ThreadSafetyLevel; 050 051 052 053 /** 054 * <BLOCKQUOTE> 055 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID 056 * LDAP SDK for Java. It is not available for use in applications that 057 * include only the Standard Edition of the LDAP SDK, and is not supported for 058 * use in conjunction with non-UnboundID products. 059 * </BLOCKQUOTE> 060 * This class provides an entry point that may be used to launch other tools 061 * provided as part of the LDAP SDK. This is primarily a convenience for 062 * someone who just has the jar file and none of the scripts, since you can run 063 * "<CODE>java -jar unboundid-ldapsdk-se.jar {tool-name} {tool-args}</CODE>" 064 * in order to invoke any of the example tools. Running just 065 * "<CODE>java -jar unboundid-ldapsdk-se.jar</CODE>" will display version 066 * information about the LDAP SDK. 067 * <BR><BR> 068 * The tool names are case-insensitive. Supported tool names include: 069 * <UL> 070 * <LI>authrate -- Launch the {@link AuthRate} tool.</LI> 071 * <LI>deliver-one-time-password -- Launch the 072 * {@link DeliverOneTimePassword} tool.</LI> 073 * <LI>dump-dns -- Launch the {@link DumpDNs} tool.</LI> 074 * <LI>in-memory-directory-server -- Launch the 075 * {@link InMemoryDirectoryServerTool} tool.</LI> 076 * <LI>generate-schema-from-source -- Launch the 077 * {@link GenerateSchemaFromSource} tool.</LI> 078 * <LI>generate-source-from-schema -- Launch the 079 * {@link GenerateSourceFromSchema} tool.</LI> 080 * <LI>identify-references-to-missing-entries -- Launch the 081 * {@link IdentifyReferencesToMissingEntries} tool.</LI> 082 * <LI>identify-unique-attribute-conflicts -- Launch the 083 * {@link IdentifyUniqueAttributeConflicts} tool.</LI> 084 * <LI>in-memory-directory-server -- Launch the 085 * {@link InMemoryDirectoryServerTool} tool.</LI> 086 * <LI>ldapcompare -- Launch the {@link LDAPCompare} tool.</LI> 087 * <LI>ldapmodify -- Launch the {@link LDAPModify} tool.</LI> 088 * <LI>ldapsearch -- Launch the {@link LDAPSearch} tool.</LI> 089 * <LI>ldap-debugger -- Launch the {@link LDAPDebugger} tool.</LI> 090 * <LI>modrate -- Launch the {@link ModRate} tool.</LI> 091 * <LI>move-subtree -- Launch the {@link MoveSubtree} tool.</LI> 092 * <LI>searchrate -- Launch the {@link SearchRate} tool.</LI> 093 * <LI>search-and-mod-rate -- Launch the {@link SearchAndModRate} tool.</LI> 094 * <LI>subtree-accessibility -- Launch the {@link SubtreeAccessibility} 095 * tool.</LI> 096 * <LI>summarize-access-log -- Launch the {@link SummarizeAccessLog} 097 * tool.</LI> 098 * <LI>validate-ldif -- Launch the {@link ValidateLDIF} tool.</LI> 099 * <LI>version -- Display version information for the LDAP SDK.</LI> 100 * </UL> 101 */ 102 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 103 public final class Launcher 104 { 105 /** 106 * Prevent this utility class from being instantiated. 107 */ 108 Launcher() 109 { 110 // No implementation required. 111 } 112 113 114 115 /** 116 * Parses the command-line arguments and performs any appropriate processing 117 * for this program. 118 * 119 * @param args The command-line arguments provided to this program. 120 */ 121 public static void main(final String... args) 122 { 123 main(System.out, System.err, args); 124 } 125 126 127 128 /** 129 * Parses the command-line arguments and performs any appropriate processing 130 * for this program. 131 * 132 * @param outStream The output stream to which standard out should be 133 * written. It may be {@code null} if output should be 134 * suppressed. 135 * @param errStream The output stream to which standard error should be 136 * written. It may be {@code null} if error messages 137 * should be suppressed. 138 * @param args The command-line arguments provided to this program. 139 * 140 * @return A result code with information about the status of processing. 141 */ 142 public static ResultCode main(final OutputStream outStream, 143 final OutputStream errStream, 144 final String... args) 145 { 146 if ((args == null) || (args.length == 0) || 147 args[0].equalsIgnoreCase("version")) 148 { 149 if (outStream != null) 150 { 151 final PrintStream out = new PrintStream(outStream); 152 for (final String line : Version.getVersionLines()) 153 { 154 out.println(line); 155 } 156 } 157 158 return ResultCode.SUCCESS; 159 } 160 161 final String firstArg = StaticUtils.toLowerCase(args[0]); 162 final String[] remainingArgs = new String[args.length - 1]; 163 System.arraycopy(args, 1, remainingArgs, 0, remainingArgs.length); 164 165 if (firstArg.equals("authrate")) 166 { 167 return AuthRate.main(remainingArgs, outStream, errStream); 168 } 169 else if (firstArg.equals("deliver-one-time-password")) 170 { 171 return DeliverOneTimePassword.main(remainingArgs, outStream, errStream); 172 } 173 else if (firstArg.equals("dump-dns")) 174 { 175 return DumpDNs.main(remainingArgs, outStream, errStream); 176 } 177 else if (firstArg.equals("identify-references-to-missing-entries")) 178 { 179 return IdentifyReferencesToMissingEntries.main(remainingArgs, outStream, 180 errStream); 181 } 182 else if (firstArg.equals("identify-unique-attribute-conflicts")) 183 { 184 return IdentifyUniqueAttributeConflicts.main(remainingArgs, outStream, 185 errStream); 186 } 187 else if (firstArg.equals("in-memory-directory-server")) 188 { 189 return InMemoryDirectoryServerTool.main(remainingArgs, outStream, 190 errStream); 191 } 192 else if (firstArg.equals("generate-schema-from-source")) 193 { 194 return GenerateSchemaFromSource.main(remainingArgs, outStream, errStream); 195 } 196 else if (firstArg.equals("generate-source-from-schema")) 197 { 198 return GenerateSourceFromSchema.main(remainingArgs, outStream, errStream); 199 } 200 else if (firstArg.equals("ldapcompare")) 201 { 202 return LDAPCompare.main(remainingArgs, outStream, errStream); 203 } 204 else if (firstArg.equals("ldapmodify")) 205 { 206 return LDAPModify.main(remainingArgs, outStream, errStream); 207 } 208 else if (firstArg.equals("ldapsearch")) 209 { 210 return LDAPSearch.main(remainingArgs, outStream, errStream); 211 } 212 else if (firstArg.equals("ldap-debugger")) 213 { 214 return LDAPDebugger.main(remainingArgs, outStream, errStream); 215 } 216 else if (firstArg.equals("modrate")) 217 { 218 return ModRate.main(remainingArgs, outStream, errStream); 219 } 220 else if (firstArg.equals("move-subtree")) 221 { 222 return MoveSubtree.main(remainingArgs, outStream, errStream); 223 } 224 else if (firstArg.equals("searchrate")) 225 { 226 return SearchRate.main(remainingArgs, outStream, errStream); 227 } 228 else if (firstArg.equals("search-and-mod-rate")) 229 { 230 return SearchAndModRate.main(remainingArgs, outStream, errStream); 231 } 232 else if (firstArg.equals("subtree-accessibility")) 233 { 234 return SubtreeAccessibility.main(remainingArgs, outStream, errStream); 235 } 236 else if (firstArg.equals("summarize-access-log")) 237 { 238 return SummarizeAccessLog.main(remainingArgs, outStream, errStream); 239 } 240 else if (firstArg.equals("validate-ldif")) 241 { 242 return ValidateLDIF.main(remainingArgs, outStream, errStream); 243 } 244 else 245 { 246 if (errStream != null) 247 { 248 final PrintStream err = new PrintStream(errStream); 249 err.println("Unrecognized tool name '" + args[0] + '\''); 250 err.println("Supported tool names include:"); 251 err.println(" authrate"); 252 err.println(" deliver-one-time-password"); 253 err.println(" dump-dns"); 254 err.println(" identify-references-to-missing-entries"); 255 err.println(" identify-unique-attribute-conflicts"); 256 err.println(" in-memory-directory-server"); 257 err.println(" generate-schema-from-source"); 258 err.println(" generate-source-from-schema"); 259 err.println(" ldapcompare"); 260 err.println(" ldapmodify"); 261 err.println(" ldapsearch"); 262 err.println(" ldap-debugger"); 263 err.println(" modrate"); 264 err.println(" move-subtree"); 265 err.println(" searchrate"); 266 err.println(" search-and-mod-rate"); 267 err.println(" subtree-accessibility"); 268 err.println(" summarize-access-log"); 269 err.println(" validate-ldif"); 270 err.println(" version"); 271 } 272 273 return ResultCode.PARAM_ERROR; 274 } 275 } 276 }