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.aegis.type.xml;
19:
20: import javax.xml.stream.XMLStreamException;
21: import javax.xml.stream.XMLStreamReader;
22:
23: import org.apache.cxf.aegis.Context;
24: import org.apache.cxf.aegis.DatabindingException;
25: import org.apache.cxf.aegis.type.Type;
26: import org.apache.cxf.aegis.xml.MessageReader;
27: import org.apache.cxf.aegis.xml.MessageWriter;
28: import org.apache.cxf.aegis.xml.stax.ElementReader;
29: import org.apache.cxf.aegis.xml.stax.ElementWriter;
30: import org.apache.cxf.staxutils.StaxUtils;
31:
32: /**
33: * Reads and writes <code>org.w3c.dom.Document</code> types.
34: *
35: * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
36: */
37: public class XMLStreamReaderType extends Type {
38: public XMLStreamReaderType() {
39: setWriteOuter(false);
40: }
41:
42: @Override
43: public Object readObject(MessageReader mreader, Context context)
44: throws DatabindingException {
45: return ((ElementReader) mreader).getXMLStreamReader();
46: }
47:
48: @Override
49: public void writeObject(Object object, MessageWriter writer,
50: Context context) throws DatabindingException {
51: XMLStreamReader reader = (XMLStreamReader) object;
52:
53: try {
54: StaxUtils.copy(reader, ((ElementWriter) writer)
55: .getXMLStreamWriter());
56: reader.close();
57: } catch (XMLStreamException e) {
58: throw new DatabindingException("Could not write xml.", e);
59: }
60: }
61: }
|