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: */
19: package org.apache.axis2.jaxws.message.databinding.impl;
20:
21: import org.apache.axiom.om.OMElement;
22: import org.apache.axiom.om.util.StAXUtils;
23: import org.apache.axis2.jaxws.message.databinding.XMLStringBlock;
24: import org.apache.axis2.jaxws.message.factory.BlockFactory;
25: import org.apache.axis2.jaxws.message.impl.BlockImpl;
26: import org.apache.axis2.jaxws.message.util.Reader2Writer;
27:
28: import javax.xml.namespace.QName;
29: import javax.xml.stream.XMLStreamException;
30: import javax.xml.stream.XMLStreamReader;
31: import javax.xml.stream.XMLStreamWriter;
32: import java.io.StringReader;
33:
34: /**
35: * XMLStringBlock
36: * <p/>
37: * Block containing a business object that is a String of xml text
38: */
39: public class XMLStringBlockImpl extends BlockImpl implements
40: XMLStringBlock {
41:
42: /**
43: * Constructor called from factory
44: *
45: * @param busObject
46: * @param qName
47: * @param factory
48: */
49: XMLStringBlockImpl(String busObject, QName qName,
50: BlockFactory factory) {
51: super (busObject, null, qName, factory);
52: }
53:
54: /**
55: * Constructor called from factory
56: *
57: * @param reader
58: * @param qName
59: * @param factory
60: */
61: public XMLStringBlockImpl(OMElement omElement, QName qName,
62: BlockFactory factory) {
63: super (omElement, null, qName, factory);
64: }
65:
66: @Override
67: protected Object _getBOFromReader(XMLStreamReader reader,
68: Object busContext) throws XMLStreamException {
69: // Create a Reader2Writer converter and get the output as a String
70: Reader2Writer r2w = new Reader2Writer(reader);
71: return r2w.getAsString();
72: }
73:
74: @Override
75: protected XMLStreamReader _getReaderFromBO(Object busObj,
76: Object busContext) throws XMLStreamException {
77: // Create an XMLStreamReader from the inputFactory using the String as the sources
78: String str = (String) busObj;
79: StringReader sr = new StringReader(str);
80: return StAXUtils.createXMLStreamReader(sr);
81: }
82:
83: @Override
84: protected void _outputFromBO(Object busObject, Object busContext,
85: XMLStreamWriter writer) throws XMLStreamException {
86: // There is no fast way to output the String to a writer, so get the reader
87: // and pass use the default reader->writer.
88: XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
89: _outputFromReader(reader, writer);
90: }
91:
92: public boolean isElementData() {
93: return false; // The text could be element or text or something else
94: }
95: }
|