001package org.hl7.fhir.dstu2016may.metamodel;
002
003import java.io.InputStream;
004import java.io.OutputStream;
005
006import org.hl7.fhir.dstu2016may.formats.IParser.OutputStyle;
007import org.hl7.fhir.dstu2016may.utils.IWorkerContext;
008
009public class Manager {
010
011  public enum FhirFormat { XML, JSON, JSONLD, TURTLE }
012  
013  public static Element parse(IWorkerContext context, InputStream source, FhirFormat inputFormat) throws Exception {
014    return makeParser(context, inputFormat).parse(source);
015  }
016
017  public static void compose(IWorkerContext context, Element e, OutputStream destination, FhirFormat outputFormat, OutputStyle style, String base) throws Exception {
018    makeParser(context, outputFormat).compose(e, destination, style, base);
019  }
020
021  public static ParserBase makeParser(IWorkerContext context, FhirFormat format) {
022    switch (format) {
023    case JSON : return new JsonParser(context);
024    case XML : return new XmlParser(context);
025    default:
026      throw new IllegalArgumentException("Unknown type: " + format);
027    }
028  }
029  
030}