001package org.hl7.fhir.r4.model; 002 003/* 004Copyright (c) 2011+, HL7, Inc. 005All rights reserved. 006 007Redistribution and use in source and binary forms, with or without modification, 008are permitted provided that the following conditions are met: 009 010 * Redistributions of source code must retain the above copyright notice, this 011 list of conditions and the following disclaimer. 012 * Redistributions in binary form must reproduce the above copyright notice, 013 this list of conditions and the following disclaimer in the documentation 014 and/or other materials provided with the distribution. 015 * Neither the name of HL7 nor the names of its contributors may be used to 016 endorse or promote products derived from this software without specific 017 prior written permission. 018 019THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 022IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 025PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028POSSIBILITY OF SUCH DAMAGE. 029 030*/ 031 032/** 033 * This class is created to help implementers deal with a change to 034 * the API that was made between versions 0.81 and 0.9 035 * 036 * The change is the behaviour of the .getX() where the cardinality of 037 * x is 0..1 or 1..1. Before the change, these routines would return 038 * null if the object had not previously been assigned, and after the ' 039 * change, they will automatically create the object if it had not 040 * been assigned (unless the object is polymorphic, in which case, 041 * only the type specific getters create the object) 042 * 043 * When making the transition from the old style to the new style, 044 * the main change is that when testing for presence or abssense 045 * of the element, instead of doing one of these two: 046 * 047 * if (obj.getProperty() == null) 048 * if (obj.getProperty() != null) 049 * 050 * you instead do 051 * 052 * if (!obj.hasProperty()) 053 * if (obj.hasProperty()) 054 * 055 * or else one of these two: 056 * 057 * if (obj.getProperty().isEmpty()) 058 * if (!obj.getProperty().isEmpty()) 059 * 060 * The only way to sort this out is by finding all these things 061 * in the code, and changing them. 062 * 063 * To help with that, you can set the status field of this class 064 * to change how this API behaves. Note: the status value is tied 065 * to the way that you program. The intent of this class is to 066 * help make developers the transiition to status = 0. The old 067 * behaviour is status = 2. To make the transition, set the 068 * status code to 1. This way, any time a .getX routine needs 069 * to automatically create an object, an exception will be 070 * raised instead. The expected use of this is: 071 * - set status = 1 072 * - test your code (all paths) 073 * - when an exception happens, change the code to use .hasX() or .isEmpty() 074 * - when all execution paths don't raise an exception, set status = 0 075 * - start programming to the new style. 076 * 077 * You can set status = 2 and leave it like that, but this is not 078 * compatible with the utilities and validation code, nor with the 079 * HAPI code. So everyone shoul make this transition 080 * 081 * This is a difficult change to make to an API. Most users should engage with it 082 * as they migrate from DSTU1 to DSTU2, at the same time as they encounter 083 * other changes. This change was made in order to align the two java reference 084 * implementations on a common object model, which is an important outcome that 085 * justifies making this change to implementers (sorry for any pain caused) 086 * 087 * @author Grahame 088 * 089 */ 090public class Configuration { 091 092 private static int status = 0; 093 // 0: auto-create 094 // 1: error 095 // 2: return null 096 097 private static boolean acceptInvalidEnums; 098 099 public static boolean errorOnAutoCreate() { 100 return status == 1; 101 } 102 103 104 public static boolean doAutoCreate() { 105 return status == 0; 106 } 107 108 109 public static boolean isAcceptInvalidEnums() { 110 return acceptInvalidEnums; 111 } 112 113 114 public static void setAcceptInvalidEnums(boolean value) { 115 acceptInvalidEnums = value; 116 } 117 118 119}