예제 #1
0
 public Parameterized(WrappedParameter wp, ParametersDelegate pd, Field field, Method method) {
   m_wrappedParameter = wp;
   m_method = method;
   m_field = field;
   if (m_field != null) {
     setFieldAccessible(m_field);
   }
   m_parametersDelegate = pd;
 }
예제 #2
0
 public Object get(Object object) {
   try {
     if (m_method != null) {
       if (m_getter == null) {
         m_getter =
             m_method
                 .getDeclaringClass()
                 .getMethod("g" + m_method.getName().substring(1), new Class[0]);
       }
       return m_getter.invoke(object);
     } else {
       return m_field.get(object);
     }
   } catch (SecurityException e) {
     throw new ParameterException(e);
   } catch (NoSuchMethodException e) {
     // Try to find a field
     String name = m_method.getName();
     String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
     Object result = null;
     try {
       Field field = m_method.getDeclaringClass().getDeclaredField(fieldName);
       if (field != null) {
         setFieldAccessible(field);
         result = field.get(object);
       }
     } catch (NoSuchFieldException ex) {
       // ignore
     } catch (IllegalAccessException ex) {
       // ignore
     }
     return result;
   } catch (IllegalArgumentException e) {
     throw new ParameterException(e);
   } catch (IllegalAccessException e) {
     throw new ParameterException(e);
   } catch (InvocationTargetException e) {
     throw new ParameterException(e);
   }
 }