Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je.utilint;
  
Used as the main class for the manifest of the je.jar file, and so it is executed when running: java -jar je.jar. The first argument must be the final part of the class name of a utility in the com.sleepycat.je.util package, e.g., DbDump. All following parameters are passed to the main method of the utility and are processed as usual. Apart from the package, this class is ambivalent about the name of the utility specified; the only requirement is that it must be a public static class and must contain a public static main method.
 
 public class JarMain {
 
     private static final String USAGE = "usage: java <utility> [options...]";
 
     /* Use a HashMap to allow the utilities to live in multiple packages. */
     private static HashMap<StringStringutilPrefixMap =
         new HashMap<StringString>();
 
     /* Map each utility name to its package. */
     static {
         /* The utilities in directory com/sleepycat/je/util. */
         .put("DbCacheSize""com.sleepycat.je.util.");
         .put("DbDump""com.sleepycat.je.util.");
         .put("DbLoad""com.sleepycat.je.util.");
         .put("DbPrintLog""com.sleepycat.je.util.");
         .put("DbTruncateLog""com.sleepycat.je.util.");
         .put("DbRunAction""com.sleepycat.je.util.");
         .put("DbScavenger""com.sleepycat.je.util.");
         .put("DbSpace""com.sleepycat.je.util.");
         .put("DbStat""com.sleepycat.je.util.");
         .put("DbVerify""com.sleepycat.je.util.");
         .put("DbVerifyLog""com.sleepycat.je.util.");
 
         /* The utilities in directory com/sleepycat/je/rep/util. */
         .put("DbEnableReplication",
                           "com.sleepycat.je.rep.util.");
         .put("DbGroupAdmin""com.sleepycat.je.rep.util.");
         .put("DbPing""com.sleepycat.je.rep.util.");
         .put("LDiff""com.sleepycat.je.rep.util.ldiff.");
 
         /* The utilities in directory com/sleepycat/je/rep/utilint. */
         .put("DbDumpGroup""com.sleepycat.je.rep.utilint.");
         .put("DbFeederPrintLog",
                           "com.sleepycat.je.rep.utilint.");
         .put("DbStreamVerify""com.sleepycat.je.rep.utilint.");
         .put("DbSync""com.sleepycat.je.rep.utilint.");
         .put("DbRepRunAction""com.sleepycat.je.rep.utilint.");
         .put("DbNullNode""com.sleepycat.je.rep.utilint.");
     }
 
     /* List all the available utilities. */
     private static String availableUtilities() {
         StringBuilder sbuf = new StringBuilder();
         for (String util : .keySet()) {
             sbuf.append(.get(util));
             sbuf.append(util);
             sbuf.append("\n");
         }
 
         return sbuf.toString();
     }
 
     public static void main(String[] args) {
         try {
             if (args.length < 1) {
                 usage("Missing utility name");
             }
 
             String utilPrefix = .get(args[0]);
             if (utilPrefix == null) {
                 ..println("Available utilities are: ");
                 ..println(availableUtilities());
                 usage("No such utility");
             }
 
             Class<?> cls = Class.forName(utilPrefix + args[0]);
 
             Method mainMethod = cls.getMethod
                 ("main"new Class[] { String[].class });
 
             String[] mainArgs = new String[args.length - 1];
             System.arraycopy(args, 1, mainArgs, 0, mainArgs.length);
 
             mainMethod.invoke(nullnew Object[] { mainArgs });
         } catch (InvocationTargetException ITE) {
            if (ITE.getCause() != null) {
                usage(ITE.getCause().toString());
            } else {
                ..println("Problem invoking main method:");
                ITE.printStackTrace(.);
            }
        } catch (Throwable e) {
            e.printStackTrace();
            usage(e.toString());
        }
    }
    private static void usage(String msg) {
        ..println(msg);
        ..println();
        System.exit(-1);
    }
New to GrepCode? Check out our FAQ X