private boolean evaluateConditional ( Siren4JCondition condition , EntityContext context ) { boolean result = true ; if ( condition != null && ! ( "null" . equals ( condition . name ( ) ) ) ) { result = false ; Object val = null ; ConditionFactory factory = ConditionFactory . getInstance ( ) ; Condition cond = factory . getCondition ( condition . logic ( ) ) ; Object obj = condition . name ( ) . startsWith ( "parent." ) ? context . getParentObject ( ) : context . getCurrentObject ( ) ; String name = condition . name ( ) . startsWith ( "parent." ) ? condition . name ( ) . substring ( 7 ) : condition . name ( ) ; if ( obj == null ) { throw new Siren4JRuntimeException ( "No object found. Conditional probably references a parent but does not have a parent: " + condition . name ( ) ) ; } if ( condition . type ( ) . equals ( Type . METHOD ) ) { try { Method method = ReflectionUtils . findMethod ( obj . getClass ( ) , name , null ) ; if ( method != null ) { method . setAccessible ( true ) ; val = method . invoke ( obj , new Object [ ] { } ) ; result = cond . evaluate ( val ) ; } else { throw new Siren4JException ( "Method referenced in condition does not exist: " + condition . name ( ) ) ; } } catch ( Exception e ) { throw new Siren4JRuntimeException ( e ) ; } } else { try { Field field = ReflectionUtils . findField ( obj . getClass ( ) , name ) ; if ( field != null ) { field . setAccessible ( true ) ; val = field . get ( obj ) ; result = cond . evaluate ( val ) ; } else { throw new Siren4JException ( "Field referenced in condition does not exist: " + condition . name ( ) ) ; } } catch ( Exception e ) { throw new Siren4JRuntimeException ( e ) ; } } } return result ; }
Evaluates a value against its specified conditional .