Package org.apache.oodt.cas.cli.exception

Examples of org.apache.oodt.cas.cli.exception.CmdLineConstructionException


            // check if option is a valid one
            CmdLineOption option = getOptionByName(arg.getName(),
                  validOptions);
            if (option == null) {
               throw new CmdLineConstructionException("Invalid option: '" + arg.getName() + "'");
            }

            // read found option
            CmdLineOptionInstance specifiedOption = getOption(parsedArgs, option);

            // Check if we are currently loading subOptions.
            if (!groupOptions.isEmpty()) {

               CmdLineOptionInstance currentGroup = groupOptions.peek();

               // Check if option is NOT a subOption for current group.
               if (!isSubOption(currentGroup.getOption(), option)) {

                  // Check if current group was expecting more subOptions.
                  Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
                  if (!requiredSubOptions.isEmpty()) {
                     throw new CmdLineConstructionException(
                           "Missing the following required subOptions for '"
                                 + currentGroup.getOption()
                                 + "': "
                                 + sortOptionsByRequiredStatus(requiredSubOptions));

                  } else if (currentGroup.getSubOptions().isEmpty()) {
                     throw new CmdLineConstructionException(
                           "Must specify a subOption for group option '"
                                 + currentGroup.getOption() + "'");

                  } else {

                     // pop group and add to list of specified options.
                     optionInstances.add(groupOptions.pop());
                  }
               // It is a sub-option...
               } else {

                  // Add option to current group subOptions.
                  currentGroup.addSubOption(specifiedOption);
                  continue;

               }
            }

            if (option instanceof GroupCmdLineOption) {

               // Push group as current group.
               groupOptions.push(specifiedOption);
              
               if (!parsedArgs.hasNext()) {
                  throw new CmdLineConstructionException(
                        "Must specify a subOption for group option '"
                              + specifiedOption.getOption() + "'");
               }
            } else if (option.isSubOption()) {
               throw new CmdLineConstructionException("Option '" + option
                     + "' is a subOption, but was used at top level Option");

            } else {

               // Option good to go.
               optionInstances.add(specifiedOption);
            }
         } else {
            throw new CmdLineConstructionException("Invalid argument: '" + arg + "'");
         }
      }
      while (!groupOptions.isEmpty()) {
         CmdLineOptionInstance currentGroup = groupOptions.pop();
         Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
         if (!requiredSubOptions.isEmpty()) {
            throw new CmdLineConstructionException(
                  "Missing the following required subOptions for '"
                        + currentGroup.getOption() + "': "
                        + sortOptionsByRequiredStatus(requiredSubOptions));

         } else {
View Full Code Here


         specifiedOption.setValues(values);        
      } else if (option.hasArgs()) {
         if (!values.isEmpty()) {
            specifiedOption.setValues(values);
         } else if (!option.hasStaticArgs()) {
            throw new CmdLineConstructionException("Option " + option + " requires args");
         }
      } else if (!option.hasArgs() && !values.isEmpty()) {
         throw new CmdLineConstructionException("Option " + option + " does not support args");
      }
      return specifiedOption;
   }
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.cli.exception.CmdLineConstructionException

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.