Another attempt to avoid parser classload

This commit is contained in:
jamesagnew 2022-01-21 14:59:50 -05:00
parent 8818acfbf8
commit 315604759c
4 changed files with 67 additions and 40 deletions

View File

@ -131,10 +131,11 @@ public abstract class FormatUtilities {
*
* See https://github.com/hapifhir/hapi-fhir/issues/3268
*/
try {
if ("XML".equalsIgnoreCase(format))
return new org.hl7.fhir.r5.formats.XmlParser();
return (ParserBase) Class.forName("org.hl7.fhir.r5.formats.XmlParser").getConstructor().newInstance();
if ("JSON".equalsIgnoreCase(format))
return new org.hl7.fhir.r5.formats.JsonParser();
return (ParserBase) Class.forName("org.hl7.fhir.r5.formats.JsonParser").getConstructor().newInstance();
if ("TURTLE".equalsIgnoreCase(format))
throw new Error("unsupported Format " + format.toString()); // return new TurtleParser();
if ("JSONLD".equalsIgnoreCase(format))
@ -142,6 +143,9 @@ public abstract class FormatUtilities {
if ("VBAR".equalsIgnoreCase(format)) throw new Error("unsupported Format " + format.toString()); //
if ("TEXT".equalsIgnoreCase(format)) throw new Error("unsupported Format " + format.toString()); //
throw new Error("unsupported Format " + format);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) {
throw new Error("Could not instantiate", e);
}
}
public static FhirFormat determineFormat(byte[] source) throws FHIRException {

View File

@ -75,6 +75,7 @@ import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.PrimitiveType;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.test.utils.ClassesLoadedFlags;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser;
@ -86,6 +87,8 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import org.slf4j.LoggerFactory;
/**
* General parser for JSON content. You instantiate an JsonParser of these, but you
* actually use parse or parseGeneral defined on this class
@ -94,6 +97,11 @@ import com.google.gson.JsonSyntaxException;
*/
public abstract class JsonParserBase extends ParserBase implements IParser {
static {
LoggerFactory.getLogger("org.hl7.fhir.r5.formats.XmlParserBase").debug("XML Parser is being loaded");
ClassesLoadedFlags.ourJsonParserBaseLoaded = true;
}
@Override
public ParserType getType() {
return ParserType.JSON;

View File

@ -76,6 +76,7 @@ import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Element;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.test.utils.ClassesLoadedFlags;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
@ -83,6 +84,7 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
import org.hl7.fhir.utilities.xml.IXMLWriter;
import org.hl7.fhir.utilities.xml.XMLWriter;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
@ -95,6 +97,11 @@ import org.xmlpull.v1.XmlPullParserFactory;
*/
public abstract class XmlParserBase extends ParserBase implements IParser {
static {
LoggerFactory.getLogger("org.hl7.fhir.r5.formats.XmlParserBase").debug("XML Parser is being loaded");
ClassesLoadedFlags.ourXmlParserBaseLoaded = true;
}
@Override
public ParserType getType() {
return ParserType.XML;

View File

@ -0,0 +1,8 @@
package org.hl7.fhir.r5.test.utils;
public class ClassesLoadedFlags {
public static boolean ourXmlParserBaseLoaded;
public static boolean ourJsonParserBaseLoaded;
}