01: package de.schlund.pfixcore.oxm.impl.serializers;
02:
03: import de.schlund.pfixcore.oxm.impl.ComplexTypeSerializer;
04: import de.schlund.pfixcore.oxm.impl.SerializationContext;
05: import de.schlund.pfixcore.oxm.impl.SerializationException;
06: import de.schlund.pfixcore.oxm.impl.XMLWriter;
07:
08: /**
09: * XMLFragmentSerializer
10: *
11: * Treats a string as an XML fragement and inserts it
12: * into the document.
13: *
14: * @author Stephan Schmidt <schst@stubbles.net>
15: */
16: public class XMLFragmentSerializer implements ComplexTypeSerializer {
17:
18: public XMLFragmentSerializer() {
19: }
20:
21: public void serialize(Object obj, SerializationContext context,
22: XMLWriter writer) throws SerializationException {
23: if (!(obj instanceof String)) {
24: throw new SerializationException("Type not supported: "
25: + obj.getClass().getName());
26: }
27: String fragment = (String) obj;
28: try {
29: writer.writeFragment(fragment);
30: } catch (RuntimeException e) {
31: throw new SecurityException("Fragment " + fragment
32: + " could not be written to the document.", e
33: .getCause());
34: }
35: }
36: }
|