/** {@inheritDoc} */
  public void transform(TransformationInfo info, EsbNode subject) throws TransformerException {
    // Check subject.
    Assert.isTrue(subject instanceof EndPoint, "Invalid subject");
    DefaultEndPoint visualEP = (DefaultEndPoint) subject;
    DefaultEndpoint synapseEP = create(visualEP, visualEP.getEndPointName());
    setEndpointToSendCallOrProxy(info, visualEP, synapseEP);

    if (!info.isEndPointFound) {
      info.isEndPointFound = true;
      info.firstEndPoint = visualEP;
    }

    if (visualEP.getOutputConnector() != null) {
      if (visualEP.getOutputConnector().getOutgoingLink() != null) {
        InputConnector nextInputConnector =
            visualEP.getOutputConnector().getOutgoingLink().getTarget();
        if ((!(nextInputConnector instanceof SequenceInputConnector))
            || ((((Sequence) nextInputConnector.eContainer())
                        .getOutputConnector()
                        .get(0)
                        .getOutgoingLink()
                    != null)
                && (!(((Sequence) nextInputConnector.eContainer())
                        .getOutputConnector()
                        .get(0)
                        .getOutgoingLink()
                        .getTarget()
                        .eContainer()
                    instanceof EndPoint)))) {
          info.setParentSequence(info.getOriginOutSequence());
          info.setTraversalDirection(TransformationInfo.TRAVERSAL_DIRECTION_OUT);
        } else if (visualEP.getInputConnector().getIncomingLinks().get(0).getSource().eContainer()
            instanceof Sequence) {
          info.setParentSequence(info.getCurrentReferredSequence());
        }
      }
    }

    List<EsbNode> transformedMediators = info.getTransformedMediators();
    if (visualEP.getOutputConnector() != null
        && visualEP.getOutputConnector().getOutgoingLink() != null) {
      EsbNode nextElement =
          (EsbNode) visualEP.getOutputConnector().getOutgoingLink().getTarget().eContainer();
      if (transformedMediators.contains(nextElement)) {
        return;
      }
      transformedMediators.add(nextElement);
    }

    // Transform endpoint output data flow.
    // TODO: find out why this was commented out.
    // might want to check if the flow is connected back to initial proxy
    // service
    doTransform(info, visualEP.getOutputConnector());
  }
 protected CallMediator getCallMediator(TransformationInfo info) {
   CallMediator callMediator = null;
   if (info.getPreviouNode() instanceof org.wso2.developerstudio.eclipse.gmf.esb.CallMediator) {
     int size = info.getParentSequence().getList().size();
     if (size > 0) {
       Mediator lastObj = info.getParentSequence().getList().get(size - 1);
       if (lastObj instanceof CallMediator) {
         callMediator = (CallMediator) lastObj;
       }
     }
   } else if (info.getPreviouNode() instanceof org.wso2.developerstudio.eclipse.gmf.esb.Sequence) {
     callMediator = null;
   } else {
     // sendMediator = new SendMediator();
     // info.getParentSequence().addChild(sendMediator);
   }
   return callMediator;
 }
 public void transform(TransformationInfo information, EsbNode subject)
     throws TransformerException {
   try {
     information.getParentSequence().addChild(createValidateMediator(subject, information));
     doTransform(information, ((ValidateMediator) subject).getOutputConnector());
   } catch (JaxenException e) {
     throw new TransformerException(e);
   }
 }
  protected void setEndpointToSendCallOrProxy(
      TransformationInfo info, EndPoint visualEndPoint, Endpoint synapseEP) {
    SendMediator sendMediator = getSendMediator(info);
    CallMediator callMediator = getCallMediator(info);

    if (visualEndPoint.isInLine()) {
      info.getCurrentProxy().setTargetInLineEndpoint(synapseEP);
    } else {
      if (sendMediator != null) {
        sendMediator.setEndpoint(synapseEP);
      } else if (callMediator != null) {
        callMediator.setEndpoint(synapseEP);
      }
    }
  }
  /**
   * transform Endpoint Output flow
   *
   * @param info
   */
  protected void transformEndpointOutflow(TransformationInfo info) {
    if (!info.isOutputPathSet) {
      if (info.firstEndPoint instanceof FailoverEndPoint) {
        try {
          FailoverEndPointWestOutputConnector westOutputConnector =
              ((FailoverEndPoint) info.firstEndPoint).getWestOutputConnector();

          List<EsbNode> transformedMediators = info.getTransformedMediators();
          if (westOutputConnector != null) {
            EsbNode nextElement = getTargetContainer(westOutputConnector);
            if (nextElement != null) {
              if (!transformedMediators.contains(nextElement)) {
                doTransform(info, westOutputConnector);
                transformedMediators.add(nextElement);
              }
            }
          }

        } catch (Exception e) {
          log.warn("Error while executing outflow  serialization", e);
        }
      } else if (info.firstEndPoint instanceof LoadBalanceEndPoint) {
        try {
          LoadBalanceEndPointWestOutputConnector westOutputConnector =
              ((LoadBalanceEndPoint) info.firstEndPoint).getWestOutputConnector();
          List<EsbNode> transformedMediators = info.getTransformedMediators();
          if (westOutputConnector != null) {
            EsbNode nextElement = getTargetContainer(westOutputConnector);
            if (nextElement != null) {
              if (!transformedMediators.contains(nextElement)) {
                doTransform(info, westOutputConnector);
                transformedMediators.add(nextElement);
              }
            }
          }
        } catch (Exception e) {
          log.warn("Error while executing outflow  serialization", e);
        }
      } else if (info.firstEndPoint instanceof RecipientListEndPoint) {
        try {
          RecipientListEndPointWestOutputConnector westOutputConnector =
              ((RecipientListEndPoint) info.firstEndPoint).getWestOutputConnector();

          List<EsbNode> transformedMediators = info.getTransformedMediators();
          if (westOutputConnector != null) {
            EsbNode nextElement = getTargetContainer(westOutputConnector);
            if (nextElement != null) {
              if (!transformedMediators.contains(nextElement)) {
                doTransform(info, westOutputConnector);
                transformedMediators.add(nextElement);
              }
            }
          }

        } catch (Exception e) {
          log.warn("Error while executing outflow  serialization", e);
        }
      }
      info.isOutputPathSet = true;
    }
  }
  private org.apache.synapse.mediators.builtin.ValidateMediator createValidateMediator(
      EsbNode subject, TransformationInfo information) throws TransformerException, JaxenException {

    /*
     * Check subject.
     */
    Assert.isTrue(subject instanceof ValidateMediator, "Invalid subject.");
    ValidateMediator visualValidateMediator = (ValidateMediator) subject;
    /*
     * Configure Validate mediator.
     */

    org.apache.synapse.mediators.builtin.ValidateMediator validateMediator =
        new org.apache.synapse.mediators.builtin.ValidateMediator();
    setCommonProperties(validateMediator, visualValidateMediator);

    NamespacedProperty sourceXPath = visualValidateMediator.getSourceXpath();
    if (sourceXPath.getPropertyValue() != null && !sourceXPath.getPropertyValue().equals("")) {
      SynapseXPath synapseXPath = new SynapseXPath(sourceXPath.getPropertyValue());
      for (Entry<String, String> entry : sourceXPath.getNamespaces().entrySet()) {
        synapseXPath.addNamespace(entry.getKey(), entry.getValue());
      }
      validateMediator.setSource(synapseXPath);
    }

    List<Value> valueList = new ArrayList<Value>();
    for (ValidateSchema schema : visualValidateMediator.getSchemas()) {

      if (schema.getValidateSchemaKeyType().getLiteral().equals(KeyType.STATIC.getLiteral())) {

        if (schema.getValidateStaticSchemaKey() != null
            && schema.getValidateStaticSchemaKey().getKeyValue() != null) {
          Value val = new Value(schema.getValidateStaticSchemaKey().getKeyValue());
          valueList.add(val);
        }

      } else {

        NamespacedProperty dynamicSchemaKey = schema.getValidateDynamicSchemaKey();
        if (dynamicSchemaKey != null && dynamicSchemaKey.getPropertyValue() != null) {
          SynapseXPath xpath = new SynapseXPath(dynamicSchemaKey.getPropertyValue());
          for (Entry<String, String> entry : dynamicSchemaKey.getNamespaces().entrySet()) {
            xpath.addNamespace(entry.getKey(), entry.getValue());
          }
          Value val = new Value(xpath);
          valueList.add(val);
        }
      }
    }
    validateMediator.setSchemaKeys(valueList);

    // ListMediator onFailMediatorList = new AnonymousListMediator();
    SequenceMediator onFailMediatorList = new SequenceMediator();
    TransformationInfo newOnFailInfo = new TransformationInfo();
    newOnFailInfo.setTraversalDirection(information.getTraversalDirection());
    newOnFailInfo.setSynapseConfiguration(information.getSynapseConfiguration());
    newOnFailInfo.setOriginInSequence(information.getOriginInSequence());
    newOnFailInfo.setOriginOutSequence(information.getOriginOutSequence());
    newOnFailInfo.setCurrentProxy(information.getCurrentProxy());
    newOnFailInfo.setParentSequence(onFailMediatorList);
    doTransform(newOnFailInfo, visualValidateMediator.getOnFailOutputConnector());
    validateMediator.addAll(onFailMediatorList.getList());

    for (ValidateFeature feature : visualValidateMediator.getFeatures()) {
      try {
        validateMediator.addFeature(feature.getFeatureName(), feature.isFeatureEnabled());
      } catch (Exception e) {
        log.error(e);
      }
    }

    if (!visualValidateMediator.getResources().isEmpty()) {

      ResourceMap rMap = new ResourceMap();

      for (ValidateResource resource : visualValidateMediator.getResources()) {

        if (resource.getLocation() != null && resource.getKey() != null) {

          rMap.addResource(resource.getLocation(), resource.getKey().getKeyValue());
        }
      }

      validateMediator.setResourceMap(rMap);
    }

    return validateMediator;
  }
  public void transform(TransformationInfo information, EsbNode subject) throws Exception {
    information.getParentSequence().addChild(createValidateMediator(subject, information));

    doTransform(information, ((ValidateMediator) subject).getOutputConnector());
  }
  public void transform(TransformationInfo information, EsbNode subject) throws Exception {
    org.apache.synapse.mediators.builtin.CallMediator callMediator = createCallMediator(subject);
    if (callMediator != null) {
      information.getParentSequence().addChild(callMediator);
    }

    TransformationInfo tmpInformation = new TransformationInfo();
    tmpInformation.setParentSequence(information.getParentSequence());
    tmpInformation.setTraversalDirection(information.getTraversalDirection());
    tmpInformation.setOriginInSequence(information.getOriginInSequence());
    tmpInformation.setOriginOutSequence(information.getOriginOutSequence());
    tmpInformation.setPreviousNode(information.getPreviouNode());
    tmpInformation.setSynapseConfiguration(information.getSynapseConfiguration());
    tmpInformation.setCurrentAPI(information.getCurrentAPI());
    tmpInformation.setCurrentProxy(information.getCurrentProxy());
    tmpInformation.setCurrentReferredSequence(information.getCurrentReferredSequence());
    tmpInformation.setMainSequence(information.getMainSequence());
    if (((CallMediator) subject).getEndpointType() == CallMediatorEndpointType.INLINE) {
      doTransform(
          tmpInformation,
          ((CallMediator) subject)
              .getEndpointOutputConnector()); // to transform the mediators inside the mediator
    }
    doTransform(
        information, ((CallMediator) subject).getOutputConnector()); // continue in normal flow
  }