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.springframework.util.Assert;
24 import org.springframework.util.xml.StaxUtils;
25 import org.springframework.ws.soap.axiom.support.AxiomUtils;
26
27 import org.apache.axiom.om.OMElement;
28 import org.apache.axiom.om.OMException;
29 import org.apache.axiom.soap.SOAPBody;
30 import org.apache.axiom.soap.SOAPFactory;
31
32
33
34
35
36
37
38 abstract class AbstractPayload extends Payload {
39
40 private final SOAPBody axiomBody;
41
42 private final SOAPFactory axiomFactory;
43
44 protected AbstractPayload(SOAPBody axiomBody, SOAPFactory axiomFactory) {
45 Assert.notNull(axiomBody, "'axiomBody' must not be null");
46 Assert.notNull(axiomFactory, "'axiomFactory' must not be null");
47 this.axiomBody = axiomBody;
48 this.axiomFactory = axiomFactory;
49 }
50
51 @Override
52 public final Source getSource() {
53 try {
54 OMElement payloadElement = getPayloadElement();
55 if (payloadElement != null) {
56 XMLStreamReader streamReader = getStreamReader(payloadElement);
57 return StaxUtils.createCustomStaxSource(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 @Override
71 public final Result getResult() {
72 AxiomUtils.removeContents(getAxiomBody());
73 return getResultInternal();
74 }
75
76 protected abstract Result getResultInternal();
77
78 public SOAPFactory getAxiomFactory() {
79 return axiomFactory;
80 }
81
82 protected SOAPBody getAxiomBody() {
83 return axiomBody;
84 }
85
86 protected OMElement getPayloadElement() throws OMException {
87 return getAxiomBody().getFirstElement();
88 }
89
90 }