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