01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.xml.export;
19:
20: import java.io.IOException;
21: import java.io.Writer;
22:
23: import de.finix.contelligent.Type;
24: import de.finix.contelligent.logging.LoggingService;
25:
26: /**
27: * Writes an XML representation of one or multiple {@link Type types} to a given
28: * Writer or into a local file-system.
29: */
30: final public class TypeXMLWriter {
31:
32: final static org.apache.log4j.Logger log = LoggingService
33: .getLogger(TypeXMLWriter.class);
34:
35: final private TypeXMLPolicy policy;
36:
37: public TypeXMLWriter(TypeXMLPolicy policy) {
38: this .policy = policy;
39: }
40:
41: public TypeXMLWriter() {
42: this (new DefaultTypeXMLPolicy());
43: }
44:
45: public void write(Type[] types, Writer writer, boolean ommitHeader)
46: throws IOException {
47: if (!ommitHeader)
48: policy.writeXMLHeader(writer);
49: for (int i = 0; i < types.length; i++)
50: policy.writeType(types[i], writer);
51: if (!ommitHeader)
52: policy.writeXMLFooter(writer);
53: writer.flush();
54: }
55:
56: public void write(Type type, Writer writer, boolean ommitHeader)
57: throws IOException {
58: if (!ommitHeader)
59: policy.writeXMLHeader(writer);
60: policy.writeType(type, writer);
61: if (!ommitHeader)
62: policy.writeXMLFooter(writer);
63: writer.flush();
64: }
65:
66: }
|