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 );
if ( evaluator == null ) {
return false;
}
restriction = new VariableRestriction( extractor,
declr,
evaluator );
if ( declr.getPattern().getObjectType().equals( new ClassObjectType( DroolsQuery.class ) ) && Operator.EQUAL.getOperatorString().equals( operator ) ) {
// declaration is query argument, so allow for unification.
restriction = new UnificationRestriction( (VariableRestriction) restriction );
}
}
if ( restriction == null ) {
Dialect dialect = context.getDialect();
if ( !value2.startsWith( "(" ) ) {
// it's not a traditional return value, so override the dialect
MVELDialect mvelDialect = (MVELDialect) context.getDialect( "mvel" );
context.setDialect( mvelDialect );
}
// execute it as a return value
restriction = buildRestriction( context,
(Pattern) context.getBuildStack().peek(),
extractor,
new ReturnValueRestrictionDescr( operator,
relDescr.isNegated(),
relDescr.getParametersText(),
value2 ) );
// fall back to original dialect
context.setDialect( dialect );
}
if ( restriction == null ) {
// something failed and an error should already have been reported
return false;
}
if (declr == null) {
ReturnValueRestriction returnValueRestriction = (ReturnValueRestriction)restriction;
Declaration[] requiredDeclarations = restriction.getRequiredDeclarations();
String[] requiredGlobals = returnValueRestriction.getRequiredGlobals();
declarations = new Declaration[(requiredDeclarations != null ? requiredDeclarations.length : 0) + (requiredGlobals != null ? requiredGlobals.length : 0)];
int i = 0;
if (requiredDeclarations != null) {
for (Declaration requiredDeclaration : requiredDeclarations)