public Vector get_device_list ( String pattern ) { // - The returned list final Vector dl = new Vector ( ) ; // ------------------------------------------------------------------ // CASE I: pattern does not contain any '*' char - it's a device name if ( pattern . indexOf ( ' ' ) == - 1 ) { DeviceImpl dev = null ; try { dev = get_device_by_name ( pattern ) ; } catch ( final DevFailed df ) { // - Ignore exception } if ( dev != null ) { dl . add ( dev ) ; return dl ; } } // - For the two remaining cases, we need the list of all DeviceClasses. final Vector dcl = get_class_list ( ) ; // - A temp vector to store a given class' devices Vector temp_dl ; // ------------------------------------------------------------------ // CASE II: pattern == "*" - return a list containing all devices if ( pattern . equals ( "*" ) ) { for ( int i = 0 ; i < dcl . size ( ) ; i ++ ) { temp_dl = ( ( DeviceClass ) dcl . elementAt ( i ) ) . get_device_list ( ) ; for ( final Object aTemp_dl : temp_dl ) { final DeviceImpl dev = ( DeviceImpl ) aTemp_dl ; dl . add ( dev ) ; } } return dl ; } // ------------------------------------------------------------------ // CASE III: pattern contains at least one '*' char Iterator dl_it ; String dev_name ; DeviceImpl dev ; final Iterator dcl_it = dcl . iterator ( ) ; // - Compile the pattern pattern = pattern . replace ( ' ' , ' ' ) ; final Pattern p = Pattern . compile ( pattern ) ; // - For each DeviceClass... while ( dcl_it . hasNext ( ) ) { // ...get device list temp_dl = ( ( DeviceClass ) dcl_it . next ( ) ) . get_device_list ( ) ; // for each device in in list... dl_it = temp_dl . iterator ( ) ; while ( dl_it . hasNext ( ) ) { // ...get device ... dev = ( DeviceImpl ) dl_it . next ( ) ; // ...and device name dev_name = dev . get_name ( ) . toLowerCase ( ) ; // then look for token(s) in device name if ( p . matcher ( dev_name ) . matches ( ) ) { dl . add ( dev ) ; } } } return dl ; }
Get the list of device references which name name match the specified pattern Returns a null vector in case there is no device matching the pattern