001: /*
002: * Copyright 2007 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.saaj;
018:
019: import java.util.Iterator;
020: import javax.xml.namespace.QName;
021: import javax.xml.soap.SOAPException;
022: import javax.xml.soap.SOAPHeader;
023: import javax.xml.soap.SOAPHeaderElement;
024: import javax.xml.transform.Result;
025:
026: import org.springframework.util.Assert;
027: import org.springframework.ws.soap.SoapHeader;
028: import org.springframework.ws.soap.SoapHeaderElement;
029: import org.springframework.ws.soap.SoapHeaderException;
030:
031: /**
032: * SAAJ-specific implementation of the <code>SoapHeader</code> interface. Wraps a {@link javax.xml.soap.SOAPHeader}.
033: *
034: * @author Arjen Poutsma
035: * @since 1.0.0
036: */
037: abstract class SaajSoapHeader extends SaajSoapElement implements
038: SoapHeader {
039:
040: SaajSoapHeader(SOAPHeader header) {
041: super (header);
042: }
043:
044: public Iterator examineAllHeaderElements()
045: throws SoapHeaderException {
046: Iterator iterator = getImplementation()
047: .examineAllHeaderElements(getSaajHeader());
048: return new SaajSoapHeaderElementIterator(iterator);
049: }
050:
051: public Iterator examineMustUnderstandHeaderElements(
052: String actorOrRole) throws SoapHeaderException {
053: Iterator iterator = getImplementation()
054: .examineMustUnderstandHeaderElements(getSaajHeader(),
055: actorOrRole);
056: return new SaajSoapHeaderElementIterator(iterator);
057: }
058:
059: public SoapHeaderElement addHeaderElement(QName name)
060: throws SoapHeaderException {
061: try {
062: SOAPHeaderElement headerElement = getImplementation()
063: .addHeaderElement(getSaajHeader(), name);
064: return new SaajSoapHeaderElement(headerElement);
065: } catch (SOAPException ex) {
066: throw new SaajSoapHeaderException(ex);
067: }
068: }
069:
070: protected SOAPHeader getSaajHeader() {
071: return (SOAPHeader) getSaajElement();
072: }
073:
074: public Result getResult() {
075: return getImplementation().getResult(getSaajHeader());
076: }
077:
078: protected static class SaajSoapHeaderElementIterator implements
079: Iterator {
080:
081: private final Iterator iterator;
082:
083: protected SaajSoapHeaderElementIterator(Iterator iterator) {
084: Assert.notNull(iterator, "iterator must not be null");
085: this .iterator = iterator;
086: }
087:
088: public boolean hasNext() {
089: return iterator.hasNext();
090: }
091:
092: public Object next() {
093: SOAPHeaderElement saajHeaderElement = (SOAPHeaderElement) iterator
094: .next();
095: return new SaajSoapHeaderElement(saajHeaderElement);
096: }
097:
098: public void remove() {
099: iterator.remove();
100: }
101: }
102:
103: }
|