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.Arrays;
020: import java.util.Iterator;
021: import java.util.List;
022: import javax.xml.namespace.QName;
023:
024: import org.apache.axiom.om.OMElement;
025: import org.apache.axiom.om.OMException;
026: import org.apache.axiom.om.OMNamespace;
027: import org.apache.axiom.soap.RolePlayer;
028: import org.apache.axiom.soap.SOAPFactory;
029: import org.apache.axiom.soap.SOAPHeader;
030: import org.apache.axiom.soap.SOAPHeaderBlock;
031: import org.apache.axiom.soap.SOAPProcessingException;
032: import org.springframework.util.ObjectUtils;
033: import org.springframework.ws.soap.SoapHeaderElement;
034: import org.springframework.ws.soap.SoapHeaderException;
035: import org.springframework.ws.soap.soap12.Soap12Header;
036: import org.springframework.xml.namespace.QNameUtils;
037:
038: /**
039: * Axiom-specific version of <code>org.springframework.ws.soap.Soap12Header</code>.
040: *
041: * @author Arjen Poutsma
042: * @since 1.0.0
043: */
044: class AxiomSoap12Header extends AxiomSoapHeader implements Soap12Header {
045:
046: AxiomSoap12Header(SOAPHeader axiomHeader, SOAPFactory axiomFactory) {
047: super (axiomHeader, axiomFactory);
048: }
049:
050: public SoapHeaderElement addNotUnderstoodHeaderElement(
051: QName headerName) {
052: try {
053: SOAPHeaderBlock notUnderstood = getAxiomHeader()
054: .addHeaderBlock("NotUnderstood",
055: getAxiomHeader().getNamespace());
056: OMNamespace headerNamespace = notUnderstood
057: .declareNamespace(headerName.getNamespaceURI(),
058: QNameUtils.getPrefix(headerName));
059: notUnderstood.addAttribute("qname", headerNamespace
060: .getPrefix()
061: + ":" + headerName.getLocalPart(), null);
062: return new AxiomSoapHeaderElement(notUnderstood,
063: getAxiomFactory());
064: } catch (SOAPProcessingException ex) {
065: throw new AxiomSoapHeaderException(ex);
066: }
067: }
068:
069: public SoapHeaderElement addUpgradeHeaderElement(
070: String[] supportedSoapUris) {
071: try {
072: SOAPHeaderBlock upgrade = getAxiomHeader().addHeaderBlock(
073: "Upgrade", getAxiomHeader().getNamespace());
074: for (int i = 0; i < supportedSoapUris.length; i++) {
075: OMElement supportedEnvelope = getAxiomFactory()
076: .createOMElement("SupportedEnvelope",
077: getAxiomHeader().getNamespace(),
078: upgrade);
079: OMNamespace namespace = supportedEnvelope
080: .declareNamespace(supportedSoapUris[i], "");
081: supportedEnvelope.addAttribute("qname", namespace
082: .getPrefix()
083: + ":Envelope", null);
084: }
085: return new AxiomSoapHeaderElement(upgrade,
086: getAxiomFactory());
087: } catch (OMException ex) {
088: throw new AxiomSoapHeaderException(ex);
089: }
090: }
091:
092: public Iterator examineHeaderElementsToProcess(
093: final String[] roles, final boolean isUltimateDestination)
094: throws SoapHeaderException {
095: RolePlayer rolePlayer = null;
096: if (!ObjectUtils.isEmpty(roles)) {
097: rolePlayer = new RolePlayer() {
098:
099: public List getRoles() {
100: return Arrays.asList(roles);
101: }
102:
103: public boolean isUltimateDestination() {
104: return isUltimateDestination;
105: }
106: };
107: }
108: Iterator result = getAxiomHeader().getHeadersToProcess(
109: rolePlayer);
110: return new AxiomSoapHeaderElementIterator(result);
111: }
112: }
|