01: /**
02: *
03: */package com.bostechcorp.cbesb.runtime.parser.util;
04:
05: import java.io.OutputStream;
06:
07: import org.w3c.dom.Document;
08:
09: import com.bostechcorp.cbesb.common.mdl.IMDLDocument;
10: import com.bostechcorp.cbesb.common.mdl.IMessageDefinition;
11: import com.bostechcorp.cbesb.common.mdl.util.FormatDefUtil;
12: import com.bostechcorp.cbesb.common.runtime.CbesbException;
13: import com.bostechcorp.cbesb.runtime.parser.impl.LegacyDataSerializer;
14: import com.bostechcorp.cbesb.runtime.parser.impl.Hl7Serializer;
15: import com.bostechcorp.cbesb.runtime.parser.impl.X12Serializer;
16:
17: /**
18: * @author mpreston
19: *
20: */
21: public class SerializerUtil {
22:
23: private char x12SegmentTerminator = 0;
24: private char x12FieldSeparator = 0;
25: private char x12CompositeSeparator = 0;
26:
27: /**
28: * @return the x12CompositeSeparator
29: */
30: public char getX12CompositeSeparator() {
31: return x12CompositeSeparator;
32: }
33:
34: /**
35: * @param compositeSeparator the x12CompositeSeparator to set
36: */
37: public void setX12CompositeSeparator(char compositeSeparator) {
38: x12CompositeSeparator = compositeSeparator;
39: }
40:
41: /**
42: * @return the x12FieldSeparator
43: */
44: public char getX12FieldSeparator() {
45: return x12FieldSeparator;
46: }
47:
48: /**
49: * @param fieldSeparator the x12FieldSeparator to set
50: */
51: public void setX12FieldSeparator(char fieldSeparator) {
52: x12FieldSeparator = fieldSeparator;
53: }
54:
55: /**
56: * @return the x12SegmentTerminator
57: */
58: public char getX12SegmentTerminator() {
59: return x12SegmentTerminator;
60: }
61:
62: /**
63: * @param segmentTerminator the x12SegmentTerminator to set
64: */
65: public void setX12SegmentTerminator(char segmentTerminator) {
66: x12SegmentTerminator = segmentTerminator;
67: }
68:
69: public void serialize(OutputStream os, Document doc, String format,
70: String formatSpec, String rootName) throws CbesbException {
71: IMDLDocument mdlDoc = FormatDefUtil.getMdlDocFromFormatSpec(
72: format, formatSpec);
73: IMessageDefinition msgDef = mdlDoc.getMessageDefinition(mdlDoc
74: .getTargetNamespace(), rootName);
75:
76: LegacyDataSerializer serializer;
77: if (format.equals("x12")) {
78: serializer = new X12Serializer();
79: ((X12Serializer) serializer).setMdlDoc(mdlDoc);
80: ((X12Serializer) serializer)
81: .setSegmentTerminator(x12SegmentTerminator);
82: ((X12Serializer) serializer)
83: .setFieldSeparator(x12FieldSeparator);
84: ((X12Serializer) serializer)
85: .setCompositeSeparator(x12CompositeSeparator);
86:
87: } else if (format.equals("hl7")) {
88: serializer = new Hl7Serializer();
89: ((Hl7Serializer) serializer).setMdlDoc(mdlDoc);
90:
91: } else {
92: serializer = new LegacyDataSerializer();
93: }
94:
95: serializer.serialize(doc, msgDef, os);
96: }
97:
98: }
|