Skip to content

Commit

Permalink
Added LoadingModelEvaluatorBuilder#setJAXBContext(JAXBContext) method
Browse files Browse the repository at this point in the history
See #246
  • Loading branch information
vruusmann committed Aug 6, 2022
1 parent d1b9e75 commit 7e0e08c
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.xml.transform.Source;
import javax.xml.validation.Schema;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Unmarshaller;
import jakarta.xml.bind.ValidationEventHandler;
Expand Down Expand Up @@ -101,6 +102,8 @@
*/
public class LoadingModelEvaluatorBuilder extends ModelEvaluatorBuilder {

private JAXBContext jaxbContext = null;

private Schema schema = null;

private ValidationEventHandler validationEventHandler = null;
Expand Down Expand Up @@ -136,14 +139,19 @@ public LoadingModelEvaluatorBuilder load(InputStream is) throws ParserConfigurat
}

public LoadingModelEvaluatorBuilder load(InputStream is, String modelName) throws ParserConfigurationException, SAXException, JAXBException {
JAXBContext jaxbContext = getJAXBContext();
Schema schema = getSchema();
ValidationEventHandler validationEventHandler = getValidationEventHandler();
List<? extends XMLFilter> filters = getFilters();
boolean locatable = getLocatable();
boolean mutable = getMutable();
VisitorBattery visitors = getVisitors();

Unmarshaller unmarshaller = JAXBUtil.createUnmarshaller();
if(jaxbContext == null){
jaxbContext = JAXBUtil.getContext();
}

Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setSchema(schema);
unmarshaller.setEventHandler(validationEventHandler);

Expand Down Expand Up @@ -267,6 +275,19 @@ public LoadingModelEvaluatorBuilder setCheckSchema(boolean checkSchema){
return (LoadingModelEvaluatorBuilder)super.setCheckSchema(checkSchema);
}

public JAXBContext getJAXBContext(){
return this.jaxbContext;
}

/**
* @see JAXBUtil#getObjectFactoryClasses()
*/
public LoadingModelEvaluatorBuilder setJAXBContext(JAXBContext jaxbContext){
this.jaxbContext = jaxbContext;

return this;
}

public Schema getSchema(){
return this.schema;
}
Expand Down

0 comments on commit 7e0e08c

Please sign in to comment.