Hi,

Below method is useful if a query with multiple joint tables is used
in your struts application. Any input is very much welcomed.

Regards,
Muliawan


/*
 * name: stuffToBean
 * return: Object
 * parameters: o - an Iterator object returned by getReportQueryIteratorByQuery
 *                         beanClass - a currently being processed class
 *                         attributes - a collection of attributes that is used by
ReportQueryByCriteria
 */
public Object stuffToBean(Object[] o, Class beanClass, String[] attributes) {
        Object classObj = null;
        String attribute = null;
        
        try {
                Method[] methods = beanClass.getDeclaredMethods();
                classObj = beanClass.newInstance();

                for (int i=0; i<attributes.length; i++) {                       
                        attribute = attributes[i];
                                                        
                        if (attributes[i].indexOf(".") != -1) {
                                attribute = 
attributes[i].substring(attributes[i].lastIndexOf(".")+1);
                        }
                
                        for(int j=0; j<methods.length; j++) {
                                if (methods[j].getName().startsWith("set") &&
                                        
methods[j].getName().substring(3).equalsIgnoreCase(attribute)) {
                                        
                                        try {                                          
 
                                                methods[j].invoke(classObj, new 
Object[]{ o[i] });
                                        } catch (InvocationTargetException e) {
                                                e.printStackTrace();
                                        }
                                        break;
                                }
                        }
                }
        } catch (InstantiationException e) {
                e.printStackTrace();
        } catch (IllegalAccessException e) {
                e.printStackTrace();
        }
        return classObj;
}

-- 
"It is your attitude, and not your aptitude, that determines your altitude"

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to