public void unbind ( ValidationSession session , ValidationObject validationObject , Map < ValidationObject , ProxyObject > boundMap ) { if ( validationObject == null ) { return ; } // For all the fields: look for attached objects. ProxyObject proxyObject = session . getProxyObject ( validationObject ) ; Map < String , ProxyField > fieldMap = proxyObject . getFieldMap ( ) ; for ( String fieldName : fieldMap . keySet ( ) ) { if ( fieldName != null ) { final ClassMetadata classMetadata = m_validationEngine . getClassMetadata ( validationObject . getClass ( ) ) ; final PropertyMetadata fieldMetadata = classMetadata . getField ( fieldName ) ; if ( fieldMetadata == null ) { continue ; } ProxyField proxyField = proxyObject . getProxyField ( fieldName ) ; Method getter = proxyField . getGetter ( ) ; if ( getter . getReturnType ( ) . isAssignableFrom ( List . class ) ) { // if this is a list then walk the list and unbind the objects there. try { @ SuppressWarnings ( "unchecked" ) final List < ValidationObject > validationObjects = ( List < ValidationObject > ) getter . invoke ( validationObject , new Object [ ] { } ) ; for ( ValidationObject child : validationObjects ) { m_validationEngine . unbind ( session , proxyField , child , boundMap ) ; if ( child != null ) { child . setValidationSession ( null ) ; } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } continue ; } if ( m_validationEngine . getClassMetadata ( getter . getReturnType ( ) ) != null ) { // if this is a known object then unbind it try { ValidationObject child = ( ValidationObject ) getter . invoke ( validationObject , new Object [ ] { } ) ; m_validationEngine . unbind ( session , proxyField , child , boundMap ) ; if ( child != null ) { child . setValidationSession ( null ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } continue ; } } } }
Unbind the given object . We have to locate any attached objects and unbind them first .