Code example for Method

Methods: equals, getDeclaringClass, getName, toString

0
  } 
 
  @Override 
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Method getResult = ProducerCommandContext.class.getMethod("getResult");
    if (method.equals(getResult)) {
      return result;
    } 
    Method setResult = ProducerCommandContext.class.getMethod("setResult", Object.class);
    if (method.equals(setResult)) {
      result = args[0];
      return null; 
    } 
    Method toString = Object.class.getMethod("toString");
    if (method.equals(toString)) {
      return "JdbcProducer proxy for " + contextType.getSimpleName();
    } 
 
    if (method.getDeclaringClass().equals(JdbcProducerCommandContext.class)) {
      return method.invoke(backend.newJdbcCommandContext(), args);
    } 
 
    if (method.getName().startsWith("get")) {
      String fieldName = method.getName().substring("get".length());
      fieldName = Character.toLowerCase(fieldName.charAt(0)) + fieldName.substring(1);
      return fields.get(fieldName);
    } 
 
    throw new UnsupportedOperationException("TODO implement: " + method.toString());
  } 
 
}