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: package testengine1;
030:
031: import org.w3c.dom.Document;
032:
033: import java.io.StringReader;
034:
035: import javax.jbi.messaging.NormalizedMessage;
036:
037: import javax.xml.parsers.DocumentBuilder;
038: import javax.xml.parsers.DocumentBuilderFactory;
039: import javax.xml.transform.dom.DOMSource;
040: import javax.xml.transform.stream.StreamSource;
041:
042: /**
043: * Simple utility class used to load a dummy DOM document.
044: *
045: * @author Sun Microsystems, Inc.
046: */
047: public class Payload {
048: /**
049: *
050: */
051: public static String mDefaultPath;
052:
053: /**
054: *
055: */
056: private static Document mDefaultDoc;
057:
058: /**
059: *
060: */
061: private static DocumentBuilder mBuilder;
062:
063: /**
064: *
065: *
066: * @param msg NOT YET DOCUMENTED
067: *
068: * @throws Exception
069: */
070: public static synchronized void setBadPayload(NormalizedMessage msg)
071: throws Exception {
072: try {
073: StringReader reader = new StringReader(
074: "<xmlstart>aim not a good xml <ddd>");
075: msg.setContent(new StreamSource(reader));
076: } catch (Exception e) {
077: e.printStackTrace();
078: throw e;
079: }
080: }
081:
082: /**
083: *
084: *
085: * @param msg NOT YET DOCUMENTED
086: *
087: * @throws Exception
088: */
089: public static synchronized void setPayload(NormalizedMessage msg)
090: throws Exception {
091: if (mBuilder == null) {
092: init();
093: }
094:
095: msg.setContent(new DOMSource(mDefaultDoc));
096: }
097:
098: /**
099: *
100: *
101: * @throws Exception
102: */
103: private static void init() throws Exception {
104: DocumentBuilderFactory factory;
105:
106: factory = DocumentBuilderFactory.newInstance();
107: factory.setNamespaceAware(true);
108: mBuilder = factory.newDocumentBuilder();
109: mDefaultDoc = mBuilder.parse(mDefaultPath);
110: }
111: }
|