@Override public void incorrectJsonType(IParseLocation theLocation, String theElementName, ValueType theExpected, ScalarType theExpectedScalarType, ValueType theFound, ScalarType theFoundScalarType) { String message = LenientErrorHandler.createIncorrectJsonTypeMessage(theElementName, theExpected, theExpectedScalarType, theFound, theFoundScalarType); throw new DataFormatException(message); }
static ParserState<TagList> getPreTagListInstance(IParser theParser, FhirContext theContext, boolean theJsonMode, IParserErrorHandler theErrorHandler) { ParserState<TagList> retVal = new ParserState<TagList>(theParser, theContext, theJsonMode, theErrorHandler); retVal.push(retVal.new PreTagListState()); return retVal; }
protected void containResourcesForEncoding(IBaseResource theResource) { ContainedResources contained = new ContainedResources(); containResourcesForEncoding(contained, theResource, theResource); contained.assignIdsToContainedResources(); myContainedResources = contained; }
public void parserValidation() { // START SNIPPET: parserValidation FhirContext ctx = FhirContext.forDstu3(); // Create a parser and configure it to use the strict error handler IParser parser = ctx.newXmlParser(); parser.setParserErrorHandler(new StrictErrorHandler()); // This example resource is invalid, as Patient.active can not repeat String input = "<Patient><active value=\"true\"/><active value=\"false\"/></Patient>"; // The following will throw a DataFormatException because of the StrictErrorHandler parser.parseResource(Patient.class, input); // END SNIPPET: parserValidation }
@Override public void unknownReference(IParseLocation theLocation, String theReference) { throw new DataFormatException("Resource has invalid reference: " + theReference); }
private <T extends IBaseResource> T parseResource(Class<T> theResourceType, XMLEventReader theStreamReader) { ParserState<T> parserState = ParserState.getPreResourceInstance(this, theResourceType, myContext, false, getErrorHandler()); return doXmlLoop(theStreamReader, parserState); }
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonLikeWriter theEventWriter, boolean theContainedResource, boolean theSubResource, CompositeChildElement theParent) throws IOException, DataFormatException { writeCommentsPreAndPost(theNextValue, theEventWriter); encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, theContainedResource, theSubResource, theParent); }
@SuppressWarnings("unchecked") private void pop() { myPreviousElement = myState.getCurrentElement(); if (myState.myStack != null) { myState = myState.myStack; myState.wereBack(); } else { myObject = (T) myState.getCurrentElement(); myState = null; } }
@Override public <T extends IBaseResource> T doParseResource(Class<T> theResourceType, Reader theReader) { XMLEventReader streamReader = createStreamReader(theReader); return parseResource(theResourceType, streamReader); }
@Override protected void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException { JsonLikeWriter eventWriter = createJsonWriter(theWriter); doEncodeResourceToJsonLikeWriter(theResource, eventWriter); }
private boolean checkIfParentShouldBeEncodedAndBuildPath(StringBuilder thePathBuilder, boolean theStarPass) { Set<String> encodeElements = myEncodeElements; if (encodeElements != null && encodeElements.isEmpty() == false) { if (isEncodeElementsAppliesToChildResourcesOnly() && !mySubResource) { encodeElements = null; } } return checkIfPathMatchesForEncoding(thePathBuilder, theStarPass, myEncodeElementsAppliesToResourceTypes, encodeElements, true); }
@Override public IBaseResource parseResource(String theMessageString) throws ConfigurationException, DataFormatException { return parseResource(null, theMessageString); }
/** * Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically * intended for embedded XHTML content */ public void xmlEvent(XMLEvent theNextEvent) { if (myState != null) { myState.xmlEvent(theNextEvent); } }
@Override public IBaseResource parseResource(JsonLikeStructure theJsonLikeStructure) throws DataFormatException { return parseResource(null, theJsonLikeStructure); }
@Override public void containedResourceWithNoId(IParseLocation theLocation) { throw new DataFormatException("Resource has contained child resource with no ID"); }
@Override public IBaseResource parseResource(Reader theReader) throws ConfigurationException, DataFormatException { return parseResource(null, theReader); }
@Override public void invalidValue(IParseLocation theLocation, String theValue, String theError) { throw new DataFormatException("Invalid attribute value \"" + theValue + "\": " + theError); }
@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"); }