001: /*
002: * Copyright 2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.soap.axiom;
018:
019: import java.util.Iterator;
020: import javax.xml.namespace.QName;
021: import javax.xml.transform.Result;
022: import javax.xml.transform.sax.SAXResult;
023:
024: import org.apache.axiom.om.OMException;
025: import org.apache.axiom.om.OMNamespace;
026: import org.apache.axiom.soap.SOAPFactory;
027: import org.apache.axiom.soap.SOAPHeader;
028: import org.apache.axiom.soap.SOAPHeaderBlock;
029: import org.springframework.ws.soap.SoapHeader;
030: import org.springframework.ws.soap.SoapHeaderElement;
031: import org.springframework.ws.soap.SoapHeaderException;
032: import org.springframework.xml.namespace.QNameUtils;
033:
034: /**
035: * Axiom-specific version of <code>org.springframework.ws.soap.SoapHeader</code>.
036: *
037: * @author Arjen Poutsma
038: * @since 1.0.0
039: */
040: abstract class AxiomSoapHeader extends AxiomSoapElement implements
041: SoapHeader {
042:
043: AxiomSoapHeader(SOAPHeader axiomHeader, SOAPFactory axiomFactory) {
044: super (axiomHeader, axiomFactory);
045: }
046:
047: public Result getResult() {
048: return new SAXResult(new AxiomContentHandler(getAxiomHeader()));
049: }
050:
051: public SoapHeaderElement addHeaderElement(QName name) {
052: try {
053: OMNamespace namespace = getAxiomFactory()
054: .createOMNamespace(name.getNamespaceURI(),
055: QNameUtils.getPrefix(name));
056: SOAPHeaderBlock axiomHeaderBlock = getAxiomHeader()
057: .addHeaderBlock(name.getLocalPart(), namespace);
058: return new AxiomSoapHeaderElement(axiomHeaderBlock,
059: getAxiomFactory());
060: } catch (OMException ex) {
061: throw new AxiomSoapHeaderException(ex);
062: }
063: }
064:
065: public Iterator examineMustUnderstandHeaderElements(String role) {
066: try {
067: return new AxiomSoapHeaderElementIterator(getAxiomHeader()
068: .examineMustUnderstandHeaderBlocks(role));
069: } catch (OMException ex) {
070: throw new AxiomSoapHeaderException(ex);
071: }
072: }
073:
074: public Iterator examineAllHeaderElements() {
075: try {
076: return new AxiomSoapHeaderElementIterator(getAxiomHeader()
077: .examineAllHeaderBlocks());
078: } catch (OMException ex) {
079: throw new AxiomSoapHeaderException(ex);
080: }
081: }
082:
083: public Iterator examineHeaderElements(QName name)
084: throws SoapHeaderException {
085: try {
086: return new AxiomSoapHeaderElementIterator(getAxiomHeader()
087: .getChildrenWithName(name));
088: } catch (OMException ex) {
089: throw new AxiomSoapHeaderException(ex);
090: }
091: }
092:
093: protected SOAPHeader getAxiomHeader() {
094: return (SOAPHeader) getAxiomElement();
095: }
096:
097: protected class AxiomSoapHeaderElementIterator implements Iterator {
098:
099: private final Iterator axiomIterator;
100:
101: protected AxiomSoapHeaderElementIterator(Iterator axiomIterator) {
102: this .axiomIterator = axiomIterator;
103: }
104:
105: public boolean hasNext() {
106: return axiomIterator.hasNext();
107: }
108:
109: public Object next() {
110: try {
111: SOAPHeaderBlock axiomHeaderBlock = (SOAPHeaderBlock) axiomIterator
112: .next();
113: return new AxiomSoapHeaderElement(axiomHeaderBlock,
114: getAxiomFactory());
115: } catch (OMException ex) {
116: throw new AxiomSoapHeaderException(ex);
117: }
118: }
119:
120: public void remove() {
121: axiomIterator.remove();
122: }
123: }
124: }
|