Java源码示例:org.mvel2.integration.PropertyHandlerFactory
示例1
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);
}
示例2
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;
}
示例3
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;
}
示例4
@Override
public void finalize() {
PropertyHandlerFactory.unregisterPropertyHandler(IMessage.class);
PropertyHandlerFactory.unregisterPropertyHandler(MapMessage.class);
}