/**
   * Handle the request primitive retrieve ... TODO: Strategy for error handling ... TS0004 7.1.1.2
   *
   * @param onem2mResponse response
   */
  public void handleOperationRetrieve(ResponsePrimitive onem2mResponse) {

    // Use table TS0004: 7.1.1.1-1 to validate RETRIEVE specific parameters that were not handled in
    // the calling routine

    // if the content format is provided then it must be supported
    String cf = getPrimitive(RequestPrimitive.CONTENT_FORMAT);
    if (cf != null) {
      if (!cf.contentEquals(Onem2m.ContentFormat.JSON)
          && !cf.contentEquals(Onem2m.ContentFormat.XML)) {
        onem2mResponse.setRSC(
            Onem2m.ResponseStatusCode.CONTENTS_UNACCEPTABLE,
            "CONTENT_FORMAT(" + RequestPrimitive.CONTENT_FORMAT + ") not accepted (" + cf + ")");
        return;
      }
    }

    // validate result content options for retrieve
    String rc = getPrimitive(RequestPrimitive.RESULT_CONTENT);
    if (rc != null) {
      if (!(rc.contentEquals(Onem2m.ResultContent.ATTRIBUTES)
          || rc.contentEquals(Onem2m.ResultContent.ATTRIBUTES_CHILD_RESOURCES)
          || rc.contentEquals(Onem2m.ResultContent.CHILD_RESOURCE_REFS)
          || rc.contentEquals(Onem2m.ResultContent.ATTRIBUTES_CHILD_RESOURCE_REFS))) {
        onem2mResponse.setRSC(
            Onem2m.ResponseStatusCode.CONTENTS_UNACCEPTABLE,
            "RESULT_CONTENT(" + RequestPrimitive.RESULT_CONTENT + ") not accepted (" + rc + ")");
        return;
      }
    }

    // return hierarchical address by default if not specified
    String drt = getPrimitive(RequestPrimitive.DISCOVERY_RESULT_TYPE);
    if (drt == null) {
      setPrimitive(RequestPrimitive.DISCOVERY_RESULT_TYPE, Onem2m.DiscoveryResultType.HIERARCHICAL);
    }

    // find the resource using the TO URI ...
    String to = this.getPrimitive(RequestPrimitive.TO);
    if (!Onem2mDb.getInstance().findResourceUsingURI(to, this, onem2mResponse)) {

      // check to see if an resource/attribute was specified
      if (!Onem2mDb.getInstance().findResourceUsingURIAndAttribute(to, this, onem2mResponse)) {

        onem2mResponse.setRSC(
            Onem2m.ResponseStatusCode.NOT_FOUND, "Resource target URI not found: " + to);
        return;
      }
      return;
    }

    // process the resource specific attributes
    ResourceContentProcessor.handleRetrieve(this, onem2mResponse);
    if (onem2mResponse.getPrimitive(ResponsePrimitive.RESPONSE_STATUS_CODE) != null) {
      return;
    }

    // return the data according to result content and filter criteria
    ResultContentProcessor.handleRetrieve(this, onem2mResponse);

    // TODO: see TS0004 6.8
    // if FOUND, and all went well, send back OK
    if (onem2mResponse.getPrimitive(ResponsePrimitive.RESPONSE_STATUS_CODE) == null) {
      onem2mResponse.setPrimitive(
          ResponsePrimitive.RESPONSE_STATUS_CODE, Onem2m.ResponseStatusCode.OK);
    }
  }