001package org.hl7.fhir.dstu3.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.dstu3 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 Copyright (c) 2011+, HL7, Inc. 025 All rights reserved. 026 027 Redistribution and use in source and binary forms, with or without modification, 028 are permitted provided that the following conditions are met: 029 030 * Redistributions of source code must retain the above copyright notice, this 031 list of conditions and the following disclaimer. 032 * Redistributions in binary form must reproduce the above copyright notice, 033 this list of conditions and the following disclaimer in the documentation 034 and/or other materials provided with the distribution. 035 * Neither the name of HL7 nor the names of its contributors may be used to 036 endorse or promote products derived from this software without specific 037 prior written permission. 038 039 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 040 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 041 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 042 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 043 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 044 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 045 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 046 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 047 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 048 POSSIBILITY OF SUCH DAMAGE. 049 050*/ 051 052// Generated on Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.x 053import java.util.List; 054 055import org.hl7.fhir.exceptions.FHIRException; 056import org.hl7.fhir.instance.model.api.IBaseBinary; 057 058import ca.uhn.fhir.model.api.annotation.Child; 059import ca.uhn.fhir.model.api.annotation.Description; 060import ca.uhn.fhir.model.api.annotation.ResourceDef; 061import ca.uhn.fhir.model.api.annotation.SearchParamDefinition; 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 * Treat this binary as if it was this other resource for access control purposes. 077 */ 078 @Child(name = "securityContext", type = {Reference.class}, order=1, min=0, max=1, modifier=false, summary=true) 079 @Description(shortDefinition="Access Control Management", formalDefinition="Treat this binary as if it was this other resource for access control purposes." ) 080 protected Reference securityContext; 081 082 /** 083 * The actual object that is the target of the reference (Treat this binary as if it was this other resource for access control purposes.) 084 */ 085 protected Resource securityContextTarget; 086 087 /** 088 * The actual content, base64 encoded. 089 */ 090 @Child(name = "content", type = {Base64BinaryType.class}, order=2, min=1, max=1, modifier=false, summary=false) 091 @Description(shortDefinition="The actual content", formalDefinition="The actual content, base64 encoded." ) 092 protected Base64BinaryType content; 093 094 private static final long serialVersionUID = 1111991335L; 095 096 /** 097 * Constructor 098 */ 099 public Binary() { 100 super(); 101 } 102 103 /** 104 * Constructor 105 */ 106 public Binary(CodeType contentType, Base64BinaryType content) { 107 super(); 108 this.contentType = contentType; 109 this.content = content; 110 } 111 112 /** 113 * @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 114 */ 115 public CodeType getContentTypeElement() { 116 if (this.contentType == null) 117 if (Configuration.errorOnAutoCreate()) 118 throw new Error("Attempt to auto-create Binary.contentType"); 119 else if (Configuration.doAutoCreate()) 120 this.contentType = new CodeType(); // bb 121 return this.contentType; 122 } 123 124 public boolean hasContentTypeElement() { 125 return this.contentType != null && !this.contentType.isEmpty(); 126 } 127 128 public boolean hasContentType() { 129 return this.contentType != null && !this.contentType.isEmpty(); 130 } 131 132 /** 133 * @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 134 */ 135 public Binary setContentTypeElement(CodeType value) { 136 this.contentType = value; 137 return this; 138 } 139 140 /** 141 * @return MimeType of the binary content represented as a standard MimeType (BCP 13). 142 */ 143 public String getContentType() { 144 return this.contentType == null ? null : this.contentType.getValue(); 145 } 146 147 /** 148 * @param value MimeType of the binary content represented as a standard MimeType (BCP 13). 149 */ 150 public Binary setContentType(String value) { 151 if (this.contentType == null) 152 this.contentType = new CodeType(); 153 this.contentType.setValue(value); 154 return this; 155 } 156 157 /** 158 * @return {@link #securityContext} (Treat this binary as if it was this other resource for access control purposes.) 159 */ 160 public Reference getSecurityContext() { 161 if (this.securityContext == null) 162 if (Configuration.errorOnAutoCreate()) 163 throw new Error("Attempt to auto-create Binary.securityContext"); 164 else if (Configuration.doAutoCreate()) 165 this.securityContext = new Reference(); // cc 166 return this.securityContext; 167 } 168 169 public boolean hasSecurityContext() { 170 return this.securityContext != null && !this.securityContext.isEmpty(); 171 } 172 173 /** 174 * @param value {@link #securityContext} (Treat this binary as if it was this other resource for access control purposes.) 175 */ 176 public Binary setSecurityContext(Reference value) { 177 this.securityContext = value; 178 return this; 179 } 180 181 /** 182 * @return {@link #securityContext} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (Treat this binary as if it was this other resource for access control purposes.) 183 */ 184 public Resource getSecurityContextTarget() { 185 return this.securityContextTarget; 186 } 187 188 /** 189 * @param value {@link #securityContext} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (Treat this binary as if it was this other resource for access control purposes.) 190 */ 191 public Binary setSecurityContextTarget(Resource value) { 192 this.securityContextTarget = value; 193 return this; 194 } 195 196 /** 197 * @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 198 */ 199 public Base64BinaryType getContentElement() { 200 if (this.content == null) 201 if (Configuration.errorOnAutoCreate()) 202 throw new Error("Attempt to auto-create Binary.content"); 203 else if (Configuration.doAutoCreate()) 204 this.content = new Base64BinaryType(); // bb 205 return this.content; 206 } 207 208 public boolean hasContentElement() { 209 return this.content != null && !this.content.isEmpty(); 210 } 211 212 public boolean hasContent() { 213 return this.content != null && !this.content.isEmpty(); 214 } 215 216 /** 217 * @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 218 */ 219 public Binary setContentElement(Base64BinaryType value) { 220 this.content = value; 221 return this; 222 } 223 224 /** 225 * @return The actual content, base64 encoded. 226 */ 227 public byte[] getContent() { 228 return this.content == null ? null : this.content.getValue(); 229 } 230 231 /** 232 * @param value The actual content, base64 encoded. 233 */ 234 public Binary setContent(byte[] value) { 235 if (this.content == null) 236 this.content = new Base64BinaryType(); 237 this.content.setValue(value); 238 return this; 239 } 240 241 protected void listChildren(List<Property> children) { 242 super.listChildren(children); 243 children.add(new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType)); 244 children.add(new Property("securityContext", "Reference(Any)", "Treat this binary as if it was this other resource for access control purposes.", 0, 1, securityContext)); 245 children.add(new Property("content", "base64Binary", "The actual content, base64 encoded.", 0, 1, content)); 246 } 247 248 @Override 249 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 250 switch (_hash) { 251 case -389131437: /*contentType*/ return new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType); 252 case -1622888881: /*securityContext*/ return new Property("securityContext", "Reference(Any)", "Treat this binary as if it was this other resource for access control purposes.", 0, 1, securityContext); 253 case 951530617: /*content*/ return new Property("content", "base64Binary", "The actual content, base64 encoded.", 0, 1, content); 254 default: return super.getNamedProperty(_hash, _name, _checkValid); 255 } 256 257 } 258 259 @Override 260 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 261 switch (hash) { 262 case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType 263 case -1622888881: /*securityContext*/ return this.securityContext == null ? new Base[0] : new Base[] {this.securityContext}; // Reference 264 case 951530617: /*content*/ return this.content == null ? new Base[0] : new Base[] {this.content}; // Base64BinaryType 265 default: return super.getProperty(hash, name, checkValid); 266 } 267 268 } 269 270 @Override 271 public Base setProperty(int hash, String name, Base value) throws FHIRException { 272 switch (hash) { 273 case -389131437: // contentType 274 this.contentType = castToCode(value); // CodeType 275 return value; 276 case -1622888881: // securityContext 277 this.securityContext = castToReference(value); // Reference 278 return value; 279 case 951530617: // content 280 this.content = castToBase64Binary(value); // Base64BinaryType 281 return value; 282 default: return super.setProperty(hash, name, value); 283 } 284 285 } 286 287 @Override 288 public Base setProperty(String name, Base value) throws FHIRException { 289 if (name.equals("contentType")) { 290 this.contentType = castToCode(value); // CodeType 291 } else if (name.equals("securityContext")) { 292 this.securityContext = castToReference(value); // Reference 293 } else if (name.equals("content")) { 294 this.content = castToBase64Binary(value); // Base64BinaryType 295 } else 296 return super.setProperty(name, value); 297 return value; 298 } 299 300 @Override 301 public Base makeProperty(int hash, String name) throws FHIRException { 302 switch (hash) { 303 case -389131437: return getContentTypeElement(); 304 case -1622888881: return getSecurityContext(); 305 case 951530617: return getContentElement(); 306 default: return super.makeProperty(hash, name); 307 } 308 309 } 310 311 @Override 312 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 313 switch (hash) { 314 case -389131437: /*contentType*/ return new String[] {"code"}; 315 case -1622888881: /*securityContext*/ return new String[] {"Reference"}; 316 case 951530617: /*content*/ return new String[] {"base64Binary"}; 317 default: return super.getTypesForProperty(hash, name); 318 } 319 320 } 321 322 @Override 323 public Base addChild(String name) throws FHIRException { 324 if (name.equals("contentType")) { 325 throw new FHIRException("Cannot call addChild on a primitive type Binary.contentType"); 326 } 327 else if (name.equals("securityContext")) { 328 this.securityContext = new Reference(); 329 return this.securityContext; 330 } 331 else if (name.equals("content")) { 332 throw new FHIRException("Cannot call addChild on a primitive type Binary.content"); 333 } 334 else 335 return super.addChild(name); 336 } 337 338 public String fhirType() { 339 return "Binary"; 340 341 } 342 343 public Binary copy() { 344 Binary dst = new Binary(); 345 copyValues(dst); 346 dst.contentType = contentType == null ? null : contentType.copy(); 347 dst.securityContext = securityContext == null ? null : securityContext.copy(); 348 dst.content = content == null ? null : content.copy(); 349 return dst; 350 } 351 352 protected Binary typedCopy() { 353 return copy(); 354 } 355 356 @Override 357 public boolean equalsDeep(Base other_) { 358 if (!super.equalsDeep(other_)) 359 return false; 360 if (!(other_ instanceof Binary)) 361 return false; 362 Binary o = (Binary) other_; 363 return compareDeep(contentType, o.contentType, true) && compareDeep(securityContext, o.securityContext, true) 364 && compareDeep(content, o.content, true); 365 } 366 367 @Override 368 public boolean equalsShallow(Base other_) { 369 if (!super.equalsShallow(other_)) 370 return false; 371 if (!(other_ instanceof Binary)) 372 return false; 373 Binary o = (Binary) other_; 374 return compareValues(contentType, o.contentType, true) && compareValues(content, o.content, true); 375 } 376 377 public boolean isEmpty() { 378 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(contentType, securityContext 379 , content); 380 } 381 382 @Override 383 public ResourceType getResourceType() { 384 return ResourceType.Binary; 385 } 386 387 /** 388 * Search parameter: <b>contenttype</b> 389 * <p> 390 * Description: <b>MimeType of the binary content</b><br> 391 * Type: <b>token</b><br> 392 * Path: <b>Binary.contentType</b><br> 393 * </p> 394 */ 395 @SearchParamDefinition(name="contenttype", path="Binary.contentType", description="MimeType of the binary content", type="token" ) 396 public static final String SP_CONTENTTYPE = "contenttype"; 397 /** 398 * <b>Fluent Client</b> search parameter constant for <b>contenttype</b> 399 * <p> 400 * Description: <b>MimeType of the binary content</b><br> 401 * Type: <b>token</b><br> 402 * Path: <b>Binary.contentType</b><br> 403 * </p> 404 */ 405 public static final ca.uhn.fhir.rest.gclient.TokenClientParam CONTENTTYPE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CONTENTTYPE); 406 407 408} 409