View Javadoc
1   /*
2    * Copyright 2009 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  package org.openehealth.ipf.commons.ihe.xds.core.metadata;
17  
18  import lombok.EqualsAndHashCode;
19  import lombok.ToString;
20  import org.openehealth.ipf.commons.core.ContentMap;
21  
22  import javax.activation.DataHandler;
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlMimeType;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  import java.io.Serializable;
30  
31  /**
32   * Represents the contents of a document and the describing entry.
33   * <p> 
34   * All members of this class are allowed to be <code>null</code>.
35   * @author Jens Riemschneider
36   * @author Stefan Ivanov
37   * @author Dmytro Rud
38   */
39  @XmlAccessorType(XmlAccessType.FIELD)
40  @XmlType(name = "Document")
41  @XmlRootElement(name = "document")
42  @EqualsAndHashCode(callSuper = false, doNotUseGetters = true)
43  @ToString(doNotUseGetters = true)
44  public class Document extends ContentMap implements Serializable {
45      private static final long serialVersionUID = 5206884085835642756L;
46  
47      private DocumentEntry documentEntry;
48  
49      public Document() {
50      }
51  
52      /**
53       * Constructs a document.
54       * @param documentEntry
55       *          the document entry describing the meta data of the document.
56       * @param dataHandler
57       *          the data handler allowing access to the contents of the document.
58       */
59      public Document(DocumentEntry documentEntry, DataHandler dataHandler) {
60          this.documentEntry = documentEntry;
61          if (dataHandler != null) {
62              setContent(DataHandler.class, dataHandler);
63          }
64      }
65  
66      /**
67       * @return the document entry describing the meta data of the document.
68       */
69      public DocumentEntry getDocumentEntry() {
70          return documentEntry;
71      }
72      
73      /**
74       * @param documentEntry
75       *            the document entry describing the meta data of the document.
76       */
77      public void setDocumentEntry(DocumentEntry documentEntry) {
78          this.documentEntry = documentEntry;
79      }
80  
81      /**
82       * Same as <code>getContent(DataHandler.class)</code>.
83       *
84       * @return the data handler allowing access to the contents of the document.
85       */
86      @XmlElement(name = "data")
87      @XmlMimeType("application/octet-stream")
88      public DataHandler getDataHandler() {
89          return getContent(DataHandler.class);
90      }
91      
92      /**
93       * Same as <code>setContent(DataHandler.class, DataHandler dataHandler)</code>.
94       *
95       * @param dataHandler
96       *          the data handler allowing access to the contents of the document.
97       */
98      public void setDataHandler(DataHandler dataHandler) {
99          setContent(DataHandler.class, dataHandler);
100     }
101 
102 }