Saturday, September 27, 2014

Sample

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

public class ReflectionUpdate {
        private static class InterceptCall
        {
            private Object ObjectToCall1;
            private Object ObjectToCall2;
            private String returnValueString;
            private List<?> returnValueList;

            public InterceptCall(Object ObjectToCall1, Object ObjectToCall2)
            {
                Object ret1 = null;
                Object ret2 = null;
             
                    Method method1 = ObjectToCall1.getClass().getMethod("getString", new Class[0]);
                    ret1 = method1.invoke(ObjectToCall1, new Object[0]);
                    Method method2 = ObjectToCall1.getClass().getMethod("getList", new Class[0]);
                    ret2 = method2.invoke(ObjectToCall2, new Object[0]); //getoredCriteria is called
                    returnValueString = (String)ret1;
                    returnValueList = (List<?>)ret2;
}
            }
       
        ReflectionUpdate(){
           
        }
       public int  updateObjectState( Object originalObject, Object ObjectThatChangeState){
           Method method1 = originalObject.getClass().getMethod("TransformationState", new Class[0]);
           Method methods[] = originalObject.getClass().getMethods();
           String test="abiskar";
           for(int i = 0; i < methods.length; i++)
           {
               Method method = methods[i];
               try
               {
                   if(method.getName().lastIndexOf(test) > 0 && method.getName().startsWith("set"))
                       method.invoke(originalObject, new Object[] {
                           ""
                       });
   
           method1.invoke(originalObject, new Object[] {
               ObjectThatChangeState
           });
         
           InterceptCall parms = new InterceptCall(originalObject,originalObject);
        }
       
}

No comments:

Post a Comment