value1 = value1.substring(dotPos + 1);
expr = expr.substring(dotPos + 1);
}
}
final InternalReadAccessor extractor = getFieldReadAccessor( context, relDescr, pattern.getObjectType(), value1, null, false );
if ( extractor == null ) {
return false; // impossible to create extractor
}
ValueType vtype = extractor.getValueType();
String operator = relDescr.getOperator().trim();
LiteralRestrictionDescr restrictionDescr = buildLiteralRestrictionDescr(context, relDescr, value2, operator, isConstant);
if (restrictionDescr != null) {
FieldValue field = getFieldValue(context, vtype, restrictionDescr);
if (field != null) {
Constraint constraint = buildLiteralConstraint(context, vtype, field, expr, value1, operator, value2, extractor, restrictionDescr);
if (constraint != null) {
pattern.addConstraint(constraint);
return true;
}
}
}
Restriction restriction = null;
Declaration[] declarations = null;
Declaration declr = null;
if ( value2.indexOf( '(' ) < 0 && value2.indexOf( '.' ) < 0 && value2.indexOf( '[' ) < 0 ) {
declr = context.getDeclarationResolver().getDeclaration( context.getRule(), value2 );
if ( declr == null ) {
// trying to create implicit declaration
final Pattern thisPattern = (Pattern) context.getBuildStack().peek();
declr = this.createDeclarationObject( context,
value2,
thisPattern );
if ( declr == null ) {
// maybe it was a class literal ?
try {
final Class< ? > cls = context.getDialect().getTypeResolver().resolveType( value2 );
restrictionDescr = new LiteralRestrictionDescr( operator,
relDescr.isNegated(),
relDescr.getParameters(),
cls.getName(),
LiteralRestrictionDescr.TYPE_STRING ); // default type
restriction = buildLiteralRestriction( context,
extractor,
restrictionDescr,
getFieldValue(context, vtype, restrictionDescr),
vtype );
} catch ( ClassNotFoundException cnfe ) {
// we will later fallback to regular predicates, so don't raise error
// context.getErrors().add( new DescrBuildError( context.getParentDescr(),
// d,
// null,
// "Unable to return Declaration for identifier '" + rightValue + "'" ) );
return false;
}
}
}
}
if ( declr == null ) {
String[] parts = value2.split( "\\." );
if ( parts.length == 2 ) {
if ( "this".equals( parts[0].trim() ) ) {
declr = this.createDeclarationObject( context,
parts[1].trim(),
(Pattern) context.getBuildStack().peek() );
value2 = parts[1].trim();
} else {
declr = context.getDeclarationResolver().getDeclaration( context.getRule(),
parts[0].trim() );
// if a declaration exists, then it may be a variable direct property access
if ( declr != null ) {
if ( declr.isPatternDeclaration() ) {
// TODO: no need to extract inner declaration when using mvel constraint
declarations = new Declaration[] { declr };
declr = this.createDeclarationObject( context,
parts[1].trim(),
declr.getPattern() );
value2 = parts[1].trim();
} else {
// we will later fallback to regular predicates, so don't raise error
// context.getErrors().add( new DescrBuildError( context.getParentDescr(),
// relDescr,
// "",
// "Not possible to directly access the property '" + parts[1] + "' of declaration '" + parts[0] + "' since it is not a pattern" ) );
return false;
}
}
}
}
}
if ( declr != null ) {
Target right = getRightTarget( extractor );
Target left = (declr.isPatternDeclaration() && !(Date.class.isAssignableFrom( declr.getExtractor().getExtractToClass() ) || Number.class.isAssignableFrom( declr.getExtractor().getExtractToClass() ))) ? Target.HANDLE : Target.FACT;
final Evaluator evaluator = getEvaluator( context,
relDescr,
extractor.getValueType(),
operator,
relDescr.isNegated(),
relDescr.getParametersText(),
left,
right );