@Override
public Object visit(final ExistExpression obj, final Object arg) throws RIFException {
final VALIDATION flag = (VALIDATION) arg;
if (flag == VALIDATION.NO_TRIPLE_AND_EXISTS) {
throw new RIFException("Exists not allowed in Comparsion!");
}
// variablenscopes �berpr�fen
final Set<RuleVariable> declared = obj.getDeclaredVariables();
final Set<RuleVariable> innerVars = obj.expr.getVariables();
// Deklarierte Variablen d�rfen nicht schon deklariert sein (Scope)
// und m�ssen vorkommen im Term
for (final RuleVariable var : declared) {
if (!innerVars.contains(var)) {
throw new RIFException("Variable " + var.toString()
+ " is declared, but not used!");
} else if (this.declaredVars.contains(var)) {
throw new RIFException("Variable " + var.toString()
+ " in Exists is already declared!");
}
}
// Jede Variable muss gebunden sein im Variablenscope
final Collection<RuleVariable> boundVars = new HashSet<RuleVariable>();
// Boundvars intialisieren
int initSize = 0;
do {
initSize = boundVars.size();
for (final RuleVariable var : declared) {
obj.expr.isBound(var, boundVars);
}
} while (initSize < boundVars.size());
// zweite Iteration, Ungebundene Variablen k�nnen an gebundene
// gebunden werden
for (final RuleVariable var : declared) {
if (!boundVars.contains(var)) {
throw new RIFException("Variable " + var.toString()
+ " not bound!");
}
}
this.declaredVars.addAll(declared);