01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *
22: * $Id: LegacyDataSerializer.java 3622 2006-12-12 03:04:08Z lzheng $
23: */
24: package com.bostechcorp.cbesb.runtime.parser.impl;
25:
26: import java.io.OutputStream;
27:
28: import org.w3c.dom.Document;
29: import org.w3c.dom.Element;
30:
31: import com.bostechcorp.cbesb.common.mdl.IMessageDefinition;
32: import com.bostechcorp.cbesb.runtime.parser.DataEscapingUtil;
33: import com.bostechcorp.cbesb.runtime.parser.ElementSerializerFactory;
34: import com.bostechcorp.cbesb.runtime.parser.IElementSerializer;
35: import com.bostechcorp.cbesb.runtime.parser.ParserException;
36:
37: /**
38: * The LegacyDataSerializer class is the main interface to serialize a DOM
39: * Document into a non-xml message. All other classes in this API are used by
40: * this class to provide the different serializing functions. The class that
41: * instantiates the LegacyDataSerializer should also have an instance of
42: * MDLDocumentFactory to load the MessageDefinition object used to serialize the
43: * data. Basic flow of the serialize method: 1. Call ElementSerializerFactory's
44: * getElementSerializer method with the MessageDefinition to get the appropriate
45: * ElementSerializer for the root element of the message. 2. Call the
46: * ElementSerializer's serialize method passing in the root element of the DOM
47: * Document, the MessageDefinition and OutputStream.
48: *
49: */
50: public class LegacyDataSerializer {
51:
52: public void serialize(Document doc,
53: IMessageDefinition messageDefinition, OutputStream os)
54: throws ParserException {
55: IElementSerializer serializer = ElementSerializerFactory
56: .instance().getElementSerializer(messageDefinition);
57: Element root = doc.getDocumentElement();
58: DataEscapingUtil dataEscapingUtil = new DataEscapingUtil();
59: serializer.serialize(root, messageDefinition, dataEscapingUtil,
60: os);
61: }
62: }
|