{
HashMap<Long, CtMethod> allMethods = JavassistMethodHashing.getMethodMap(proxy.getSuperclass());
for (Map.Entry<Long, CtMethod> entry : allMethods.entrySet())
{
CtMethod m = entry.getValue();
if (!Modifier.isPublic(m.getModifiers()) || Modifier.isStatic(m.getModifiers()) || Modifier.isFinal(m.getModifiers())) continue;
Long hash = entry.getKey();
if (addedMethods.contains(hash)) continue;
if (hardcodedMethods.contains(hash)) continue;
addedMethods.add(hash);
String aopReturnStr = (m.getReturnType().equals(CtClass.voidType)) ? "" : "return ($r)";
String returnStr = (m.getReturnType().equals(CtClass.voidType)) ? "" : "return ";
String args = "null";
String name = null;
if (isAdvised)
{
MethodInfo info = advisor.getMethodInfo(hash.longValue());
Method originalMethod = info.getUnadvisedMethod();
name = originalMethod.getName();
}
else
{
name = m.getName();
}
if (m.getParameterTypes().length > 0) args = "$args";
String code = "{ " +
" boolean handled = false;" +
" try{" +
" if (currentAdvisor != null) {" +
" org.jboss.aop.MethodInfo mi = currentAdvisor.getMethodInfo(" + hash.longValue() + "L); " +
" if (mi == null) " +
" throw new java.lang.NoSuchMethodError(\"" + m.getName() + m.getSignature() + "\");" +
" org.jboss.aop.advice.Interceptor[] interceptors = mi.getInterceptors(); " +
" if (interceptors != (Object[])null && interceptors.length > 0) { " +
" handled = true;" +
" org.jboss.aop.proxy.container.ContainerProxyMethodInvocation invocation = new org.jboss.aop.proxy.container.ContainerProxyMethodInvocation(mi, interceptors, this); " +
" invocation.setArguments(" + args + "); " +
" invocation.setTargetObject(delegate); " +
" invocation.setMetaData(metadata);" +
" " + aopReturnStr + " invocation.invokeNext(); " +
" }" +
" }" +
" if (!handled && delegate != null){ " +
" " + returnStr + " delegate." + name + "($$); " +
" }" +
" return " + getNullType(m.getReturnType()) + ";" +
" }finally{" +
" }" +
"}";
CtMethod newMethod = CtNewMethod.make(m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes(), code, proxy);
newMethod.setModifiers(Modifier.PUBLIC);
proxy.addMethod(newMethod);
copyAnnotations(m, newMethod);
copySignature(m, newMethod);
}