public OMElement serializeMediator(OMElement parent, Mediator m) {

    AggregateMediator mediator = null;
    if (!(m instanceof AggregateMediator)) {
      handleException("Unsupported mediator passed in for serialization : " + m.getType());
    } else {
      mediator = (AggregateMediator) m;
    }

    OMElement aggregator = fac.createOMElement("aggregate", synNS);
    saveTracingState(aggregator, mediator);

    assert mediator != null;
    if (mediator.getCorrelateExpression() != null) {
      OMElement corelateOn = fac.createOMElement("correlateOn", synNS);
      SynapseXPathSerializer.serializeXPath(
          mediator.getCorrelateExpression(), corelateOn, "expression");
      aggregator.addChild(corelateOn);
    }

    OMElement completeCond = fac.createOMElement("completeCondition", synNS);
    if (mediator.getCompletionTimeoutMillis() != 0) {
      completeCond.addAttribute(
          "timeout", Long.toString(mediator.getCompletionTimeoutMillis() / 1000), nullNS);
    }
    OMElement messageCount = fac.createOMElement("messageCount", synNS);
    if (mediator.getMinMessagesToComplete() != 0) {
      messageCount.addAttribute(
          "min", Integer.toString(mediator.getMinMessagesToComplete()), nullNS);
    }
    if (mediator.getMaxMessagesToComplete() != 0) {
      messageCount.addAttribute(
          "max", Integer.toString(mediator.getMaxMessagesToComplete()), nullNS);
    }
    completeCond.addChild(messageCount);
    aggregator.addChild(completeCond);

    OMElement onCompleteElem = fac.createOMElement("onComplete", synNS);
    if (mediator.getAggregationExpression() != null) {
      SynapseXPathSerializer.serializeXPath(
          mediator.getAggregationExpression(), onCompleteElem, "expression");
    }
    if (mediator.getOnCompleteSequenceRef() != null) {
      onCompleteElem.addAttribute("sequence", mediator.getOnCompleteSequenceRef(), nullNS);
    } else if (mediator.getOnCompleteSequence() != null) {
      new SequenceMediatorSerializer()
          .serializeChildren(onCompleteElem, mediator.getOnCompleteSequence().getList());
    }
    aggregator.addChild(onCompleteElem);

    if (parent != null) {
      parent.addChild(aggregator);
    }

    return aggregator;
  }
  public OMElement serializeSpecificMediator(Mediator m) {

    if (!(m instanceof RelayTransformerMediator)) {
      handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }

    RelayTransformerMediator mediator = (RelayTransformerMediator) m;
    OMElement relayTransformer = fac.createOMElement("relayTransformer", synNS);

    if (mediator.getXsltKey() != null) {
      // Serialize Value using ValueSerializer
      ValueSerializer keySerializer = new ValueSerializer();
      keySerializer.serializeValue(mediator.getXsltKey(), XMLConfigConstants.KEY, relayTransformer);
    } else {
      handleException("Invalid relayTransformer mediator. XSLT registry key is required");
    }
    saveTracingState(relayTransformer, mediator);

    if (mediator.getSource() != null) {

      SynapseXPathSerializer.serializeXPath(mediator.getSource(), relayTransformer, "source");
    }
    if (mediator.getTargetPropertyName() != null) {
      relayTransformer.addAttribute(
          fac.createOMAttribute("target", nullNS, mediator.getTargetPropertyName()));
    }
    if (mediator.getInputType() != null) {
      relayTransformer.addAttribute(
          fac.createOMAttribute("input", nullNS, mediator.getInputType()));
    }
    serializeProperties(relayTransformer, mediator.getProperties());
    List<MediatorProperty> features = mediator.getFeatures();
    if (!features.isEmpty()) {
      for (MediatorProperty mp : features) {
        OMElement prop = fac.createOMElement("feature", synNS, relayTransformer);
        if (mp.getName() != null) {
          prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
        } else {
          handleException("The Feature name is missing");
        }
        if (mp.getValue() != null) {
          prop.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));
        } else {
          handleException("The Feature value is missing");
        }
      }
    }
    serializeMediatorProperties(relayTransformer, mediator.getAttributes(), ATTRIBUTE_Q);

    ResourceMapSerializer.serializeResourceMap(relayTransformer, mediator.getResourceMap());

    return relayTransformer;
  }
  private OMElement createStatementParamElement(Statement.Parameter param) {
    OMElement paramElt =
        fac.createOMElement(AbstractDBMediatorFactory.PARAM_Q.getLocalPart(), synNS);

    if (param.getPropertyName() != null) {
      paramElt.addAttribute(fac.createOMAttribute("value", nullNS, param.getPropertyName()));
    }
    if (param.getXpath() != null) {
      SynapseXPathSerializer.serializeXPath(param.getXpath(), paramElt, "expression");
    }

    switch (param.getType()) {
      case Types.CHAR:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "CHAR"));
          break;
        }
      case Types.VARCHAR:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "VARCHAR"));
          break;
        }
      case Types.LONGVARCHAR:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "LONGVARCHAR"));
          break;
        }
      case Types.NUMERIC:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "NUMERIC"));
          break;
        }
      case Types.DECIMAL:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "DECIMAL"));
          break;
        }
      case Types.BIT:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "BIT"));
          break;
        }
      case Types.TINYINT:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "TINYINT"));
          break;
        }
      case Types.SMALLINT:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "SMALLINT"));
          break;
        }
      case Types.INTEGER:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "INTEGER"));
          break;
        }
      case Types.BIGINT:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "BIGINT"));
          break;
        }
      case Types.REAL:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "REAL"));
          break;
        }
      case Types.FLOAT:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "FLOAT"));
          break;
        }
      case Types.DOUBLE:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "DOUBLE"));
          break;
        }
      case Types.DATE:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "DATE"));
          break;
        }
      case Types.TIME:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "TIME"));
          break;
        }
      case Types.TIMESTAMP:
        {
          paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "TIMESTAMP"));
          break;
        }
      default:
        {
          throw new SynapseException("Unknown or unsupported JDBC type : " + param.getType());
        }
    }
    return paramElt;
  }