org.mvel2.integration.PropertyHandlerFactory Java Examples

The following examples show how to use org.mvel2.integration.PropertyHandlerFactory. 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: MVELInitializer.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private MVELInitializer() {
	MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true; // forcing to use PropertyHandler
       MathProcessor.COMPARE_WITH_PRECISION = true;
       OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE); //Workaround for MVEL-291 "Custom property handler optimization fails with RuntimeException unable to compileShared"
	PropertyHandlerFactory.registerPropertyHandler(IMessage.class, new IMessagePropertyHandler());
	PropertyHandlerFactory.registerPropertyHandler(Map.class, new MapPropertyHandler());

	ctx = new ParserContext();
	ctx.addImport(LocalDateTime.class);
	ctx.addImport(LocalDate.class);
	ctx.addImport(LocalTime.class);
	ctx.addImport(BigDecimal.class);
	ctx.addImport(SailfishURI.class);
	ctx.addImport(Objects.class);
}
 
Example #2
Source File: MvelExpressionExecutor.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static Boolean executeInputExpression(InputClause inputClause, UnaryTests inputEntry, MvelExecutionContext executionContext) {

        if (inputClause == null) {
            throw new IllegalArgumentException("input clause is required");
        }
        if (inputClause.getInputExpression() == null) {
            throw new IllegalArgumentException("input expression is required");
        }
        if (inputEntry == null) {
            throw new IllegalArgumentException("input entry is required");
        }
        
        for (Class<?> variableClass : executionContext.getPropertyHandlers().keySet()) {
            PropertyHandlerFactory.registerPropertyHandler(variableClass, executionContext.getPropertyHandlers().get(variableClass));
        }

        // check if variable is present MVEL execution context
        executionContext.checkExecutionContext(inputClause.getInputExpression().getText());

        // pre parse expression
        String parsedExpression = MvelConditionExpressionPreParser.parse(inputEntry.getText(), inputClause.getInputExpression().getText());

        // compile MVEL expression
        Serializable compiledExpression = MVEL.compileExpression(parsedExpression, executionContext.getParserContext());

        // execute MVEL expression
        Boolean result;

        try {
            result = MVEL.executeExpression(compiledExpression, executionContext.getStackVariables(), Boolean.class);
        } catch (Exception ex) {
            logger.warn("Error while executing input entry: {}", parsedExpression, ex);
            throw new ActivitiDmnExpressionException("error while executing input entry", parsedExpression, ex);
        }

        return result;
    }
 
Example #3
Source File: PatternBuilder.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
private Pattern buildPattern(RuleBuildContext context, PatternDescr patternDescr, ObjectType objectType) {
    String patternIdentifier = patternDescr.getIdentifier();
    boolean duplicateBindings = patternIdentifier != null && objectType instanceof ClassObjectType &&
            context.getDeclarationResolver().isDuplicated(context.getRule(),
                                                          patternIdentifier,
                                                          objectType.getClassName());

    Pattern pattern;
    if (!StringUtils.isEmpty(patternIdentifier) && !duplicateBindings) {

        pattern = new Pattern(context.getNextPatternId(),
                              0, // offset is 0 by default
                              objectType,
                              patternIdentifier,
                              patternDescr.isInternalFact(context));
        if (objectType instanceof ClassObjectType) {
            // make sure PatternExtractor is wired up to correct ClassObjectType and set as a target for rewiring
            context.getPkg().getClassFieldAccessorStore().wireObjectType(objectType, (AcceptsClassObjectType) pattern.getDeclaration().getExtractor());
        }
    } else {
        pattern = new Pattern(context.getNextPatternId(),
                              0, // offset is 0 by default
                              objectType,
                              null);
    }
    pattern.setPassive(patternDescr.isPassive(context));

    if (ClassObjectType.Match_ObjectType.isAssignableFrom(pattern.getObjectType())) {
        PropertyHandler handler = PropertyHandlerFactory.getPropertyHandler(RuleTerminalNodeLeftTuple.class);
        if (handler == null) {
            PropertyHandlerFactoryFixer.getPropertyHandlerClass().put(RuleTerminalNodeLeftTuple.class,
                                                                      new ActivationPropertyHandler());
        }
    }

    // adding the newly created pattern to the build stack this is necessary in case of local declaration usage
    context.getDeclarationResolver().pushOnBuildStack(pattern);

    if (duplicateBindings) {
        processDuplicateBindings(patternDescr.isUnification(), patternDescr, pattern, patternDescr, "this", patternDescr.getIdentifier(), context);
    }
    return pattern;
}
 
Example #4
Source File: MVELInitializer.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public void finalize() {
	PropertyHandlerFactory.unregisterPropertyHandler(IMessage.class);
	PropertyHandlerFactory.unregisterPropertyHandler(MapMessage.class);
}