Ejemplo n.º 1
0
  private void processKeyElement(OMElement keyElement, BAMStreamConfiguration streamConfiguration) {
    BAMKey bamKey;
    String name;
    BAMKey.BAMKeyType type;
    String variable;
    String expression;
    String part = null;
    String query = null;

    OMAttribute nameAttribute = keyElement.getAttribute(new QName("name"));
    if (nameAttribute == null || "".equals(nameAttribute.getAttributeValue())) {
      String errMsg =
          "name attribute of Key element cannot be null for BAM server "
              + "profile: "
              + profileLocation;
      handleError(errMsg);
    }
    name = nameAttribute.getAttributeValue();

    OMAttribute typeAttribute = keyElement.getAttribute(new QName("type"));
    if (typeAttribute == null || "".equals(typeAttribute.getAttributeValue())) {
      type = BAMKey.BAMKeyType.PAYLOAD;
      log.debug(
          "type attribute of Key element: "
              + name
              + " is not available. "
              + "Type is default to payload");
    }
    type = BAMKey.BAMKeyType.valueOf(typeAttribute.getAttributeType());

    OMElement fromElement =
        keyElement.getFirstChildWithName(new QName(BPELConstants.BAM_SERVER_PROFILE_NS, "From"));
    if (fromElement == null) {
      String errMsg =
          "From element not found for Key element: "
              + name
              + " for BAM server "
              + "profile: "
              + profileLocation;
      handleError(errMsg);
    }

    OMAttribute variableAttribute = fromElement.getAttribute(new QName("variable"));
    if (variableAttribute != null && !"".equals(variableAttribute.getAttributeValue())) {
      variable = variableAttribute.getAttributeValue();

      OMAttribute partAttribute = fromElement.getAttribute(new QName("part"));
      if (partAttribute != null) {
        part = partAttribute.getAttributeValue();
      }

      OMElement queryElement =
          fromElement.getFirstChildWithName(
              new QName(BPELConstants.BAM_SERVER_PROFILE_NS, "Query"));
      if (queryElement == null || "".equals(queryElement.getText())) {
        query = queryElement.getText();
      }
      bamKey = new BAMKey(name, variable, part, query, type);
    } else {
      if (fromElement.getText() == null || "".equals(fromElement.getText())) {
        String errMsg =
            "Variable name or XPath expression not found for From of Key: "
                + name
                + " for BAM server profile: "
                + profileLocation;
        handleError(errMsg);
      }
      expression = fromElement.getText().trim();
      bamKey = new BAMKey(name, type);
      bamKey.setExpression(expression);
    }

    switch (bamKey.getType()) {
      case PAYLOAD:
        streamConfiguration.addPayloadBAMKey(bamKey);
        break;
      case CORRELATION:
        streamConfiguration.addCorrelationBAMKey(bamKey);
        break;
      case META:
        streamConfiguration.addMetaBAMKey(bamKey);
        break;
      default:
        String errMsg =
            "Unknown BAM key type: "
                + type
                + " with BAM key name: "
                + bamKey.getName()
                + " in stream: "
                + streamConfiguration.getName();
        handleError(errMsg);
    }
  }