View Javadoc

1   /*
2    * Copyright 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.axiom;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import javax.activation.DataHandler;
22  
23  import org.springframework.util.Assert;
24  import org.springframework.ws.mime.Attachment;
25  
26  /**
27   * Axiom-specific implementation of [email protected] org.springframework.ws.mime.Attachment}
28   *
29   * @author Arjen Poutsma
30   * @since 1.0.0
31   */
32  class AxiomAttachment implements Attachment {
33  
34      private final DataHandler dataHandler;
35  
36      private final String contentId;
37  
38      public AxiomAttachment(String contentId, DataHandler dataHandler) {
39          Assert.notNull(contentId, "contentId must not be null");
40          Assert.notNull(dataHandler, "dataHandler must not be null");
41          this.contentId = contentId;
42          this.dataHandler = dataHandler;
43      }
44  
45      public String getContentId() {
46          return contentId;
47      }
48  
49      public String getContentType() {
50          return dataHandler.getContentType();
51      }
52  
53      public InputStream getInputStream() throws IOException {
54          return dataHandler.getInputStream();
55      }
56  
57      public long getSize() {
58          // Axiom does not support getting the size of attachments.
59          return -1;
60      }
61  
62      public DataHandler getDataHandler() {
63          return dataHandler;
64      }
65  }