Java源码示例:org.mvel2.integration.VariableResolverFactory

示例1
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();
}
 
示例2
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();
}
 
示例3
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();
}
 
示例4
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);
}
 
示例5
public void accumulate(Object workingMemoryContext,
                       Object context,
                       Tuple tuple,
                       InternalFactHandle handle,
                       Declaration[] declarations,
                       Declaration[] innerDeclarations,
                       WorkingMemory workingMemory) throws Exception {
    
    VariableResolverFactory factory = unit.getFactory( null, null, null, handle, tuple, null, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver()  );
    
    final Object value = MVEL.executeExpression( this.expression,
                                                 handle.getObject(),
                                                 factory );
    if ( this.function.supportsReverse() ) {
        ((MVELAccumulatorFunctionContext) context).reverseSupport.put( handle.getId(), value );
    }
    this.function.accumulate( ((MVELAccumulatorFunctionContext) context).context,
                              value );
}
 
示例6
private boolean evaluate(ExecutableStatement statement, InternalFactHandle handle, InternalWorkingMemory workingMemory, Tuple tuple) {
    if (compilationUnit == null) {
        Map<String, Object> vars = valuesAsMap(handle.getObject(), workingMemory, tuple, declarations);
        if (operators.length > 0) {
            if (vars == null) {
                vars = new HashMap<String, Object>();
            }
            InternalFactHandle[] handles = tuple != null ? tuple.toFactHandles() : new InternalFactHandle[0];
            for (EvaluatorWrapper operator : operators) {
                vars.put( operator.getBindingName(), operator );
                operator.loadHandles(handles, handle);
            }
        }
        return evaluate(statement, handle.getObject(), vars);
    }

    VariableResolverFactory factory = compilationUnit.createFactory();
    compilationUnit.updateFactory( handle, tuple, null, workingMemory,
                                   workingMemory.getGlobalResolver(),
                                   factory );

    return (Boolean) MVELSafeHelper.getEvaluator().executeExpression( statement, handle.getObject(), factory );
}
 
示例7
private String resolveVariable(String s, VariableResolverFactory factory) {
    Map<String, String> replacements = new HashMap<>();
    Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s);
    while (matcher.find()) {
        String paramName = matcher.group(1);
        if (replacements.get(paramName) == null) {

            Object variableValue = getVariable(paramName);
            if (variableValue != null) {
                replacements.put(paramName, variableValue.toString());
            } else {
                try {
                    variableValue = MVELSafeHelper.getEvaluator().eval(paramName, factory);
                    String variableValueString = variableValue == null ? "" : variableValue.toString();
                    replacements.put(paramName, variableValueString);
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", paramName);
                }
            }
        }
    }
    for (Map.Entry<String, String> replacement : replacements.entrySet()) {
        s = s.replace("#{" + replacement.getKey() + "}", replacement.getValue());
    }
    return s;
}
 
示例8
@Override
public Object getProperty(
		String propName,
		Object object,
		VariableResolverFactory arg2) {
	if (object instanceof IMessage) {
		IMessage iMessage = (IMessage)object;
           Object propertyValue = iMessage.getField(propName);
           if(propertyValue instanceof IFilter){
               try {
                   return ((IFilter) propertyValue).getValue();
               } catch(MvelException e) {
                   throw new EPSCommonException("Failed to get value: probably wrong filter type", e);
               }
           }
		return propertyValue;
	}
	throw new IllegalArgumentException("object is not an IMessage");
}
 
示例9
public boolean isDefinedAt(IBatisRoutingFact routingFact) {
    Validate.notNull(routingFact);
    String namespace = StringUtils.substringBeforeLast(routingFact.getAction(), ".");
    boolean matches = StringUtils.equals(namespace, getTypePattern());
    if (matches) {
        try {
            Map<String, Object> vrs = new HashMap<String, Object>();
            vrs.putAll(getFunctionMap());
            vrs.put("$ROOT", routingFact.getArgument()); // add top object reference for expression
            VariableResolverFactory vrfactory = new MapVariableResolverFactory(vrs);
            if (MVEL.evalToBoolean(getAttributePattern(), routingFact.getArgument(), vrfactory)) {
                return true;
            }
        } catch (Throwable t) {
            logger
                    .info(
                            "failed to evaluate attribute expression:'{}' with context object:'{}'\n{}",
                            new Object[] { getAttributePattern(), routingFact.getArgument(), t });
        }
    }
    return false;
}
 
示例10
public boolean isDefinedAt(IBatisRoutingFact routingFact) {
    Validate.notNull(routingFact);
    boolean matches = StringUtils.equals(getTypePattern(), routingFact.getAction());
    if (matches) {
        try {
            Map<String, Object> vrs = new HashMap<String, Object>();
            vrs.putAll(getFunctionMap());
            vrs.put("$ROOT", routingFact.getArgument()); // add top object reference for expression
            VariableResolverFactory vrfactory = new MapVariableResolverFactory(vrs);
            if (MVEL.evalToBoolean(getAttributePattern(), routingFact.getArgument(), vrfactory)) {
                return true;
            }
        } catch (Throwable t) {
            logger
                    .info(
                            "failed to evaluate attribute expression:'{}' with context object:'{}'\n{}",
                            new Object[] { getAttributePattern(), routingFact.getArgument(), t });
        }
    }

    return false;
}
 
示例11
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 );
}
 
示例12
public void accumulate(Object workingMemoryContext,
                       Object context,
                       Tuple tuple,
                       InternalFactHandle handle,
                       Declaration[] declarations,
                       Declaration[] innerDeclarations,
                       WorkingMemory workingMemory) throws Exception {
    Object[]  localVars = ((MVELAccumulatorContext) context).getVariables();
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext)workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getActionFactory();
    actionUnit.updateFactory( handle, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory );

    DroolsVarFactory df = ( DroolsVarFactory ) factory.getNextFactory();
    
    if ( reverse != null ) {
        Object[] shadow = new Object [df.getOtherVarsPos()];
        for ( int i = 0; i < df.getOtherVarsPos(); i++ ) {
            shadow[i] = factory.getIndexedVariableResolver( i ).getValue();
            
            
        }
        // SNAPSHOT variable values
        ((MVELAccumulatorContext) context).getShadow().put( handle.getId(), shadow);
    }
    MVELSafeHelper.getEvaluator().executeExpression( this.action,
                            null,
                            factory );
    
    
    if ( localVars.length > 0 ) {
        for ( int i = 0; i < df.getOtherVarsLength(); i++ ) {
            localVars[i] = factory.getIndexedVariableResolver( df.getOtherVarsPos() + i ).getValue();
        }
    }
    
    ((MVELAccumulatorContext) context).setVariables( localVars );        
}
 
示例13
public Object getResult(Object workingMemoryContext,
                        Object context,
                        Tuple tuple,
                        Declaration[] declarations,
                        WorkingMemory workingMemory) throws Exception {
    Object[]  localVars = ((MVELAccumulatorContext) context).getVariables();
    
    MVELAccumulatorFactoryContext factoryContext = (MVELAccumulatorFactoryContext)workingMemoryContext;
    VariableResolverFactory factory = factoryContext.getResultFactory();
    resultUnit.updateFactory( null, tuple, localVars, (InternalWorkingMemory) workingMemory, workingMemory.getGlobalResolver(), factory );

    return MVELSafeHelper.getEvaluator().executeExpression( this.result, null, factory );
}
 
示例14
public MVELAccumulatorFactoryContext(VariableResolverFactory initFactory,
                                     VariableResolverFactory actionFactory,
                                     VariableResolverFactory resultFactory) {
    this.initFactory = initFactory;
    this.actionFactory = actionFactory;
    this.resultFactory = resultFactory;
}
 
示例15
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 );
    }
}
 
示例16
public VariableResolverFactory createFactory() {
    Object[] vals = new Object[inputIdentifiers.length];

    VariableResolverFactory factory = varModel.createFactory( vals );
    factory.setNextFactory( new DroolsVarFactory() );
    return factory;
}
 
示例17
public VariableResolverFactory getFactory(final Object knowledgeHelper,
                                          final Declaration[] prevDecl,
                                          final Rule rule,
                                          final Tuple tuples,
                                          final Object[] otherVars,
                                          final InternalWorkingMemory workingMemory,
                                          final GlobalResolver globals) {
    VariableResolverFactory factory = createFactory();
    updateFactory(knowledgeHelper, prevDecl, rule, null, knowledgeHelper, tuples, otherVars, workingMemory, globals, factory );
    return factory;
}
 
示例18
public VariableResolverFactory getFactory(final Object knowledgeHelper,
                                          final Declaration[] prevDecl,
                                          final Rule rule,
                                          final InternalFactHandle rightHandle,
                                          final Tuple tuple,
                                          final Object[] otherVars,
                                          final InternalWorkingMemory workingMemory,
                                          final GlobalResolver globals) {
    VariableResolverFactory factory = createFactory();
    updateFactory(knowledgeHelper, prevDecl, rule, rightHandle, rightHandle != null ? rightHandle.getObject() : null, tuple, otherVars, workingMemory, globals, factory);
    return factory;
}
 
示例19
public void updateFactory( InternalFactHandle rightHandle,
                           Tuple tuple,
                           Object[] localVars,
                           InternalWorkingMemory workingMemory,
                           GlobalResolver globalResolver,
                           VariableResolverFactory factory ) {
    updateFactory( null, null, null, rightHandle, rightHandle != null ? rightHandle.getObject() : null, tuple, localVars, workingMemory, globalResolver, factory );
}
 
示例20
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 ) );
}
 
示例21
public Object getProperty(String name,
                          Object obj,
                          VariableResolverFactory variableFactory) {
    AgendaItem item = ( AgendaItem ) obj;
    if ( "rule".equals( name ) ) {
        return item.getRule();
    } else if ( "active".equals( name ) ) {
        return item.isQueued();
    } else if ( "objects".equals( name ) ) {
        return item.getObjects();
    } else if ( "factHandles".equals( name ) ) {
        return item.getFactHandles();
    } else if ( "declarationIds".equals( name ) ) {
        return item.getDeclarationIds();
    } else if ( "this".equals( name ) ) {
        return item;
    }

    // FIXME hack as MVEL seems to be ignoring indexed variables
    VariableResolver vr = variableFactory.getNextFactory().getVariableResolver( name );
    if ( vr != null ) {
        return vr.getValue();
    }
            
    Declaration declr = item.getTerminalNode().getSubRule().getOuterDeclarations().get( name );
    if ( declr != null ) {
        return declr.getValue( null, item.getTuple().get( declr ).getObject() );
    } else {
        return item.getRule().getMetaData( name );
    }
}
 
示例22
public int doAfter(Object value,
                   ASTNode node,
                   VariableResolverFactory factory) {
    while ( factory != null && !(factory instanceof DroolsVarFactory)) {
        factory =  factory.getNextFactory();
    }

    if ( factory == null ) {
        throw new RuntimeException( "Unable to find DroolsMVELIndexedFactory" );
    }

    KnowledgeHelper knowledgeHelper = ((DroolsVarFactory)factory).getKnowledgeHelper();
    if (isEqualityMode == null) {
        isEqualityMode = knowledgeHelper.getWorkingMemory().getKnowledgeBase().getConfiguration().getAssertBehaviour() == RuleBaseConfiguration.AssertBehaviour.EQUALITY;
    }

    if (modificationMask.isSet(PropertySpecificUtil.TRAITABLE_BIT)) {
        calculateModificationMask(knowledgeHelper, (WithNode)node);
    }

    if (isEqualityMode) {
        Tuple tuple = knowledgeHelper.getTuple();
        InternalFactHandle modifiedFh = tuple.getFactHandle();
        while (modifiedFh == null || modifiedFh.getObject() != value) {
            tuple = tuple.getParent();
            modifiedFh = tuple.getFactHandle();
        }
        knowledgeHelper.update(modifiedFh, modificationMask, value.getClass());
    } else {
        knowledgeHelper.update(value, modificationMask, value.getClass());
    }

    return 0;
}
 
示例23
@Override
public Object eval(final String expression, final VariableResolverFactory resolverFactory) {
    return MVEL.eval(expression, resolverFactory);
}
 
示例24
@Override
public Object eval(final String expression, final Object ctx, final VariableResolverFactory resolverFactory) {
    return MVEL.eval(expression, ctx, resolverFactory);
}
 
示例25
@Override
public <T> T eval(final String expression, final VariableResolverFactory vars, final Class<T> toType) {
    return MVEL.eval(expression, vars, toType);
}
 
示例26
@Override
public <T> T eval(final String expression, final Object ctx, final VariableResolverFactory vars, final Class<T> toType) {
    return MVEL.eval(expression, ctx, vars, toType);
}
 
示例27
@Override
public Object eval(final String expression, final VariableResolverFactory resolverFactory) {
    return AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            return MVEL.eval(expression, resolverFactory);
        }
    }, KiePolicyHelper.getAccessContext());
}
 
示例28
@Override
public Object eval(final String expression, final Object ctx, final VariableResolverFactory resolverFactory) {
    return AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            return MVEL.eval(expression, ctx, resolverFactory);
        }
    }, KiePolicyHelper.getAccessContext());
}
 
示例29
@Override
public <T> T eval(final String expression, final VariableResolverFactory vars, final Class<T> toType) {
    return AccessController.doPrivileged(new PrivilegedAction<T>() {

        @Override
        public T run() {
            return MVEL.eval(expression, vars, toType);
        }
    }, KiePolicyHelper.getAccessContext());
}
 
示例30
@Override
public <T> T eval(final String expression, final Object ctx, final VariableResolverFactory vars, final Class<T> toType) {
    return AccessController.doPrivileged(new PrivilegedAction<T>() {

        @Override
        public T run() {
            return MVEL.eval(expression, ctx, vars, toType);
        }
    }, KiePolicyHelper.getAccessContext());
}