Package com.sap.aii.mapping.api

API for Java mapping programs.

See:
          Description

Interface Summary
MappingTrace A mapping can use an instance of MappingTrace to add messages to the trace.
StreamTransformation Each XI Java mapping program must implement this interface.
StreamTransformationConstants This interface contains constants that can be used in a java mapping to access runtime parameters.
 

Class Summary
AbstractTrace A mapping can use an instance of AbstractTrace to add messages to the trace.
DynamicConfiguration A DynamicConfiguration is a map containing adapter specific message attributes.
DynamicConfigurationKey A DynamicConfigurationKey denotes an adapter specific message attribute.
 

Exception Summary
StreamTransformationException This exception can be thrown by StreamTransformation.execute(java.io.InputStream, java.io.OutputStream ) to indicate problem during mapping.
 

Package com.sap.aii.mapping.api Description

API for Java mapping programs. The API works with an InputStream that is mapped to an OutputStream. Depending on the use case, application developers can choose additional APIs to do the actual mapping (for example SAXParser or DocumentBuilder to parse the InputStream). Additionally the mapping API provides classes to map a special header of the XI message that allows adapters to transport adapter specific information (classes DynamicConfiguration and DynamicConfigurationKey).

Although following example just copies the input payload to the output payload, it essentially shows how to use the mapping API. For more information see the details in the corresponding interfaces and classes.

Example:

package exampleMapping;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;

/**
 * Copy XML with a DOM.
 */
public class DomCopy implements StreamTransformation {

  private MappingTrace trace;

  /**
   * Constructor for DomCopy.
   */
  public DomCopy() {
    super();
  }

  /**
   * @see com.sap.aii.mapping.api.StreamTransformation#setParameter(Map)
   */
  public void setParameter(Map param) {
    trace = (MappingTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
  }

  /**
   * @see com.sap.aii.mapping.api.StreamTransformation#execute(InputStream,
   *      OutputStream)
   */
  public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
    try {
      // read XML
      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      Document xml = documentBuilder.parse(in);
            
      // write XML
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      Result result = new StreamResult(out);
      Source domSource = new DOMSource(xml);
      transformer.transform(domSource, result);
    } catch (ParserConfigurationException e) {
      trace.addWarning(e.getMessage());
      throw new StreamTransformationException("Can not create DocumentBuilder.", e);
    } catch (SAXException e) {
      trace.addWarning(e.getMessage());
      throw new StreamTransformationException("Can not read XML.", e);
    } catch (IOException e) {
      trace.addWarning(e.getMessage());
      throw new StreamTransformationException("Can not read XML.", e);
    } catch (TransformerConfigurationException e) {
      trace.addWarning(e.getMessage());
      throw new StreamTransformationException("Can not create Transformer.", e);
    } catch (TransformerException e) {
      trace.addWarning(e.getMessage());
      throw new StreamTransformationException("Can not write XML.", e);
    }
  }
}



Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.