Package org.openbp.common.commandline

Examples of org.openbp.common.commandline.CommandLineParser


    SyncModel processor = null;
    try
    {
      Application.setArguments(args);

      CommandLineParser cp = new CommandLineParser();
      cp
        .setUsageMsgHeader(new String[]
        {
          "Model synchronization utility.",
          "Copies model data between different model manager types",
          "", "Usage:",
        });

      cp.addArgumentOption("SourceMgr", "Source model manager (classpath|filesystem|database) (default: filesystem)");
      cp.addArgumentOption("TargetMgr", "Target model manager (filesystem|database) (default: database)");
      cp.addArgumentOption("Mode", "Operation mode (Copy|CopyAll|Remove|RemoveAll) (default: copy)");
      cp.addBooleanOption("Overwrite", "Forces existing models that exist in the target manager to be removed before the copy operation takes place (default: false)");

      try
      {
        cp.parse(args);
      }
      catch (CommandLineParserException e)
      {
        System.err.println(e.getMessage());
        cp.printUsageAndExit();
      }

      processor = new SyncModel();
      processor.setProcessServer(new ProcessServerFactory().createProcessServer("OpenBP-SyncModel-Hibernate.spring.xml"));

      int mode = 0;
      String m = cp.getStringOption("Mode");
      if (m.equalsIgnoreCase("Copy"))
      {
        mode = MODE_COPY;
      }
      else if (m.equalsIgnoreCase("CopyAll"))
      {
        mode = MODE_COPY_ALL;
      }
      else if (m.equalsIgnoreCase("Remove"))
      {
        mode = MODE_REMOVE;
      }
      else if (m.equalsIgnoreCase("RemoveAll"))
      {
        mode = MODE_REMOVE_ALL;
      }
      else
      {
        printError("Unknown operation mode '" + m + "'.");
      }
      processor.setMode(mode);

      String sourceMgrType = cp.getStringOption("SourceMgr");
      if (sourceMgrType == null)
        sourceMgrType = "filesystem";
      processor.setSourceMgrType(sourceMgrType);
      String targetMgrType = cp.getStringOption("TargetMgr");
      if (targetMgrType == null)
        targetMgrType = "database";
      processor.setTargetMgrType(targetMgrType);
      processor.setOverwrite(cp.getBooleanOption("Overwrite"));

      boolean hasArguments = false;
      String [] modelNames = cp.getArguments();
      if (modelNames != null)
      {
        for (int i = 0; i < modelNames.length; ++i)
        {
          processor.addModel(modelNames[i]);
View Full Code Here


  {
    try
    {
      Application.setArguments(args);

      CommandLineParser cp = new CommandLineParser();
      cp
        .setUsageMsgHeader(new String[]
        {
          "DDL generator for Hibernate persistence-based applications.",
          "This utility will generate create and drop DDLs based on the current Hibernate configuration (needs hibernate.cfg.xml in the classpath).",
          "The OpenBP proccess and workflow control entities will be added to the configuration automatically.",
          "", "Usage:",
        });

      cp.addArgumentOption("Dialect", "Database dialect to use for generating (also affects the output directory).");
      cp.addArgumentOption("BaseDir", "Output directory that will contain the dialect-specific sub directories.");
      cp.addArgumentOption("DDLCreateFile", "Name of the output file that will contain the DDL create statements");
      cp.addArgumentOption("DDLDropFile", "Name of the output file that will contain the DDL drop statements");

      try
      {
        cp.parse(args);
      }
      catch (CommandLineParserException e)
      {
        System.err.println(e.getMessage());
        cp.printUsageAndExit();
      }

      HibernateDDLGenerator generator = new HibernateDDLGenerator();

      generator.setDialect(cp.getStringOption("Dialect"));
      generator.setBaseDir(cp.getStringOption("BaseDir"));
      generator.setDdlCreateFileName(cp.getStringOption("DdlCreateFile"));
      generator.setDdlDropFileName(cp.getStringOption("DdlDropFile"));

      if (generator.getDdlCreateFileName() == null && generator.getDdlDropFileName() == null)
      {
        cp.printUsageAndExit();
      }

      generator.generate();

      System.exit(0);
View Full Code Here

    // Check for the configuration-related arguments
    String [] args = Application.getArguments();
    if (args != null)
    {
      CommandLineParser cp = new CommandLineParser();
      cp.setAcceptUnknownOptions(true);

      cp.addRepeatableOption("propertyFile", "Name of a property resource containing configuration information");
      cp.addRepeatableOption("property", "Configuration property value");

      try
      {
        cp.parse(args);

        String [] propertyFiles = cp.getRepeatableOption("propertyFile");
        if (propertyFiles != null)
        {
          for (int i = 0; i < propertyFiles.length; ++i)
          {
            String file = propertyFiles[i];
            readPropertyResource(file, true);
          }
        }

        String [] propertyKeys = cp.getRepeatableOption("property");
        if (propertyKeys != null)
        {
          for (int i = 0; i < propertyKeys.length; ++i)
          {
            String prop = propertyKeys[i];
            String key = null;
            String value = "true";

            int index = prop.indexOf("=");
            if (index > 0)
            {
              key = prop.substring(0, index);
              value = prop.substring(index + 1);
            }
            else
            {
              key = prop;
            }
            setValue(key, value);
          }
        }
      }
      catch (CommandLineParserException e)
      {
        System.err.println(e.getMessage());
        System.err.println("");
        cp.printUsageAndExit();
      }
    }

    if (first)
    {
View Full Code Here

TOP

Related Classes of org.openbp.common.commandline.CommandLineParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.