01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.ws.soap.saaj;
18:
19: import java.util.Iterator;
20: import javax.xml.namespace.QName;
21: import javax.xml.soap.SOAPElement;
22: import javax.xml.soap.SOAPException;
23: import javax.xml.transform.Source;
24:
25: import org.springframework.util.Assert;
26: import org.springframework.ws.soap.SoapElement;
27: import org.springframework.ws.soap.saaj.support.SaajUtils;
28:
29: /**
30: * SAAJ-specific implementation of the <code>SoapElement</code> interface. Wraps a {@link javax.xml.soap.SOAPElement}.
31: *
32: * @author Arjen Poutsma
33: * @since 1.0.0
34: */
35: class SaajSoapElement implements SoapElement {
36:
37: private final SOAPElement element;
38:
39: public SaajSoapElement(SOAPElement element) {
40: Assert.notNull(element, "element must not be null");
41: this .element = element;
42: }
43:
44: public Source getSource() {
45: return getImplementation().getSource(element);
46: }
47:
48: public QName getName() {
49: return getImplementation().getName(element);
50: }
51:
52: public void addAttribute(QName name, String value) {
53: try {
54: getImplementation().addAttribute(element, name, value);
55: } catch (SOAPException ex) {
56: throw new SaajSoapElementException(ex);
57: }
58: }
59:
60: public void removeAttribute(QName name) {
61: try {
62: getImplementation().removeAttribute(element, name);
63: } catch (SOAPException ex) {
64: throw new SaajSoapElementException(ex);
65: }
66: }
67:
68: public String getAttributeValue(QName name) {
69: try {
70: return getImplementation().getAttributeValue(element, name);
71: } catch (SOAPException ex) {
72: throw new SaajSoapElementException(ex);
73: }
74: }
75:
76: public Iterator getAllAttibutes() {
77: return getImplementation().getAllAttibutes(element);
78: }
79:
80: protected final SOAPElement getSaajElement() {
81: return element;
82: }
83:
84: protected final SaajImplementation getImplementation() {
85: if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_13) {
86: return Saaj13Implementation.getInstance();
87: } else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
88: return Saaj12Implementation.getInstance();
89: } else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_11) {
90: return Saaj11Implementation.getInstance();
91: } else {
92: throw new IllegalStateException(
93: "Could not find SAAJ on the classpath");
94: }
95: }
96: }
|