001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)Payload.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: import org.w3c.dom.Document;
030:
031: import java.io.File;
032: import java.io.StringReader;
033:
034: import javax.jbi.messaging.NormalizedMessage;
035:
036: import javax.xml.parsers.DocumentBuilder;
037: import javax.xml.parsers.DocumentBuilderFactory;
038: import javax.xml.transform.dom.DOMSource;
039: import javax.xml.transform.stream.StreamSource;
040:
041: /**
042: * Simple utility class used to load a dummy DOM document.
043: *
044: * @author Ramesh
045: */
046: public class Payload {
047: /**
048: *
049: */
050: public static String mCSVFileName;
051:
052: /**
053: *
054: */
055: public static String mXMLFile;
056:
057: /**
058: *
059: */
060: private static Document mXMLDoc;
061:
062: /**
063: *
064: */
065: private static DocumentBuilder mBuilder;
066:
067: /**
068: *
069: *
070: * @param msg NOT YET DOCUMENTED
071: *
072: * @throws Exception
073: */
074: public static synchronized void setBadPayload(NormalizedMessage msg)
075: throws Exception {
076: try {
077: StringReader reader = new StringReader(
078: "<xmlstart>aim not a good xml <ddd>");
079: msg.setContent(new StreamSource(reader));
080: } catch (Exception e) {
081: e.printStackTrace();
082: throw e;
083: }
084: }
085:
086: /**
087: *
088: *
089: * @param msg NOT YET DOCUMENTED
090: *
091: * @throws Exception
092: */
093: public static synchronized void setCSVPayload(NormalizedMessage msg)
094: throws Exception {
095: try {
096: msg.setContent(new StreamSource(new File(mCSVFileName)));
097: } catch (Exception e) {
098: e.printStackTrace();
099: throw e;
100: }
101: }
102:
103: /**
104: *
105: *
106: * @param msg NOT YET DOCUMENTED
107: *
108: * @throws Exception
109: */
110: public static synchronized void setXMLPayload(NormalizedMessage msg)
111: throws Exception {
112: if (mBuilder == null) {
113: init();
114: }
115:
116: msg.setContent(new DOMSource(mXMLDoc));
117: }
118:
119: /**
120: *
121: *
122: * @throws Exception
123: */
124: private static void init() throws Exception {
125: DocumentBuilderFactory factory;
126:
127: factory = DocumentBuilderFactory.newInstance();
128: factory.setNamespaceAware(true);
129: mBuilder = factory.newDocumentBuilder();
130: mXMLDoc = mBuilder.parse(mXMLFile);
131: }
132: }
|