if ( restriction == null ) {
// error was already logged during restriction creation failure
return;
}
Constraint constraint = null;
if ( restriction instanceof AbstractCompositeRestriction ) {
constraint = new MultiRestrictionFieldConstraint( extractor,
restriction );
} else if ( restriction instanceof LiteralRestriction ) {
constraint = new LiteralConstraint( extractor,
(LiteralRestriction) restriction );
} else if ( restriction instanceof VariableRestriction ) {
constraint = new VariableConstraint( extractor,
(VariableRestriction) restriction );
} else if ( restriction instanceof ReturnValueRestriction ) {
constraint = new ReturnValueConstraint( extractor,
(ReturnValueRestriction) restriction );
} else {
context.getErrors().add( new RuleError( context.getRule(),
fieldConstraintDescr,
null,
"This is a bug: Unkown restriction type '" + restriction.getClass() + "' for pattern '"+pattern.getObjectType().toString()+"' in rule '"+context.getRule().getName()+"'" ) );
}
if ( container == null ) {
pattern.addConstraint( constraint );
} else {
if( constraint.getType().equals( Constraint.ConstraintType.UNKNOWN ) ) {
this.setConstraintType( pattern, (MutableTypeConstraint) constraint );
}
container.addConstraint( constraint );
}
}