Java Code Examples for org.mvel2.integration.VariableResolverFactory#setNextFactory()
The following examples show how to use
org.mvel2.integration.VariableResolverFactory#setNextFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MVELSalienceExpression.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public int getValue(final KnowledgeHelper khelper, final Rule rule, final WorkingMemory workingMemory) { VariableResolverFactory factory = unit.getFactory( khelper, khelper != null ? ((AgendaItem)khelper.getMatch()).getTerminalNode().getSalienceDeclarations() : null, rule, null, khelper != null ? (LeftTuple) khelper.getMatch().getTuple() : null, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver() ); // do we have any functions for this namespace? InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id ); factory.setNextFactory( data.getFunctionFactory() ); } Object value = MVEL.executeExpression( this.expr, factory ); if (value instanceof String) { value = TimeUtils.parseTimeString( (String)value ); } return ((Number)value).intValue(); }
Example 2
Source File: MVELEvalExpression.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public boolean evaluate(final Tuple tuple, final Declaration[] requiredDeclarations, final WorkingMemory workingMemory, final Object context) throws Exception { VariableResolverFactory factory = ( VariableResolverFactory ) context; unit.updateFactory( null, (LeftTuple) tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory ); // do we have any functions for this namespace? InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id ); factory.setNextFactory( data.getFunctionFactory() ); } final Boolean result = (Boolean) MVEL.executeExpression( this.expr, null, factory ); return result.booleanValue(); }
Example 3
Source File: MVELEnabledExpression.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public boolean getValue(final Tuple tuple, final Declaration[] declrs, final RuleImpl rule, final WorkingMemory workingMemory) { VariableResolverFactory factory = unit.getFactory( null, declrs, rule, null, (LeftTuple) tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver() ); // do we have any functions for this namespace? InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id ); factory.setNextFactory( data.getFunctionFactory() ); } return ((Boolean) MVEL.executeExpression( this.expr, null, factory )).booleanValue(); }
Example 4
Source File: MVELObjectExpression.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public Object getValue(final Tuple leftTuple, final Declaration[] declrs, final InternalWorkingMemory wm) { VariableResolverFactory factory = unit.getFactory( null, declrs, null, null, leftTuple, null, wm, wm.getGlobalResolver() ); // do we have any functions for this namespace? InternalKnowledgePackage pkg = wm.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id ); factory.setNextFactory( data.getFunctionFactory() ); } return MVELSafeHelper.getEvaluator().executeExpression(this.expr, factory); }
Example 5
Source File: MVELAccumulator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public void init(Object workingMemoryContext, Object context, Tuple tuple, Declaration[] declarations, WorkingMemory workingMemory) throws Exception { Object[] localVars = new Object[initUnit.getOtherIdentifiers().length]; MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext)workingMemoryContext; VariableResolverFactory factory = factoryContext.getInitFactory(); initUnit.updateFactory( null, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory ); InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( "mvel" ); factory.setNextFactory( data.getFunctionFactory() ); } MVELSafeHelper.getEvaluator().executeExpression( this.init, null, factory ); DroolsVarFactory df = ( DroolsVarFactory ) factory.getNextFactory(); if ( localVars.length > 0 ) { for ( int i = 0; i < df.getOtherVarsLength(); i++ ) { localVars[i] = factory.getIndexedVariableResolver( df.getOtherVarsPos() + i ).getValue(); } } ((MVELAccumulatorContext) context).setVariables( localVars ); }
Example 6
Source File: MVELConsequence.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) throws Exception { VariableResolverFactory factory = unit.getFactory( knowledgeHelper, ((AgendaItem)knowledgeHelper.getMatch()).getTerminalNode().getRequiredDeclarations(), knowledgeHelper.getRule(), knowledgeHelper.getTuple(), null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver() ); // do we have any functions for this namespace? InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id ); factory.setNextFactory( data.getFunctionFactory() ); } CompiledExpression compexpr = (CompiledExpression) this.expr; if ( MVELDebugHandler.isDebugMode() ) { if ( MVELDebugHandler.verbose ) { logger.info(DebugTools.decompile(compexpr)); } MVEL.executeDebugger( compexpr, knowledgeHelper, factory ); } else { MVEL.executeExpression( compexpr, knowledgeHelper, factory ); } }
Example 7
Source File: MVELCompilationUnit.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public VariableResolverFactory createFactory() { Object[] vals = new Object[inputIdentifiers.length]; VariableResolverFactory factory = varModel.createFactory( vals ); factory.setNextFactory( new DroolsVarFactory() ); return factory; }
Example 8
Source File: MVELReturnValueExpression.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public FieldValue evaluate(final InternalFactHandle handle, final Tuple tuple, final Declaration[] previousDeclarations, final Declaration[] requiredDeclarations, final WorkingMemory workingMemory, final Object ctx) throws Exception { VariableResolverFactory factory = ( VariableResolverFactory )ctx; unit.updateFactory( handle, tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory ); // do we have any functions for this namespace? InternalKnowledgePackage pkg = workingMemory.getKnowledgeBase().getPackage( "MAIN" ); if ( pkg != null ) { MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( this.id ); factory.setNextFactory( data.getFunctionFactory() ); } return workingMemory.getKnowledgeBase().getConfiguration().getComponentFactory().getFieldFactory().getFieldValue( MVELSafeHelper.getEvaluator().executeExpression( this.expr, handle, factory ) ); }
Example 9
Source File: MVELReturnValueEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Object evaluate(ProcessContext context) throws Exception { int length = unit.getOtherIdentifiers().length; Object[] vars = new Object[ length ]; if (unit.getOtherIdentifiers() != null) { for (int i = 0; i < length; i++ ) { vars[i] = context.getVariable( unit.getOtherIdentifiers()[i] ); } } InternalWorkingMemory internalWorkingMemory = (InternalWorkingMemory) context.getKieRuntime(); VariableResolverFactory factory = unit.getFactory( context, null, // No previous declarations null, // No rule null, // No "right object" null, // No (left) tuples vars, internalWorkingMemory, (GlobalResolver) context.getKieRuntime().getGlobals() ); // do we have any functions for this namespace? KiePackage pkg = context.getKieRuntime().getKieBase().getKiePackage("MAIN"); if ( pkg instanceof KnowledgePackageImpl) { MVELDialectRuntimeData data = ( MVELDialectRuntimeData ) ((KnowledgePackageImpl) pkg).getDialectRuntimeRegistry().getDialectData( id ); factory.setNextFactory( data.getFunctionFactory() ); } Object value = MVELSafeHelper.getEvaluator().executeExpression( this.expr, null, factory ); if ( !(value instanceof Boolean) ) { throw new RuntimeException( "Constraints must return boolean values: " + unit.getExpression() + " returns " + value + (value == null? "" : " (type=" + value.getClass())); } return ((Boolean) value).booleanValue(); }