Ejemplo n.º 1
0
  @Override
  public void perform(Element originalElement, Element patchElement, Element outputParentElement)
      throws AbstractXmlMergeException {

    logger.fine("Merging: " + originalElement + " (original) and " + patchElement + " (patch)");

    Mapper mapper = (Mapper) m_mapperFactory.getOperation(originalElement, patchElement);

    if (originalElement == null) {
      outputParentElement.addContent(mapper.map(patchElement));
    } else if (patchElement == null) {
      outputParentElement.addContent((Content) originalElement.clone());
    } else {

      Element workingElement =
          new Element(
              originalElement.getName(),
              originalElement.getNamespacePrefix(),
              originalElement.getNamespaceURI());
      addAttributes(workingElement, originalElement);

      logger.fine("Adding " + workingElement);
      outputParentElement.addContent(workingElement);

      doIt(workingElement, originalElement, patchElement);
    }
  }
Ejemplo n.º 2
0
  /**
   * Applies the action which performs the merge between two source elements.
   *
   * @param workingParent Output parent element
   * @param originalElement Original element
   * @param patchElement Patch element
   * @throws AbstractXmlMergeException if an error occurred during the merge
   */
  private void applyAction(Element workingParent, Element originalElement, Element patchElement)
      throws AbstractXmlMergeException {
    Action action = (Action) m_actionFactory.getOperation(originalElement, patchElement);
    Mapper mapper = (Mapper) m_mapperFactory.getOperation(originalElement, patchElement);

    // Propagate the factories to deeper merge actions
    // TODO: find a way to make it cleaner
    if (action instanceof MergeAction) {
      MergeAction mergeAction = (MergeAction) action;
      mergeAction.setActionFactory(m_actionFactory);
      mergeAction.setMapperFactory(m_mapperFactory);
      mergeAction.setMatcherFactory(m_matcherFactory);
    }

    action.perform(originalElement, mapper.map(patchElement), workingParent);
  }