use of org.drools.core.spi.Wireable in project drools by kiegroup.
the class JavaDialect method addRule.
/**
* This will add the rule for compiling later on.
* It will not actually call the compiler
*/
public void addRule(final RuleBuildContext context) {
final RuleImpl rule = context.getRule();
final RuleDescr ruleDescr = context.getRuleDescr();
RuleClassBuilder classBuilder = context.getDialect().getRuleClassBuilder();
String ruleClass = classBuilder.buildRule(context);
// return if there is no ruleclass name;
if (ruleClass == null) {
return;
}
// The compilation result is for the entire rule, so difficult to associate with any descr
addClassCompileTask(this.pkg.getName() + "." + ruleDescr.getClassName(), ruleDescr, ruleClass, this.src, new RuleErrorHandler(ruleDescr, rule, "Rule Compilation error"));
JavaDialectRuntimeData data = (JavaDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData(ID);
for (Map.Entry<String, String> invokers : context.getInvokers().entrySet()) {
final String className = invokers.getKey();
// Check if an invoker - returnvalue, predicate, eval or consequence has been associated
// If so we add it to the PackageCompilationData as it will get wired up on compilation
final Object invoker = context.getInvokerLookup(className);
if (invoker instanceof Wireable) {
data.putInvoker(className, (Wireable) invoker);
}
final String text = invokers.getValue();
final BaseDescr descr = context.getDescrLookup(className);
addClassCompileTask(className, descr, text, this.src, new RuleInvokerErrorHandler(descr, rule, "Unable to generate rule invoker."));
}
// setup the line mappins for this rule
final String name = this.pkg.getName() + "." + StringUtils.ucFirst(ruleDescr.getClassName());
final LineMappings mapping = new LineMappings(name);
mapping.setStartLine(ruleDescr.getConsequenceLine());
mapping.setOffset(ruleDescr.getConsequenceOffset());
this.pkg.getDialectRuntimeRegistry().getLineMappings().put(name, mapping);
}
use of org.drools.core.spi.Wireable in project drools by kiegroup.
the class MVELDialectRuntimeData method onBeforeExecute.
public void onBeforeExecute() {
for (Wireable target : wireList) {
for (MVELCompileable compileable : invokerLookups.get(target)) {
compileable.compile(this);
// now wire up the target
target.wire(compileable);
}
}
wireList.clear();
for (MVELCompileable compileable : mvelReaders) {
compileable.compile(this);
}
if (dirty) {
rewireImportedMethods();
dirty = false;
}
}
use of org.drools.core.spi.Wireable in project drools by kiegroup.
the class JavaDialectRuntimeData method writeExternal.
/**
* Handles the write serialization of the PackageCompilationData. Patterns in Rules may reference generated data which cannot be serialized by
* default methods. The PackageCompilationData holds a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
*/
public void writeExternal(ObjectOutput stream) throws IOException {
KeyStoreHelper helper = new KeyStoreHelper();
stream.writeBoolean(helper.isSigned());
if (helper.isSigned()) {
stream.writeObject(helper.getPvtKeyAlias());
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeInt(this.store.size());
for (Entry<String, byte[]> entry : this.store.entrySet()) {
out.writeObject(entry.getKey());
out.writeObject(entry.getValue());
}
out.flush();
out.close();
byte[] buff = bos.toByteArray();
stream.writeObject(buff);
if (helper.isSigned()) {
sign(stream, helper, buff);
}
stream.writeInt(this.invokerLookups.size());
for (Entry<String, Wireable> entry : this.invokerLookups.entrySet()) {
stream.writeObject(entry.getKey());
stream.writeObject(entry.getValue());
}
stream.writeInt(this.classLookups.size());
for (Entry<String, byte[]> entry : this.classLookups.entrySet()) {
stream.writeObject(entry.getKey());
stream.writeObject(entry.getValue());
}
}
Aggregations