1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
31
32
33
34
35 class SaajSoapElement implements SoapElement {
36
37 private final SOAPElement element;
38
39 private SaajImplementation implementation;
40
41 SaajSoapElement(SOAPElement element) {
42 Assert.notNull(element, "element must not be null");
43 this.element = element;
44 }
45
46 public Source getSource() {
47 return getImplementation().getSource(element);
48 }
49
50 public QName getName() {
51 return getImplementation().getName(element);
52 }
53
54 public void addAttribute(QName name, String value) {
55 try {
56 getImplementation().addAttribute(element, name, value);
57 }
58 catch (SOAPException ex) {
59 throw new SaajSoapElementException(ex);
60 }
61 }
62
63 public void removeAttribute(QName name) {
64 try {
65 getImplementation().removeAttribute(element, name);
66 }
67 catch (SOAPException ex) {
68 throw new SaajSoapElementException(ex);
69 }
70 }
71
72 public String getAttributeValue(QName name) {
73 try {
74 return getImplementation().getAttributeValue(element, name);
75 }
76 catch (SOAPException ex) {
77 throw new SaajSoapElementException(ex);
78 }
79 }
80
81 public Iterator getAllAttributes() {
82 return getImplementation().getAllAttibutes(element);
83 }
84
85 public void addNamespaceDeclaration(String prefix, String namespaceUri) {
86 try {
87 getImplementation().addNamespaceDeclaration(element, prefix, namespaceUri);
88 }
89 catch (SOAPException ex) {
90 throw new SaajSoapElementException(ex);
91 }
92 }
93
94 protected final SOAPElement getSaajElement() {
95 return element;
96 }
97
98 protected final SaajImplementation getImplementation() {
99 if (implementation == null) {
100 if (SaajUtils.getSaajVersion(element) == SaajUtils.SAAJ_13) {
101 implementation = Saaj13Implementation.getInstance();
102 }
103 else if (SaajUtils.getSaajVersion(element) == SaajUtils.SAAJ_12) {
104 implementation = Saaj12Implementation.getInstance();
105 }
106 else if (SaajUtils.getSaajVersion(element) == SaajUtils.SAAJ_11) {
107 implementation = Saaj11Implementation.getInstance();
108 }
109 else {
110 throw new IllegalStateException("Could not find SAAJ on the classpath");
111 }
112 }
113 return implementation;
114 }
115 }