use of io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression.BoolOperator in project vertigo by KleeGroup.
the class DslMultiExpressionRule method handle.
/**
* {@inheritDoc}
*/
@Override
protected RuleMultiExpression handle(final PegChoice parsing) {
final List<Object> innerBlock;
switch(parsing.getChoiceIndex()) {
case 0:
final List<?> blockExpression = (List<?>) parsing.getValue();
innerBlock = (List<Object>) blockExpression.get(2);
break;
case 1:
innerBlock = (List<Object>) parsing.getValue();
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
final List<RuleExpression> expressionDefinitions = new ArrayList<>();
final List<RuleMultiExpression> multiExpressionDefinitions = new ArrayList<>();
// first (expression1|multiExpression1)
final PegChoice firstExpressionChoice = (PegChoice) innerBlock.get(1);
switch(firstExpressionChoice.getChoiceIndex()) {
case 0:
expressionDefinitions.add((RuleExpression) firstExpressionChoice.getValue());
break;
case 1:
multiExpressionDefinitions.add((RuleMultiExpression) firstExpressionChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
}
// manyNextExpressionsRule
final List<List<Object>> many = (List<List<Object>>) innerBlock.get(3);
// On récupère le produit de la règle many
BoolOperator operator = null;
for (final List<Object> item : many) {
if (operator != null && operator != item.get(1)) {
throw new IllegalArgumentException("Can't use different operator in same block, attempt to find " + operator);
}
operator = (BoolOperator) item.get(1);
// next (expression2|multiExpression2)
final PegChoice nextExpressionChoice = (PegChoice) item.get(3);
switch(nextExpressionChoice.getChoiceIndex()) {
case 0:
expressionDefinitions.add((RuleExpression) nextExpressionChoice.getValue());
break;
case 1:
multiExpressionDefinitions.add((RuleMultiExpression) nextExpressionChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + nextExpressionChoice.getChoiceIndex() + " not implemented");
}
}
final boolean block = parsing.getChoiceIndex() == 0;
// ---
return new RuleMultiExpression(block, operator != null ? operator : BoolOperator.AND, expressionDefinitions, multiExpressionDefinitions);
}
Aggregations