All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.uhn.fhir.parser.StrictErrorHandler Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
package ca.uhn.fhir.parser;

import ca.uhn.fhir.context.FhirContext;

/*
 * #%L
 * HAPI FHIR - Core Library
 * %%
 * Copyright (C) 2014 - 2016 University Health Network
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

/**
 * Parser error handler which throws a {@link DataFormatException} any time an 
 * issue is found while parsing.
 * 
 * @see IParser#setParserErrorHandler(IParserErrorHandler)
 * @see FhirContext#setParserErrorHandler(IParserErrorHandler)
 */
public class StrictErrorHandler implements IParserErrorHandler {

	@Override
	public void unknownElement(IParseLocation theLocation, String theElementName) {
		throw new DataFormatException("Unknown element '" + theElementName + "' found during parse");
	}

	@Override
	public void unknownAttribute(IParseLocation theLocation, String theAttributeName) {
		throw new DataFormatException("Unknown attribute '" + theAttributeName + "' found during parse");
	}

	@Override
	public void unexpectedRepeatingElement(IParseLocation theLocation, String theElementName) {
		throw new DataFormatException("Multiple repetitions of non-repeatable element '" + theElementName + "' found during parse");
	}

	@Override
	public void containedResourceWithNoId(IParseLocation theLocation) {
		throw new DataFormatException("Resource has contained child resource with no ID");
	}

	@Override
	public void unknownReference(IParseLocation theLocation, String theReference) {
		throw new DataFormatException("Resource has invalid reference: " + theReference);
	}

	@Override
	public void missingRequiredElement(IParseLocation theLocation, String theElementName) {
		StringBuilder b = new StringBuilder();
		b.append("Resource is missing required element '");
		b.append(theElementName);
		b.append("'");
		if (theLocation != null) {
			b.append(" in parent element '");
			b.append(theLocation.getParentElementName());
			b.append("'");
		}
		throw new DataFormatException(b.toString());
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy