1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.axiom;
18
19 import javax.xml.stream.XMLStreamReader;
20 import javax.xml.transform.Result;
21 import javax.xml.transform.Source;
22
23 import org.apache.axiom.om.OMElement;
24 import org.apache.axiom.om.OMException;
25 import org.apache.axiom.soap.SOAPBody;
26 import org.apache.axiom.soap.SOAPFactory;
27
28 import org.springframework.util.Assert;
29 import org.springframework.ws.soap.axiom.support.AxiomUtils;
30 import org.springframework.xml.transform.StaxSource;
31
32
33
34
35
36
37
38
39 abstract class Payload {
40
41 private final SOAPBody axiomBody;
42
43 private final SOAPFactory axiomFactory;
44
45 protected Payload(SOAPBody axiomBody, SOAPFactory axiomFactory) {
46 Assert.notNull(axiomBody, "'axiomBody' must not be null");
47 Assert.notNull(axiomFactory, "'axiomFactory' must not be null");
48 this.axiomBody = axiomBody;
49 this.axiomFactory = axiomFactory;
50 }
51
52 public final Source getSource() {
53 try {
54 OMElement payloadElement = getPayloadElement();
55 if (payloadElement != null) {
56 XMLStreamReader streamReader = getStreamReader(payloadElement);
57 return new StaxSource(streamReader);
58 }
59 else {
60 return null;
61 }
62 }
63 catch (OMException ex) {
64 throw new AxiomSoapBodyException(ex);
65 }
66 }
67
68 protected abstract XMLStreamReader getStreamReader(OMElement payloadElement);
69
70 public final Result getResult() {
71 AxiomUtils.removeContents(getAxiomBody());
72 return getResultInternal();
73 }
74
75 protected abstract Result getResultInternal();
76
77 public SOAPFactory getAxiomFactory() {
78 return axiomFactory;
79 }
80
81 protected SOAPBody getAxiomBody() {
82 return axiomBody;
83 }
84
85 protected OMElement getPayloadElement() throws OMException {
86 return getAxiomBody().getFirstElement();
87 }
88
89 }