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.impl;
20:
21: import org.apache.axiom.om.OMElement;
22: import org.apache.axiom.om.impl.builder.StAXOMBuilder;
23: import org.apache.axis2.jaxws.message.Block;
24: import org.apache.axis2.jaxws.message.factory.BlockFactory;
25:
26: import javax.xml.namespace.QName;
27: import javax.xml.stream.XMLStreamException;
28: import javax.xml.stream.XMLStreamReader;
29: import javax.xml.ws.WebServiceException;
30:
31: /** BlockFactoryImpl Abstract Base Class for the Block Factories */
32: public abstract class BlockFactoryImpl implements BlockFactory {
33:
34: public BlockFactoryImpl() {
35: super ();
36: }
37:
38: /* (non-Javadoc)
39: * @see org.apache.axis2.jaxws.message.BlockFactory#createFrom(org.apache.axis2.jaxws.message.Block, java.lang.Object)
40: */
41: public Block createFrom(Block other, Object context)
42: throws XMLStreamException, WebServiceException {
43: // This is the default behavior. Derived Factories may
44: // provide a more performant implementation.
45: if (other.getBlockFactory().equals(this )) {
46: if (other.getBusinessContext() == null && context == null) {
47: return other;
48: } else if (other.getBusinessContext() != null
49: && other.getBusinessContext().equals(context)) {
50: return other;
51: }
52: }
53: QName qName = null;
54: if (other.isQNameAvailable()) {
55: qName = other.getQName();
56: }
57: Block newBlock = createFrom(other.getXMLStreamReader(true),
58: context, qName);
59: return newBlock;
60: }
61:
62: public Block createFrom(XMLStreamReader reader, Object context,
63: QName qName) throws XMLStreamException, WebServiceException {
64: StAXOMBuilder builder = new StAXOMBuilder(reader);
65: OMElement omElement = builder.getDocumentElement();
66: return createFrom(omElement, context, omElement.getQName());
67: }
68:
69: }
|