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.io.IOException;
20: import java.io.InputStream;
21: import javax.activation.DataHandler;
22: import javax.xml.soap.AttachmentPart;
23: import javax.xml.soap.SOAPException;
24:
25: import org.springframework.util.Assert;
26: import org.springframework.ws.mime.Attachment;
27:
28: /**
29: * SAAJ-specific implementation of the <code>Attachment</code> interface. Wraps a {@link
30: * javax.xml.soap.AttachmentPart}.
31: *
32: * @author Arjen Poutsma
33: * @since 1.0.0
34: */
35: class SaajAttachment implements Attachment {
36:
37: private final AttachmentPart saajAttachment;
38:
39: public SaajAttachment(AttachmentPart saajAttachment) {
40: Assert.notNull(saajAttachment,
41: "saajAttachment must not be null");
42: this .saajAttachment = saajAttachment;
43: }
44:
45: public String getContentId() {
46: return saajAttachment.getContentId();
47: }
48:
49: public String getContentType() {
50: return saajAttachment.getContentType();
51: }
52:
53: public InputStream getInputStream() throws IOException {
54: try {
55: return saajAttachment.getDataHandler().getInputStream();
56: } catch (SOAPException ex) {
57: throw new SaajAttachmentException(ex);
58: }
59: }
60:
61: public long getSize() {
62: try {
63: return saajAttachment.getSize();
64: } catch (SOAPException ex) {
65: throw new SaajAttachmentException(ex);
66: }
67: }
68:
69: public DataHandler getDataHandler() {
70: try {
71: return saajAttachment.getDataHandler();
72: } catch (SOAPException ex) {
73: throw new SaajAttachmentException(ex);
74: }
75: }
76: }
|