Search in sources :

Example 6 with Function

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();
    }
}
Also used : DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) Function(org.drools.core.rule.Function) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) ByteArrayInputStream(java.io.ByteArrayInputStream) WindowDeclaration(org.drools.core.rule.WindowDeclaration) ImportDeclaration(org.drools.core.rule.ImportDeclaration) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ResourceType(org.kie.api.io.ResourceType) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage)

Example 7 with Function

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);
}
Also used : Function(org.drools.core.rule.Function) LineMappings(org.drools.core.rule.LineMappings) FunctionErrorHandler(org.drools.compiler.builder.impl.errors.FunctionErrorHandler)

Aggregations

Function (org.drools.core.rule.Function)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 AccumulateFunction (org.kie.api.runtime.rule.AccumulateFunction)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DuplicateFunction (org.drools.compiler.compiler.DuplicateFunction)2 TypeDeclaration (org.drools.core.rule.TypeDeclaration)2 WindowDeclaration (org.drools.core.rule.WindowDeclaration)2 Process (org.kie.api.definition.process.Process)2 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)2 ResourceType (org.kie.api.io.ResourceType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 FunctionErrorHandler (org.drools.compiler.builder.impl.errors.FunctionErrorHandler)1 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)1 FunctionDescr (org.drools.compiler.lang.descr.FunctionDescr)1 FunctionImportDescr (org.drools.compiler.lang.descr.FunctionImportDescr)1