@@ -0,0 +1,1924 @@
+package com.github.zhongl.hs4j.kit.proxy;%0A%0Aimport java.lang.reflect.*;%0Aimport java.util.*;%0A%0Aimport com.github.zhongl.hs4j.kit.annotations.*;%0A%0A/**%0A * %7B@link ProxyFactory%7D%0A * %0A * @author %3Ca href=mailto:zhong.lunfu@gmail.com%3Ezhongl%3C/a%3E%0A * @created 2011-6-2%0A * %0A */%0Apublic abstract class ProxyFactory %7B%0A%0A  @SuppressWarnings(%22unchecked%22)%0A  public %3CT%3E T newProxyOf(Class%3CT%3E clazz) %7B%0A    scanAndMapMethodToInvacationHandlerWith(clazz);%0A    Class%3C?%3E%5B%5D interfaces = %7B clazz %7D;%0A    return (T) Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, dispatcher);%0A  %7D%0A%0A  protected abstract InvocationHandler createInvocationHandlerWith(Method method, String database, String table);%0A%0A  private void scanAndMapMethodToInvacationHandlerWith(Class%3C?%3E clazz) %7B%0A    final Repository repository = clazz.getAnnotation(Repository.class);%0A    if (repository == null)%0A      throw new IllegalArgumentException(Repository.class + %22 should be annotated to class: %22 + clazz);%0A    final String database = repository.database();%0A    final String table = repository.table();%0A    Method%5B%5D methods = clazz.getMethods();%0A    for (Method method : methods) %7B%0A      InvocationHandler handler = createInvocationHandlerWith(method, database, table);%0A      if ((handler == null)) continue; // no need to map, so skip.%0A      invocationMap.put(method, handler);%0A    %7D%0A  %7D%0A%0A  protected final Map%3CMethod, InvocationHandler%3E invocationMap = new HashMap%3CMethod, InvocationHandler%3E();%0A  private final Dispatcher dispatcher = new Dispatcher();%0A%0A  private final class Dispatcher implements InvocationHandler %7B%0A    @Override%0A    public Object invoke(Object proxy, Method method, Object%5B%5D args) throws Throwable %7B%0A      InvocationHandler invocationHandler = invocationMap.get(method);%0A      if (invocationHandler == null) throw new UnsupportedOperationException(%22No implement method: %22 + method);%0A      return invocationHandler.invoke(proxy, method, args);%0A    %7D%0A  %7D%0A%0A%7D%0A

Remove useless Exception .