01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.databinding.source;
19:
20: import java.util.Collection;
21: import java.util.logging.Logger;
22:
23: import javax.xml.stream.XMLStreamException;
24: import javax.xml.stream.XMLStreamReader;
25: import javax.xml.stream.XMLStreamWriter;
26: import javax.xml.transform.Source;
27: import javax.xml.transform.dom.DOMSource;
28: import javax.xml.validation.Schema;
29:
30: import org.w3c.dom.Element;
31: import org.w3c.dom.Node;
32:
33: import org.apache.cxf.common.i18n.Message;
34: import org.apache.cxf.common.logging.LogUtils;
35: import org.apache.cxf.databinding.DataWriter;
36: import org.apache.cxf.interceptor.Fault;
37: import org.apache.cxf.message.Attachment;
38: import org.apache.cxf.service.model.MessagePartInfo;
39: import org.apache.cxf.staxutils.StaxUtils;
40: import org.apache.cxf.staxutils.W3CDOMStreamWriter;
41:
42: public class NodeDataWriter implements DataWriter<Node> {
43: private static final Logger LOG = LogUtils
44: .getL7dLogger(NodeDataWriter.class);
45:
46: public void write(Object obj, MessagePartInfo part, Node output) {
47: write(obj, output);
48: }
49:
50: public void write(Object obj, Node n) {
51: try {
52: Source s = (Source) obj;
53: if (s instanceof DOMSource
54: && ((DOMSource) s).getNode() == null) {
55: return;
56: }
57:
58: XMLStreamWriter writer = new W3CDOMStreamWriter((Element) n);
59: XMLStreamReader reader = StaxUtils.createXMLStreamReader(s);
60: StaxUtils.copy(reader, writer);
61: reader.close();
62: } catch (XMLStreamException e) {
63: throw new Fault(new Message("COULD_NOT_READ_XML_STREAM",
64: LOG), e);
65: }
66: }
67:
68: public void setSchema(Schema s) {
69: }
70:
71: public void setAttachments(Collection<Attachment> attachments) {
72:
73: }
74: }
|