Information Technology Reference
In-Depth Information
So far, we have created a new filesystem to start writing our project programmatically. It
will have one process (since it is a maven project, it should be located by default at src/
main/resources ); then, we set a group, artefact, and version for the POM file of the
maven project. Once we've done this, we have to validate its content using a KieBuild-
er instance:
KieBuilder kbuilder = ks.newKieBuilder(kfs);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(Level.ERROR)) {
System.out.println("Errors compiling Kie Module");
System.out.println(kbuilder.getResults().getMessages());
throw new IllegalStateException("Errors compiling
KieModule");
}
KieModule kmodule = kbuilder.getKieModule();
ks.getRepository().addKieModule(kmodule);
This will create a KieBuilder instance that will try to construct a KieModule object
from a filesystem that contains maven files. If the building of the KieModule object en-
counters any errors, all messages related to the build will be printed through the system
output, and an exception is thrown to stop the system from continuing with the load.
Otherwise, we obtain the KieModule object from the KieBuilder instance and add it
to the in-memory repository.
Once the module is added to the repository, we can use a KieContainer instance to
obtain the knowledge definitions and knowledge runtimes that are defined in it:
KieContainer kcontainer =
ks.newKieContainer(kmodule.getReleaseId());
KieBase kbase = kcontainer.getKieBase()
KieSession ksession = kbase.newKieSession();
We obtain the default KieBase object for the container and create a simple stateful ses-
sion from the said KieBase ; we could have also requested it directly from the container.
Once we have a session, we can use it to start process instances:
ProcessInstance pI =
Ksession.startProcess("myDesignedProcess");
Search WWH ::




Custom Search