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