private void buildMatch ( Object val ) { // create the match data if ( val != null ) { if ( val instanceof String ) { _match = new String [ ] { ( String ) val } ; } else if ( val instanceof String [ ] ) { String [ ] s = ( String [ ] ) val ; int cnt = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] != null ) cnt ++ ; } if ( cnt == s . length ) _match = s ; else { if ( cnt > 0 ) { _match = new String [ cnt ] ; cnt = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] != null ) { _match [ cnt ++ ] = s [ i ] ; } } } } } else { Iterator matchIterator = null ; // val is never null so this would be an error matchIterator = IteratorFactory . createIterator ( val ) ; if ( matchIterator == null ) { matchIterator = IteratorFactory . EMPTY_ITERATOR ; } ArrayList matchList = new ArrayList ( ) ; while ( matchIterator . hasNext ( ) ) { Object o = matchIterator . next ( ) ; if ( o == null ) continue ; matchList . add ( o ) ; } int size = matchList . size ( ) ; _match = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { assert ( matchList . get ( i ) != null ) ; assert ( matchList . get ( i ) . toString ( ) != null ) ; _match [ i ] = matchList . get ( i ) . toString ( ) ; } } if ( logger . isDebugEnabled ( ) ) { logger . debug ( "****** Select Matches ******" ) ; if ( _match != null ) { for ( int i = 0 ; i < _match . length ; i ++ ) { logger . debug ( i + ": " + _match [ i ] ) ; } } } } else { if ( _nullable && ! isMultiple ( ) && ( _defaultSelections == null || _defaultSelections . size ( ) == 0 ) ) { _match = new String [ ] { NULL_VALUE } ; } } }
This method builds the list of selected items so that they can be marked as selected .