private Restriction buildRestriction(final RuleBuildContext context,
final InternalReadAccessor extractor,
final FieldConstraintDescr fieldConstraintDescr,
final QualifiedIdentifierRestrictionDescr qiRestrictionDescr) {
FieldValue field = null;
final String[] parts = qiRestrictionDescr.getText().split( "\\." );
// if only 2 parts, it may be a composed direct property access
if ( parts.length == 2 ) {
Declaration implicit = null;
if ( "this".equals( parts[0] ) ) {
implicit = this.createDeclarationObject( context,
parts[1],
(Pattern) context.getBuildStack().peek() );
} else {
final Declaration decl = context.getDeclarationResolver().getDeclaration( context.getRule(),
parts[0] );
// if a declaration exists, then it may be a variable direct property access, not an enum
if ( decl != null ) {
if ( decl.isPatternDeclaration() ) {
implicit = this.createDeclarationObject( context,
parts[1],
decl.getPattern() );
} else {
context.getErrors().add( new DescrBuildError( context.getParentDescr(),
qiRestrictionDescr,
"",
"Not possible to directly access the property '" + parts[1] + "' of declaration '" + parts[0] + "' since it is not a pattern" ) );
return null;
}
}
}
if ( implicit != null ) {
Target right = getRightTarget( extractor );
Target left = (implicit.isPatternDeclaration() && !(Date.class.isAssignableFrom( implicit.getExtractor().getExtractToClass() ) || Number.class.isAssignableFrom( implicit.getExtractor().getExtractToClass() ))) ? Target.HANDLE : Target.FACT;
final Evaluator evaluator = getEvaluator( context,
qiRestrictionDescr,
extractor.getValueType(),
qiRestrictionDescr.getEvaluator(),
qiRestrictionDescr.isNegated(),
qiRestrictionDescr.getParameterText(),
left,
right );
if ( evaluator == null ) {
return null;
}
return new VariableRestriction( extractor,
implicit,
evaluator );
}
}
final int lastDot = qiRestrictionDescr.getText().lastIndexOf( '.' );
final String className = qiRestrictionDescr.getText().substring( 0,
lastDot );
final String fieldName = qiRestrictionDescr.getText().substring( lastDot + 1 );
try {
final Class staticClass = context.getDialect().getTypeResolver().resolveType( className );
field = FieldFactory.getFieldValue( staticClass.getField( fieldName ).get( null ),
extractor.getValueType(),
context.getPackageBuilder().getDateFormats() );
if ( field.isObjectField() ) {
((ObjectFieldImpl) field).setEnum( true );
((ObjectFieldImpl) field).setEnumName( staticClass.getName() );
((ObjectFieldImpl) field).setFieldName( fieldName );
}
} catch ( final ClassNotFoundException e ) {