示例#1
0
 /**
  * Cmd action to ask user and get a response
  *
  * @param argArray arguments in interpreter buffer
  * @return what's left of arguments
  */
 public ArgArray CmdCommentQuote(ArgArray argArray) {
   setDataDest(DataSink.fromSinkName("NULL:"));
   while (argArray.hasDashCommand()) {
     String dashCommand = argArray.parseDashCommand();
     switch (dashCommand) {
       case "-to":
         setDataDestfromArgArray(argArray);
         break;
       default:
         unknownDashCommand(dashCommand);
     }
   }
   if (havingUnknownDashCommand()) {
     setCommandResult(COMMANDRESULT.FAILURE);
   } else if (argArray.size() < 1) { // no text following
     logArgArrayTooShortError(argArray);
     setCommandResult(COMMANDRESULT.FAILURE);
   } else {
     String quote = argArray.nextMaybeQuotation();
     try {
       put(quote);
     } catch (SQLException
         | IOException
         | AS400SecurityException
         | ErrorCompletingRequestException
         | InterruptedException
         | ObjectDoesNotExistException
         | RequestNotSupportedException ex) {
       getLogger()
           .log(
               Level.SEVERE,
               "Could not put comment quote \"" + quote + "\" in " + getNameAndDescription(),
               ex);
       setCommandResult(COMMANDRESULT.FAILURE);
     }
   }
   return argArray;
 }
示例#2
0
  /**
   * Manage history file
   *
   * @param args the remainder of the command stream
   * @return the new remainder of the command stream
   */
  public ArgArray history(ArgArray args) {
    String historyFileName = History.DEFAULT_HISTORY_FILENAME;
    int numLines = 0;
    int doLine = 0;
    int firstLine = -1;
    int lastLine = -1;
    String change_from = null;
    String change_to = null;
    while (args.hasDashCommand()) {
      String dashCommand = args.parseDashCommand();
      switch (dashCommand) {
        case "-to":
          setDataDestfromArgArray(args);
          break;
        case "-off":
          setFunction(FUNCTIONS.OFF);
          break;
        case "-on":
          setFunction(FUNCTIONS.ON);
          break;
        case "-onfile":
          setFunction(FUNCTIONS.ONFILE);
          historyFileName = args.next();
          break;
        case "-range":
          setFunction(FUNCTIONS.RANGE);
          firstLine = args.nextInt();
          lastLine = args.nextInt();
          break;
        case "-show":
          setFunction(FUNCTIONS.SHOW);
          break;
        case "-head":
          setFunction(FUNCTIONS.HEAD);
          numLines = args.nextInt();
          break;
        case "-tail":
          setFunction(FUNCTIONS.TAIL);
          numLines = args.nextInt();
          break;
        case "-name":
          setFunction(FUNCTIONS.NAME);
          break;
        case "-do":
          setFunction(FUNCTIONS.DO);
          doLine = args.nextInt() - 1; // from one's-based history
          // to 0-based index into history array
          break;
        case "-change": // not a function, just a suboption to DO
          change_from = args.nextMaybeQuotation();
          change_to = args.nextMaybeQuotation();
          break;
        default:
          unknownDashCommand(dashCommand);
      }
    }
    if (havingUnknownDashCommand()) {
      setCommandResult(COMMANDRESULT.FAILURE);
    } else {
      History h = getInterpreter().getHistory();
      boolean withLineNumbers = getDataDest().getType() == DataSink.SINKTYPE.STD;
      switch (getFunction()) {
        case OFF:
          getInterpreter().closeHistory();
          break;
        case ON:
          getInterpreter().instanceHistory();
          break;
        case ONFILE:
          getInterpreter().setHistoryFileName(historyFileName);
          getInterpreter().instanceHistory();
          break;
        case SHOW:
          if (h != null) {
            try {
              put(h.show(withLineNumbers));
            } catch (IOException
                | RequestNotSupportedException
                | SQLException
                | AS400SecurityException
                | ErrorCompletingRequestException
                | InterruptedException
                | ObjectDoesNotExistException ex) {
              getLogger().log(Level.SEVERE, "Couldn't put history", ex);
              setCommandResult(COMMANDRESULT.FAILURE);
            }
          } else {
            getLogger().log(Level.SEVERE, "History is not enabled (try history -on)");
            setCommandResult(COMMANDRESULT.FAILURE);
          }
          break;
        case HEAD:
          if (h != null) {
            try {
              put(h.head(numLines, withLineNumbers));
            } catch (IOException
                | RequestNotSupportedException
                | SQLException
                | AS400SecurityException
                | ErrorCompletingRequestException
                | InterruptedException
                | ObjectDoesNotExistException ex) {
              getLogger().log(Level.SEVERE, "Couldn't put history", ex);
              setCommandResult(COMMANDRESULT.FAILURE);
            }
          } else {
            getLogger().log(Level.SEVERE, "History is not enabled (try history -on)");
            setCommandResult(COMMANDRESULT.FAILURE);
          }
          break;
        case TAIL:
          if (h != null) {
            try {
              put(h.tail(numLines, withLineNumbers));
            } catch (IOException
                | RequestNotSupportedException
                | SQLException
                | AS400SecurityException
                | ErrorCompletingRequestException
                | InterruptedException
                | ObjectDoesNotExistException ex) {
              getLogger().log(Level.SEVERE, "Couldn't put history", ex);
              setCommandResult(COMMANDRESULT.FAILURE);
            }
          } else {
            getLogger().log(Level.SEVERE, "History is not enabled (try history -on)");
            setCommandResult(COMMANDRESULT.FAILURE);
          }
          break;
        case NAME:
          if (h != null) {
            try {
              put(h.getHistoryFileName());
            } catch (IOException
                | RequestNotSupportedException
                | SQLException
                | AS400SecurityException
                | ErrorCompletingRequestException
                | InterruptedException
                | ObjectDoesNotExistException ex) {
              getLogger().log(Level.SEVERE, "Couldn't put history name", ex);
              setCommandResult(COMMANDRESULT.FAILURE);
            }
          } else {
            getLogger().log(Level.SEVERE, "History is not enabled (try history -on)");
            setCommandResult(COMMANDRESULT.FAILURE);
          }
          break;

        case DO:
          if (h != null) {
            if (doLine >= 0) {
              try {
                String nthLine = h.nth(doLine);
                if (nthLine != null) {
                  if (change_from != null && change_to != null) {
                    nthLine = nthLine.replace(change_from, change_to);
                  }
                  System.out.println(nthLine);
                  ArgArray newArgs = new Parser(getInterpreter(), nthLine).parseAnArgArray();
                  newArgs.addAll(args);
                  args = newArgs;
                } else {
                  getLogger()
                      .log(Level.SEVERE, "Line {0} does not exist in history buffer", doLine + 1);
                  setCommandResult(COMMANDRESULT.FAILURE);
                }
              } catch (IOException ex) {
                getLogger().log(Level.SEVERE, null, ex);
                setCommandResult(COMMANDRESULT.FAILURE);
              }
            } else {
              getLogger()
                  .log(Level.SEVERE, "Line '{'0'}' does not exist in history buffer", doLine + 1);
              setCommandResult(COMMANDRESULT.FAILURE);
            }
          } else {
            getLogger().log(Level.SEVERE, "History is not enabled (try history -on)");
            setCommandResult(COMMANDRESULT.FAILURE);
          }
          break;
        case RANGE:
          if (h != null) {
            try {
              put(h.range(firstLine - 1, lastLine - 1, withLineNumbers));
            } catch (IOException
                | RequestNotSupportedException
                | SQLException
                | AS400SecurityException
                | ErrorCompletingRequestException
                | InterruptedException
                | ObjectDoesNotExistException ex) {
              getLogger().log(Level.SEVERE, "Couldn't put history range", ex);
              setCommandResult(COMMANDRESULT.FAILURE);
            }
          } else {
            getLogger().log(Level.SEVERE, "History is not enabled (try history -on)");
            setCommandResult(COMMANDRESULT.FAILURE);
          }
          break;
      }
    }
    return args;
  }
示例#3
0
文件: CmdPpl.java 项目: jwoehr/ublu
 /**
  * Perform the work of getting a Job object and manipulating it.
  *
  * @param argArray the input arg array
  * @return what's left of the arg array
  */
 public ArgArray job(ArgArray argArray) {
   FUNCTIONS function = FUNCTIONS.INSTANCE;
   Tuple pplTuple = null;
   PrintParameterList instancePPL = null;
   int attributeId;
   String stringVal;
   Integer intVal;
   Float floatVal;
   Object getResult = null;
   while (argArray.hasDashCommand()) {
     String dashCommand = argArray.parseDashCommand();
     switch (dashCommand) {
       case "-to":
         setDataDestfromArgArray(argArray);
         break;
         //                case "-from":
         //                    String srcName = argArray.next();
         //                    setDataSrc(DataSink.fromSinkName(srcName));
         //                    break;
       case "-getint":
         function = FUNCTIONS.GETINT;
         attributeId = argArray.nextIntMaybeQuotationTuplePopString();
         getResult = getInt(pplTuple, attributeId);
         break;
       case "-getfloat":
         function = FUNCTIONS.GETFLOAT;
         attributeId = argArray.nextIntMaybeQuotationTuplePopString();
         getResult = getFloat(pplTuple, attributeId);
         break;
       case "-getstring":
         function = FUNCTIONS.GETSTRING;
         attributeId = argArray.nextIntMaybeQuotationTuplePopString();
         getResult = getString(pplTuple, attributeId);
         break;
       case "-new":
       case "-instance":
         function = FUNCTIONS.INSTANCE;
         instancePPL = new PrintParameterList();
         break;
       case "--":
       case "-ppl":
         pplTuple = argArray.nextTupleOrPop();
         break;
       case "-setint":
         function = FUNCTIONS.SETINT;
         attributeId = argArray.nextIntMaybeQuotationTuplePopString();
         intVal = argArray.nextIntMaybeQuotationTuplePopString();
         setInt(pplTuple, attributeId, intVal);
         break;
       case "-setfloat":
         function = FUNCTIONS.SETFLOAT;
         attributeId = argArray.nextIntMaybeQuotationTuplePopString();
         floatVal = Float.parseFloat(argArray.nextMaybeQuotationTuplePopString());
         setFloat(pplTuple, attributeId, floatVal);
         break;
       case "-setstring":
         function = FUNCTIONS.SETSTRING;
         attributeId = argArray.nextIntMaybeQuotationTuplePopString();
         stringVal = argArray.nextMaybeQuotationTuplePopString();
         setString(pplTuple, attributeId, stringVal);
         break;
       default:
         unknownDashCommand(dashCommand);
     }
   }
   if (havingUnknownDashCommand()) {
     setCommandResult(COMMANDRESULT.FAILURE);
   } else if (getCommandResult() != COMMANDRESULT.FAILURE) {
     switch (function) {
       case INSTANCE:
         try {
           put(instancePPL);
         } catch (SQLException
             | IOException
             | AS400SecurityException
             | ErrorCompletingRequestException
             | InterruptedException
             | ObjectDoesNotExistException
             | RequestNotSupportedException ex) {
           getLogger()
               .log(
                   Level.SEVERE,
                   "Error putting PrintParameterList in " + getNameAndDescription(),
                   ex);
           setCommandResult(COMMANDRESULT.FAILURE);
         }
         break;
       case SETFLOAT:
       case SETINT:
       case SETSTRING:
         try {
           if (pplTuple != null) {
             put(pplTuple.getValue());
           } else {
             put(null);
           }
         } catch (SQLException
             | IOException
             | AS400SecurityException
             | ErrorCompletingRequestException
             | InterruptedException
             | ObjectDoesNotExistException
             | RequestNotSupportedException ex) {
           getLogger()
               .log(
                   Level.SEVERE,
                   "Error putting PrintParameterList in " + getNameAndDescription(),
                   ex);
           setCommandResult(COMMANDRESULT.FAILURE);
         }
         break;
       case GETFLOAT:
       case GETINT:
       case GETSTRING:
         try {
           put(getResult);
         } catch (SQLException
             | IOException
             | AS400SecurityException
             | ErrorCompletingRequestException
             | InterruptedException
             | ObjectDoesNotExistException
             | RequestNotSupportedException ex) {
           getLogger()
               .log(
                   Level.SEVERE,
                   "Error putting PrintParameterList value in " + getNameAndDescription(),
                   ex);
           setCommandResult(COMMANDRESULT.FAILURE);
         }
         break;
     }
   }
   return argArray;
 }