View Javadoc
1   package ca.uhn.fhir.parser;
2   
3   import ca.uhn.fhir.parser.json.JsonLikeValue.ScalarType;
4   import ca.uhn.fhir.parser.json.JsonLikeValue.ValueType;
5   
6   /*
7    * #%L
8    * HAPI FHIR - Core Library
9    * %%
10   * Copyright (C) 2014 - 2018 University Health Network
11   * %%
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   * 
16   * http://www.apache.org/licenses/LICENSE-2.0
17   * 
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   * #L%
24   */
25  
26  /**
27   * Error handler
28   */
29  public interface IParserErrorHandler {
30  
31  	/**
32  	 * Invoked when a contained resource is parsed that has no ID specified (and is therefore invalid)
33  	 * 
34  	 * @param theLocation
35  	 *           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
36  	 *           changing the API.
37  	 * @since 2.0
38  	 */
39  	void containedResourceWithNoId(IParseLocation theLocation);
40  
41  	/**
42  	 * Invoked if the wrong type of element is found while parsing JSON. For example if a given element is
43  	 * expected to be a JSON Object and is a JSON array
44  	 * @param theLocation
45  	 *           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. 
46  	 * @param theElementName
47  	 *           The name of the element that was found.
48  	 * @param theExpectedValueType The datatype that was expected at this location
49  	 * @param theExpectedScalarType If theExpectedValueType is {@link ValueType#SCALAR}, this is the specific scalar type expected. Otherwise this parameter will be null.
50  	 * @param theFoundValueType The datatype that was found at this location
51  	 * @param theFoundScalarType If theFoundValueType is {@link ValueType#SCALAR}, this is the specific scalar type found. Otherwise this parameter will be null.
52  	 * 
53  	 * @since 2.2
54  	 */
55  	void incorrectJsonType(IParseLocation theLocation, String theElementName, ValueType theExpectedValueType, ScalarType theExpectedScalarType, ValueType theFoundValueType, ScalarType theFoundScalarType);
56  
57  	/**
58  	 * The parser detected an attribute value that was invalid (such as: empty "" values are not permitted)
59  	 * 
60  	 * @param theLocation
61  	 *           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. 
62  	 * @param theValue The actual value
63  	 * @param theError A description of why the value was invalid
64  	 * @since 2.2
65  	 */
66  	void invalidValue(IParseLocation theLocation, String theValue, String theError);
67  
68  	/**
69  	 * Resource was missing a required element
70  	 * 
71  	 * @param theLocation
72  	 *           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. 
73  	 * @param theElementName The missing element name
74  	 * @since 2.1
75  	 */
76  	void missingRequiredElement(IParseLocation theLocation, String theElementName);
77  
78  	/**
79  	 * Invoked when an element repetition (e.g. a second repetition of something) is found for a field
80  	 * which is non-repeating.
81  	 * 
82  	 * @param theLocation
83  	 *           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. 
84  	 * @param theElementName
85  	 *           The name of the element that was found.
86  	 * @since 1.2
87  	 */
88  	void unexpectedRepeatingElement(IParseLocation theLocation, String theElementName);
89  
90  	/**
91  	 * Invoked when an unknown element is found in the document.
92  	 * 
93  	 * @param theLocation
94  	 *           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. 
95  	 * @param theAttributeName
96  	 *           The name of the attribute that was found.
97  	 */
98  	void unknownAttribute(IParseLocation theLocation, String theAttributeName);
99  
100 	/**
101 	 * Invoked when an unknown element is found in the document.
102 	 * 
103 	 * @param theLocation
104 	 *           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. 
105 	 * @param theElementName
106 	 *           The name of the element that was found.
107 	 */
108 	void unknownElement(IParseLocation theLocation, String theElementName);
109 
110 	/**
111 	 * Resource contained a reference that could not be resolved and needs to be resolvable (e.g. because
112 	 * it is a local reference to an unknown contained resource)
113 	 * 
114 	 * @param theLocation
115 	 *           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. 
116 	 * @param theReference The actual invalid reference (e.g. "#3")
117 	 * @since 2.0
118 	 */
119 	void unknownReference(IParseLocation theLocation, String theReference);
120 
121 	/**
122 	 * For now this is an empty interface. Error handling methods include a parameter of this
123 	 * type which will currently always be set to null. This interface is included here so that
124 	 * locations can be added to the API in a future release without changing the API.
125 	 */
126 	interface IParseLocation {
127 
128 		/**
129 		 * Returns the name of the parent element (the element containing the element currently being parsed)
130 		 * @since 2.1
131 		 */
132 		String getParentElementName();
133 		
134 	}
135 
136 }