/**
   * sets the encoding. neccessary if data should not be retrieved in the default encoding (i.e.
   * binary data in XML respones not raw data responses)
   *
   * @param encoding use base64
   * @param outputName ID of the output
   * @return
   */
  public boolean setEncodingForOutput(String encoding, String outputName) {
    if (!execute.getExecute().isSetResponseForm()) {
      execute.getExecute().addNewResponseForm();
    }
    if (!execute.getExecute().getResponseForm().isSetResponseDocument()) {
      execute.getExecute().getResponseForm().addNewResponseDocument();
    }
    OutputDescriptionType outputDesc = getOutputDescription(outputName);
    DocumentOutputDefinitionType outputDef = getOutputDefinition(outputName);
    if (outputDef == null) {
      outputDef = execute.getExecute().getResponseForm().getResponseDocument().addNewOutput();
      outputDef.setIdentifier(outputDesc.getIdentifier());
    }

    String defaultEncoding = outputDesc.getComplexOutput().getDefault().getFormat().getEncoding();
    if (defaultEncoding == null) {
      defaultEncoding = IOHandler.DEFAULT_ENCODING;
    }
    if (defaultEncoding.equals(encoding)) {
      return true;
    } else {
      ComplexDataDescriptionType[] supportedFormats =
          outputDesc.getComplexOutput().getSupported().getFormatArray();
      for (ComplexDataDescriptionType data : supportedFormats) {
        String e = data.getEncoding();
        if (e != null && e.equals(encoding)) {
          outputDef.setEncoding(encoding);
          return true;
        }
      }
    }

    return false;
  }
  /**
   * sets the desired mimetype of the output. if not set, the default mimetype will be used as
   * stated in the process description
   *
   * @param mimeType the name of the mimetype as announced in the processdescription
   * @param outputName the Identifier of the output element
   * @return success
   */
  public boolean setMimeTypeForOutput(String mimeType, String outputName) {
    if (!execute.getExecute().isSetResponseForm()) {
      execute.getExecute().addNewResponseForm();
    }
    if (!execute.getExecute().getResponseForm().isSetResponseDocument()) {
      execute.getExecute().getResponseForm().addNewResponseDocument();
    }
    OutputDescriptionType outputDesc = getOutputDescription(outputName);
    DocumentOutputDefinitionType outputDef = getOutputDefinition(outputName);
    if (outputDef == null) {
      outputDef = execute.getExecute().getResponseForm().getResponseDocument().addNewOutput();
      outputDef.setIdentifier(outputDesc.getIdentifier());
    }

    String defaultMimeType = outputDesc.getComplexOutput().getDefault().getFormat().getMimeType();
    if (defaultMimeType == null) {
      defaultMimeType = "text/xml";
    }
    if (defaultMimeType.equals(mimeType)) {
      //			outputDef.setMimeType(mimeType);//TODO: check
      return true;
    } else {
      for (ComplexDataDescriptionType data :
          outputDesc.getComplexOutput().getSupported().getFormatArray()) {
        String m = data.getMimeType();
        if (m != null && m.equals(mimeType)) {
          outputDef.setMimeType(mimeType);
          return true;
        }
      }
    }

    return false;
  }
  /**
   * Set this if you want the data to a schema offered in the process description
   *
   * @param schema
   * @param outputName
   * @return
   */
  public boolean setSchemaForOutput(String schema, String outputName) {
    if (!execute.getExecute().isSetResponseForm()) {
      execute.getExecute().addNewResponseForm();
    }
    if (!execute.getExecute().getResponseForm().isSetResponseDocument()) {
      execute.getExecute().getResponseForm().addNewResponseDocument();
    }
    OutputDescriptionType outputDesc = getOutputDescription(outputName);
    DocumentOutputDefinitionType outputDef = getOutputDefinition(outputName);
    if (outputDef == null) {
      outputDef = execute.getExecute().getResponseForm().getResponseDocument().addNewOutput();
      outputDef.setIdentifier(outputDesc.getIdentifier());
    }
    String defaultSchema = outputDesc.getComplexOutput().getDefault().getFormat().getSchema();
    if ((defaultSchema != null && defaultSchema.equals(schema))
        || (defaultSchema == null && schema == null)) {
      outputDef.setSchema(schema);
      return true;
    } else {
      for (ComplexDataDescriptionType data :
          outputDesc.getComplexOutput().getSupported().getFormatArray()) {
        if (data.getSchema() != null && data.getSchema().equals(schema)) {
          outputDef.setSchema(schema);
          return true;
        } else if ((data.getSchema() == null && schema == null)) {
          return true;
        }
      }
    }

    return false;
  }
 public WpsOutputDefinition(
     String inWpsRequestId, DocumentOutputDefinitionType outputDefinitionType) {
   id = UUID.randomUUID().toString();
   wpsRequestId = inWpsRequestId;
   outputIdentifer = outputDefinitionType.getIdentifier().getStringValue();
   this.mimeType = outputDefinitionType.getMimeType();
 }
  private DocumentOutputDefinitionType getOutputDefinition(String outputName) {
    DocumentOutputDefinitionType[] outputs =
        execute.getExecute().getResponseForm().getResponseDocument().getOutputArray();
    for (DocumentOutputDefinitionType outputDef : outputs) {
      if (outputDef.getIdentifier().getStringValue().equals(outputName)) {
        return outputDef;
      }
    }

    return null;
  }
 /**
  * this sets store for the specific output.
  *
  * @param parentInput
  * @return
  */
 public boolean setStoreSupport(String outputName) {
   DocumentOutputDefinitionType outputDef = null;
   if (!execute.getExecute().isSetResponseForm()) {
     execute.getExecute().addNewResponseForm();
   }
   if (!execute.getExecute().getResponseForm().isSetResponseDocument()) {
     execute.getExecute().getResponseForm().addNewResponseDocument();
   }
   for (DocumentOutputDefinitionType outputDefTemp :
       execute.getExecute().getResponseForm().getResponseDocument().getOutputArray()) {
     if (outputDefTemp.getIdentifier().getStringValue().equals(outputName)) {
       outputDef = outputDefTemp;
       break;
     }
   }
   if (outputDef == null) {
     outputDef = execute.getExecute().getResponseForm().getResponseDocument().addNewOutput();
   }
   for (OutputDescriptionType outputDesc : processDesc.getProcessOutputs().getOutputArray()) {
     if (outputDesc.getIdentifier().getStringValue().equals(outputName)) {
       outputDef.setIdentifier(outputDesc.getIdentifier());
       ComplexDataDescriptionType format = outputDesc.getComplexOutput().getDefault().getFormat();
       if (format.getMimeType() != null) {
         outputDef.setMimeType(format.getMimeType());
       }
       if (format.getEncoding() != null) {
         outputDef.setEncoding(format.getEncoding());
       }
       if (format.getSchema() != null) {
         outputDef.setSchema(format.getSchema());
       }
       outputDef.setAsReference(true);
     }
   }
   return true;
 }
  /**
   * return a KVP representation for the created execute document.
   *
   * @return KVP request string
   */
  public String getExecuteAsGETString() {
    String request = "?service=wps&request=execute&version=1.0.0&identifier=";
    request = request + processDesc.getIdentifier().getStringValue();
    request = request + "&DataInputs=";
    InputType[] inputs = execute.getExecute().getDataInputs().getInputArray();
    int inputCounter = 0;
    for (InputType input : inputs) {

      request = request + input.getIdentifier().getStringValue();

      if (input.isSetReference()) {
        // reference
        InputReferenceType reference = input.getReference();
        request = request + "=" + "@xlink:href=" + URLEncoder.encode(reference.getHref());
        if (reference.isSetEncoding()) {
          request = request + "@encoding=" + reference.getEncoding();
        }
        if (reference.isSetMimeType()) {
          request = request + "@format=" + reference.getMimeType();
        }
        if (reference.isSetEncoding()) {
          request = request + "@schema=" + reference.getSchema();
        }
      }
      if (input.isSetData()) {
        if (input.getData().isSetComplexData()) {
          // complex
          ComplexDataType complexData = input.getData().getComplexData();
          request = request + "=" + URLEncoder.encode(input.getData().getComplexData().xmlText());
          if (complexData.isSetEncoding()) {
            request = request + "@encoding=" + complexData.getEncoding();
          }
          if (complexData.isSetMimeType()) {
            request = request + "@format=" + complexData.getMimeType();
          }
          if (complexData.isSetEncoding()) {
            request = request + "@schema=" + complexData.getSchema();
          }
        }
        if (input.getData().isSetLiteralData()) {
          // literal
          LiteralDataType literalData = input.getData().getLiteralData();
          request = request + "=" + literalData.getStringValue();
          if (literalData.isSetDataType()) {
            request = request + "@datatype=" + literalData.getDataType();
          }
          if (literalData.isSetUom()) {
            request = request + "@datatype=" + literalData.getUom();
          }
        }
      }
      // concatenation for next input element
      inputCounter = inputCounter + 1;
      if (inputCounter < inputs.length) {
        request = request + ";";
      }
    }
    if (execute.getExecute().getResponseForm().getResponseDocument() == null) {
      throw new RuntimeException("Responresponsedocument=se Form missing");
    }
    DocumentOutputDefinitionType[] outputs =
        execute.getExecute().getResponseForm().getResponseDocument().getOutputArray();
    int outputCounter = 0;
    if (execute.getExecute().getResponseForm().isSetRawDataOutput()) {
      request = request + "&rawdataoutput=";
    } else {
      request = request + "&responsedocument=";
    }
    for (DocumentOutputDefinitionType output : outputs) {
      request = request + output.getIdentifier().getStringValue();
      if (output.isSetEncoding()) {
        request = request + "@encoding=" + output.getEncoding();
      }
      if (output.isSetMimeType()) {
        request = request + "@format=" + output.getMimeType();
      }
      if (output.isSetEncoding()) {
        request = request + "@schema=" + output.getSchema();
      }
      if (output.isSetUom()) {
        request = request + "@datatype=" + output.getUom();
      }
      // concatenation for next output element
      outputCounter = outputCounter + 1;
      if (outputCounter < outputs.length) {
        request = request + ";";
      }
    }

    if (execute.getExecute().getResponseForm().getResponseDocument().isSetStoreExecuteResponse()) {
      request = request + "&storeExecuteResponse=true";
    }
    if (execute.getExecute().getResponseForm().getResponseDocument().isSetStatus()) {
      request = request + "&status=true";
    }
    if (execute.getExecute().getResponseForm().getResponseDocument().isSetLineage()) {
      request = request + "&lineage=true";
    }

    return request;
  }