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