001/* 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.parser; 021 022import ca.uhn.fhir.parser.json.BaseJsonLikeValue.ScalarType; 023import ca.uhn.fhir.parser.json.BaseJsonLikeValue.ValueType; 024 025/** 026 * Error handler 027 */ 028public interface IParserErrorHandler { 029 030 /** 031 * Invoked when a contained resource is parsed that has no ID specified (and is therefore invalid) 032 * 033 * @param theLocation The location in the document. WILL ALWAYS BE NULL currently, as this is not yet implemented, but this parameter is included so that locations can be added in the future without 034 * changing the API. 035 * @since 2.0 036 */ 037 void containedResourceWithNoId(IParseLocation theLocation); 038 039 /** 040 * Invoked if the wrong type of element is found while parsing JSON. For example if a given element is 041 * expected to be a JSON Object and is a JSON array 042 * 043 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 044 * @param theElementName The name of the element that was found. 045 * @param theExpectedValueType The datatype that was expected at this location 046 * @param theExpectedScalarType If theExpectedValueType is {@link ValueType#SCALAR}, this is the specific scalar type expected. Otherwise this parameter will be null. 047 * @param theFoundValueType The datatype that was found at this location 048 * @param theFoundScalarType If theFoundValueType is {@link ValueType#SCALAR}, this is the specific scalar type found. Otherwise this parameter will be null. 049 * @since 2.2 050 */ 051 void incorrectJsonType(IParseLocation theLocation, String theElementName, ValueType theExpectedValueType, ScalarType theExpectedScalarType, ValueType theFoundValueType, ScalarType theFoundScalarType); 052 053 /** 054 * The parser detected an attribute value that was invalid (such as: empty "" values are not permitted) 055 * 056 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 057 * @param theValue The actual value 058 * @param theError A description of why the value was invalid 059 * @since 2.2 060 */ 061 void invalidValue(IParseLocation theLocation, String theValue, String theError); 062 063 /** 064 * Resource was missing a required element 065 * 066 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 067 * @param theElementName The missing element name 068 * @since 2.1 069 */ 070 void missingRequiredElement(IParseLocation theLocation, String theElementName); 071 072 /** 073 * Invoked when an element repetition (e.g. a second repetition of something) is found for a field 074 * which is non-repeating. 075 * 076 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 077 * @param theElementName The name of the element that was found. 078 * @since 1.2 079 */ 080 void unexpectedRepeatingElement(IParseLocation theLocation, String theElementName); 081 082 /** 083 * Invoked when an unknown element is found in the document. 084 * 085 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 086 * @param theAttributeName The name of the attribute that was found. 087 */ 088 void unknownAttribute(IParseLocation theLocation, String theAttributeName); 089 090 /** 091 * Invoked when an unknown element is found in the document. 092 * 093 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 094 * @param theElementName The name of the element that was found. 095 */ 096 void unknownElement(IParseLocation theLocation, String theElementName); 097 098 /** 099 * Resource contained a reference that could not be resolved and needs to be resolvable (e.g. because 100 * it is a local reference to an unknown contained resource) 101 * 102 * @param theLocation The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 103 * @param theReference The actual invalid reference (e.g. "#3") 104 * @since 2.0 105 */ 106 void unknownReference(IParseLocation theLocation, String theReference); 107 108 /** 109 * An extension contains both a value and at least one nested extension 110 * 111 * @param theLoc The location in the document. Note that this may be <code>null</code> as the ParseLocation feature is experimental. Use with caution, as the API may change. 112 */ 113 void extensionContainsValueAndNestedExtensions(IParseLocation theLocation); 114 115 /** 116 * For now this is an empty interface. Error handling methods include a parameter of this 117 * type which will currently always be set to null. This interface is included here so that 118 * locations can be added to the API in a future release without changing the API. 119 */ 120 interface IParseLocation { 121 122 /** 123 * Returns the name of the parent element (the element containing the element currently being parsed) 124 * 125 * @since 2.1 126 */ 127 String getParentElementName(); 128 129 } 130 131}