/*
  verifies that each of our registered parameters has a value, either given or default

  throws an exeption otherwise
   */
  private void verify() throws Exception {
    for (Argument parameter : parameters.values()) {
      if (parameter.getValue() == null && parameter.getDefaultValue() == null) {
        throw new Exception(
            String.format("Argument '%s' is required.  Please see usage.", parameter.name));
      }
    }
  }
 /**
  * Goes through SynapsePath argument list, evaluating each by calling stringValueOf and returns a
  * HashMap String, String array where each item will contain a hash map with key "evaluated
  * expression" and value "SynapsePath type".
  *
  * @param synCtx
  * @return
  */
 private HashMap<String, String>[] getArgValues(MessageContext synCtx) {
   HashMap<String, String>[] argValues = new HashMap[pathArgumentList.size()];
   HashMap<String, String> valueMap;
   String value = "";
   for (int i = 0; i < pathArgumentList.size(); ++i) {
       /*ToDo use foreach*/
     Argument arg = pathArgumentList.get(i);
     if (arg.getValue() != null) {
       value = arg.getValue();
       if (!isWellFormedXML(value)) {
         value = StringEscapeUtils.escapeXml(value);
       }
       value = Matcher.quoteReplacement(value);
     } else if (arg.getExpression() != null) {
       value = arg.getExpression().stringValueOf(synCtx);
       if (value != null) {
         // XML escape the result of an expression that produces a literal, if the target format
         // of the payload is XML.
         if (!isWellFormedXML(value)
             && !arg.getExpression().getPathType().equals(SynapsePath.JSON_PATH)
             && XML_TYPE.equals(getType())) {
           value = StringEscapeUtils.escapeXml(value);
         }
         value = Matcher.quoteReplacement(value);
       } else {
         value = "";
       }
     } else {
       handleException("Unexpected arg type detected", synCtx);
     }
     // value = value.replace(String.valueOf((char) 160), " ").trim();
     valueMap = new HashMap<String, String>();
     if (null != arg.getExpression()) {
       valueMap.put(value, arg.getExpression().getPathType());
     } else {
       valueMap.put(value, SynapsePath.X_PATH);
     }
     argValues[i] = valueMap;
   }
   return argValues;
 }
 public Object getValue(String argumentName) {
   Object value = null;
   argumentName = argumentName.toLowerCase();
   if (parameters.containsKey(argumentName)) {
     Argument argument = parameters.get(argumentName);
     value = argument.getValue();
     if (value == null) {
       String defaultValue = argument.getDefaultValue();
       try {
         value = argument.getHandler().tryArgument(defaultValue);
       } catch (Exception e) {
       }
     }
   }
   return value;
 }
 /*
 Tries each handler for the given parameter and returns a success boolean
  */
 private boolean parseKV(String key, String value) throws Exception {
   boolean success = false;
   // must have a registered handler; see registerArgumentHandler()
   if (!parameters.containsKey(key)) {
     throw new Exception(key + " is not a valid argument");
   }
   Argument arg = parameters.get(key);
   // don't allow dupes
   if (arg.getValue() != null) {
     throw new Exception("Duplicate arguments: " + key);
   }
   try {
     // handler returns null if it can't handle the argument
     // it can throw an exception if the argument is an unacceptable value
     Object param = arg.getHandler().tryArgument(value);
     if (param != null) {
       arg.setValue(param);
       success = true;
     }
   } catch (Exception e) {
     throw new Exception("Bad argument value for '" + key + "': " + e.getMessage());
   }
   return success;
 }