public DeviceImpl get_device_by_name ( String dev_name ) throws DevFailed { // // Retrieve class list. Don't use the get_dserver_device() method // followed by // the get_class_list(). In case of several classes embedded within // the same server and the use of this method in the object creation, it // will fail because the end of the dserver object creation is after the // end of the last server device creation. // final Vector cl_list = class_list ; // // Check if the wanted device exists in each class // dev_name = dev_name . toLowerCase ( ) ; Vector dev_list = get_device_list_by_class ( ( ( DeviceClass ) cl_list . elementAt ( 0 ) ) . get_name ( ) ) ; final int nb_class = cl_list . size ( ) ; int i , j , nb_dev ; j = nb_dev = 0 ; boolean found = false ; for ( i = 0 ; i < nb_class ; i ++ ) { dev_list = get_device_list_by_class ( ( ( DeviceClass ) cl_list . elementAt ( i ) ) . get_name ( ) ) ; nb_dev = dev_list . size ( ) ; for ( j = 0 ; j < nb_dev ; j ++ ) { if ( ( ( DeviceImpl ) dev_list . elementAt ( j ) ) . get_name ( ) . toLowerCase ( ) . equals ( dev_name ) == true ) { found = true ; break ; } } if ( found == true ) { break ; } } // // Check also the dserver device // if ( found == false ) { final DServerClass ds_class = DServerClass . instance ( ) ; dev_list = ds_class . get_device_list ( ) ; final String name = ( ( DeviceImpl ) dev_list . elementAt ( 0 ) ) . get_name ( ) ; if ( name . compareToIgnoreCase ( dev_name ) == 0 ) { j = 0 ; } } // // Throw exception if the class is not found // if ( i == nb_class && j == nb_dev ) { final StringBuffer o = new StringBuffer ( "Device " ) ; o . append ( dev_name ) ; o . append ( " not found" ) ; Except . throw_exception ( "API_DeviceNotFound" , o . toString ( ) , "Util::get_device_by_name()" ) ; } return ( DeviceImpl ) dev_list . elementAt ( j ) ; }
Get a device reference from its name