use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.
the class DMNModelImpl method readExternal.
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
this.serializedAs = (SerializationFormat) in.readObject();
this.resource = (Resource) in.readObject();
String xml = (String) in.readObject();
if (!(in instanceof DroolsObjectInputStream)) {
throw new UnsupportedOperationException();
// TODO assume some defaults
}
DroolsObjectInputStream is = (DroolsObjectInputStream) in;
DMNCompilerImpl compiler = (DMNCompilerImpl) is.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
Definitions definitions = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).unmarshal(xml);
this.definitions = definitions;
DMNModelImpl compiledModel = (DMNModelImpl) compiler.compile(definitions);
this.inputs = compiledModel.inputs;
this.decisions = compiledModel.decisions;
this.bkms = compiledModel.bkms;
this.itemDefs = compiledModel.itemDefs;
this.messages = compiledModel.messages;
this.types = compiledModel.types;
this.runtimeTypeCheck = compiledModel.runtimeTypeCheck;
}
use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.
the class DMNModelImpl method writeExternal.
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(serializedAs);
out.writeObject(resource);
if (!(out instanceof DroolsObjectOutputStream)) {
throw new UnsupportedOperationException();
// TODO assume some defaults
}
DroolsObjectOutputStream os = (DroolsObjectOutputStream) out;
DMNCompilerImpl compiler = (DMNCompilerImpl) os.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
String output = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).marshal(this.definitions);
out.writeObject(output);
}
use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.
the class DMNAssemblerService method addResources.
@Override
public void addResources(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) throws Exception {
KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
DMNCompilerImpl dmnCompiler = (DMNCompilerImpl) kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
DMNMarshaller dmnMarshaller = dmnCompiler.getMarshaller();
if (resources.size() == 1) {
// quick path:
internalAddResource(kbuilderImpl, dmnCompiler, resources.iterator().next(), Collections.emptyList());
return;
}
List<DMNResource> dmnResources = new ArrayList<>();
for (ResourceWithConfiguration r : resources) {
Definitions definitions = dmnMarshaller.unmarshal(r.getResource().getReader());
QName modelID = new QName(definitions.getNamespace(), definitions.getName());
DMNResource dmnResource = new DMNResource(modelID, r, definitions);
dmnResources.add(dmnResource);
}
// enrich with imports
for (DMNResource r : dmnResources) {
for (Import i : r.getDefinitions().getImport()) {
if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Either<String, DMNResource> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnResources, DMNResource::getModelID);
DMNResource located = resolvedResult.getOrElseThrow(RuntimeException::new);
r.addDependency(located.getModelID());
}
}
}
List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
Collection<DMNModel> dmnModels = new ArrayList<>();
for (DMNResource dmnRes : sortedDmnResources) {
DMNModel dmnModel = internalAddResource(kbuilderImpl, dmnCompiler, dmnRes.getResAndConfig(), dmnModels);
dmnModels.add(dmnModel);
}
}
use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.
the class DMNValidatorImpl method validateCompilation.
private List<DMNMessage> validateCompilation(Definitions dmnModel, DMNMessageManager results) {
if (dmnModel != null) {
DMNCompiler compiler = new DMNCompilerImpl(dmnCompilerConfig);
DMNModel model = compiler.compile(dmnModel);
if (model != null) {
return model.getMessages();
} else {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, dmnModel, results, null, null, Msg.FAILED_VALIDATOR);
}
}
return Collections.emptyList();
}
Aggregations