001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.List;
037
038import ca.uhn.fhir.model.api.annotation.Child;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.ResourceDef;
041import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
042import org.hl7.fhir.instance.model.api.IBaseBinary;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * A binary resource can contain any content, whether text, image, pdf, zip archive, etc.
046 */
047@ResourceDef(name="Binary", profile="http://hl7.org/fhir/Profile/Binary")
048public class Binary extends BaseBinary implements IBaseBinary {
049
050    /**
051     * MimeType of the binary content represented as a standard MimeType (BCP 13).
052     */
053    @Child(name = "contentType", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
054    @Description(shortDefinition="MimeType of the binary content", formalDefinition="MimeType of the binary content represented as a standard MimeType (BCP 13)." )
055    protected CodeType contentType;
056
057    /**
058     * The actual content, base64 encoded.
059     */
060    @Child(name = "content", type = {Base64BinaryType.class}, order=1, min=1, max=1, modifier=false, summary=true)
061    @Description(shortDefinition="The actual content", formalDefinition="The actual content, base64 encoded." )
062    protected Base64BinaryType content;
063
064    private static final long serialVersionUID = 974764407L;
065
066  /*
067   * Constructor
068   */
069    public Binary() {
070      super();
071    }
072
073  /*
074   * Constructor
075   */
076    public Binary(CodeType contentType, Base64BinaryType content) {
077      super();
078      this.contentType = contentType;
079      this.content = content;
080    }
081
082    /**
083     * @return {@link #contentType} (MimeType of the binary content represented as a standard MimeType (BCP 13).). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
084     */
085    public CodeType getContentTypeElement() { 
086      if (this.contentType == null)
087        if (Configuration.errorOnAutoCreate())
088          throw new Error("Attempt to auto-create Binary.contentType");
089        else if (Configuration.doAutoCreate())
090          this.contentType = new CodeType(); // bb
091      return this.contentType;
092    }
093
094    public boolean hasContentTypeElement() { 
095      return this.contentType != null && !this.contentType.isEmpty();
096    }
097
098    public boolean hasContentType() { 
099      return this.contentType != null && !this.contentType.isEmpty();
100    }
101
102    /**
103     * @param value {@link #contentType} (MimeType of the binary content represented as a standard MimeType (BCP 13).). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
104     */
105    public Binary setContentTypeElement(CodeType value) { 
106      this.contentType = value;
107      return this;
108    }
109
110    /**
111     * @return MimeType of the binary content represented as a standard MimeType (BCP 13).
112     */
113    public String getContentType() { 
114      return this.contentType == null ? null : this.contentType.getValue();
115    }
116
117    /**
118     * @param value MimeType of the binary content represented as a standard MimeType (BCP 13).
119     */
120    public Binary setContentType(String value) { 
121        if (this.contentType == null)
122          this.contentType = new CodeType();
123        this.contentType.setValue(value);
124      return this;
125    }
126
127    /**
128     * @return {@link #content} (The actual content, base64 encoded.). This is the underlying object with id, value and extensions. The accessor "getContent" gives direct access to the value
129     */
130    public Base64BinaryType getContentElement() { 
131      if (this.content == null)
132        if (Configuration.errorOnAutoCreate())
133          throw new Error("Attempt to auto-create Binary.content");
134        else if (Configuration.doAutoCreate())
135          this.content = new Base64BinaryType(); // bb
136      return this.content;
137    }
138
139    public boolean hasContentElement() { 
140      return this.content != null && !this.content.isEmpty();
141    }
142
143    public boolean hasContent() { 
144      return this.content != null && !this.content.isEmpty();
145    }
146
147    /**
148     * @param value {@link #content} (The actual content, base64 encoded.). This is the underlying object with id, value and extensions. The accessor "getContent" gives direct access to the value
149     */
150    public Binary setContentElement(Base64BinaryType value) { 
151      this.content = value;
152      return this;
153    }
154
155    /**
156     * @return The actual content, base64 encoded.
157     */
158    public byte[] getContent() { 
159      return this.content == null ? null : this.content.getValue();
160    }
161
162    /**
163     * @param value The actual content, base64 encoded.
164     */
165    public Binary setContent(byte[] value) { 
166        if (this.content == null)
167          this.content = new Base64BinaryType();
168        this.content.setValue(value);
169      return this;
170    }
171
172      protected void listChildren(List<Property> childrenList) {
173        super.listChildren(childrenList);
174        childrenList.add(new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, java.lang.Integer.MAX_VALUE, contentType));
175        childrenList.add(new Property("content", "base64Binary", "The actual content, base64 encoded.", 0, java.lang.Integer.MAX_VALUE, content));
176      }
177
178      @Override
179      public void setProperty(String name, Base value) throws FHIRException {
180        if (name.equals("contentType"))
181          this.contentType = castToCode(value); // CodeType
182        else if (name.equals("content"))
183          this.content = castToBase64Binary(value); // Base64BinaryType
184        else
185          super.setProperty(name, value);
186      }
187
188      @Override
189      public Base addChild(String name) throws FHIRException {
190        if (name.equals("contentType")) {
191          throw new FHIRException("Cannot call addChild on a primitive type Binary.contentType");
192        }
193        else if (name.equals("content")) {
194          throw new FHIRException("Cannot call addChild on a primitive type Binary.content");
195        }
196        else
197          return super.addChild(name);
198      }
199
200  public String fhirType() {
201    return "Binary";
202
203  }
204
205      public Binary copy() {
206        Binary dst = new Binary();
207        copyValues(dst);
208        dst.contentType = contentType == null ? null : contentType.copy();
209        dst.content = content == null ? null : content.copy();
210        return dst;
211      }
212
213      protected Binary typedCopy() {
214        return copy();
215      }
216
217      @Override
218      public boolean equalsDeep(Base other) {
219        if (!super.equalsDeep(other))
220          return false;
221        if (!(other instanceof Binary))
222          return false;
223        Binary o = (Binary) other;
224        return compareDeep(contentType, o.contentType, true) && compareDeep(content, o.content, true);
225      }
226
227      @Override
228      public boolean equalsShallow(Base other) {
229        if (!super.equalsShallow(other))
230          return false;
231        if (!(other instanceof Binary))
232          return false;
233        Binary o = (Binary) other;
234        return compareValues(contentType, o.contentType, true) && compareValues(content, o.content, true);
235      }
236
237      public boolean isEmpty() {
238        return super.isEmpty() && (contentType == null || contentType.isEmpty()) && (content == null || content.isEmpty())
239          ;
240      }
241
242  @Override
243  public ResourceType getResourceType() {
244    return ResourceType.Binary;
245   }
246
247  @SearchParamDefinition(name="contenttype", path="Binary.contentType", description="MimeType of the binary content", type="token" )
248  public static final String SP_CONTENTTYPE = "contenttype";
249
250}