use of org.drools.core.rule.Function in project drools by kiegroup.
the class KnowledgePackageImpl method readExternal.
/**
* Handles the read serialization of the Package. Patterns in Rules may
* reference generated data which cannot be serialized by default methods.
* The Package uses PackageCompilationData to hold a reference to the
* generated bytecode; which must be restored before any Rules. A custom
* ObjectInputStream, able to resolve classes against the bytecode in the
* PackageCompilationData, is used to restore the Rules.
*
* @param stream, the stream to read data from in order to restore the object;
* should be an instance of DroolsObjectInputStream or
* InputStream
*/
public void readExternal(ObjectInput stream) throws IOException, ClassNotFoundException {
boolean isDroolsStream = stream instanceof DroolsObjectInputStream;
DroolsObjectInputStream in = isDroolsStream ? (DroolsObjectInputStream) stream : new DroolsObjectInputStream(new ByteArrayInputStream((byte[]) stream.readObject()));
this.name = (String) in.readObject();
this.classFieldAccessorStore = (ClassFieldAccessorStore) in.readObject();
in.setStore(this.classFieldAccessorStore);
this.dialectRuntimeRegistry = (DialectRuntimeRegistry) in.readObject();
this.typeDeclarations = (Map) in.readObject();
this.imports = (Map<String, ImportDeclaration>) in.readObject();
this.staticImports = (Set) in.readObject();
this.functions = (Map<String, Function>) in.readObject();
this.accumulateFunctions = (Map<String, AccumulateFunction>) in.readObject();
this.factTemplates = (Map) in.readObject();
this.ruleFlows = (Map) in.readObject();
this.globals = (Map<String, String>) in.readObject();
this.valid = in.readBoolean();
this.needStreamMode = in.readBoolean();
this.rules = (Map<String, RuleImpl>) in.readObject();
this.entryPointsIds = (Set<String>) in.readObject();
this.windowDeclarations = (Map<String, WindowDeclaration>) in.readObject();
this.traitRegistry = (TraitRegistry) in.readObject();
this.resourceTypePackages = (Map<ResourceType, ResourceTypePackage>) in.readObject();
in.setStore(null);
if (!isDroolsStream) {
in.close();
}
}
use of org.drools.core.rule.Function in project drools by kiegroup.
the class JavaDialect method addFunction.
public void addFunction(final FunctionDescr functionDescr, final TypeResolver typeResolver, final Resource resource) {
// logger.info( functionDescr + " : " + typeResolver );
final String functionClassName = this.pkg.getName() + "." + StringUtils.ucFirst(functionDescr.getName());
functionDescr.setClassName(functionClassName);
this.pkg.addStaticImport(functionClassName + "." + functionDescr.getName());
Function function = new Function(functionDescr.getNamespace(), functionDescr.getName(), ID);
if (resource != null && ((InternalResource) resource).hasURL()) {
function.setResource(resource);
}
this.pkg.addFunction(function);
final String functionSrc = getFunctionBuilder().build(this.pkg, functionDescr, typeResolver, this.pkg.getDialectRuntimeRegistry().getLineMappings(), this.results);
addClassCompileTask(functionClassName, functionDescr, functionSrc, this.src, new FunctionErrorHandler(functionDescr, "Function Compilation error"));
final LineMappings mapping = new LineMappings(functionClassName);
mapping.setStartLine(functionDescr.getLine());
mapping.setOffset(functionDescr.getOffset());
this.pkg.getDialectRuntimeRegistry().getLineMappings().put(functionClassName, mapping);
}
Aggregations