[jboss-dev-forums] [Design of AOP on JBoss (Aspects/JBoss)] - Creation of method tables in ClassAdvisor
jaikiran
do-not-reply at jboss.com
Wed May 13 08:57:30 EDT 2009
Need some input on a couple of things in the org.jboss.aop.ClassAdvisor http://anonsvn.jboss.org/repos/jbossas/projects/aop/branches/Branch_2_1/aop/src/main/java/org/jboss/aop/ClassAdvisor.java. During initialization and creation of method tables, the ClassAdvisor in it's addDeclaredMethod does this:
| protected void addDeclaredMethods(Class<?> superclass) throws Exception
| {
| Method[] declaredMethods = superclass.getDeclaredMethods();
| for (int i = 0; i < declaredMethods.length; i++)
| {
| if (ClassAdvisor.isAdvisable(declaredMethods[ i]))
| {
| long hash = MethodHashing.methodHash(declaredMethods[ i]);
| advisedMethods.put(hash, declaredMethods[ i]);
| try
| {
| Method m = declaredMethods[ i];
| Method un = superclass.getDeclaredMethod(ClassAdvisor.notAdvisedMethodName(superclass.getName(),
| m.getName()),
| m.getParameterTypes());
| un.setAccessible(true);
| unadvisedMethods.put(hash, un);
| }
| catch (NoSuchMethodException ignored)
| {
| }
| }
| }
| }
|
| public static String notAdvisedMethodName(String className,
| String methodName)
| {
| return className.replace('.', '$') + "$" + methodName +
| NOT_TRANSFORMABLE_SUFFIX;
| }
|
| /**
| * Suffix added to unadvised methods.
| */
| public static final String NOT_TRANSFORMABLE_SUFFIX = "$aop";
|
|
|
Assuming i have this expression:
| <domain name="XXX" extends="YYY" inheritBindings="true">
| <bind pointcut="execution(public * *->*(..))">
| ...
| </bind>
|
| package org.myapp;
|
|
| public class SomeClass
| {
| public void method1()
| {
| ..
| }
|
| public void method2()
| {
| ..
| }
| }
|
1) So the addDeclaredMethod piece of code, above, is going to generate for each method an "unadvised method name" as:
| org$myapp$SomeClass$method1$aop
| org$myapp$SomeClass$method2$aop
|
and later on when the
| superclass.getDeclaredMethod(ClassAdvisor.notAdvisedMethodName(superclass.getName(), m.getName()),m.getParameterTypes());
|
is called it's always going to throw a NoSuchMethodException, isn't it?
What is the purpose of this code? I guess, there is some specific scenario where this comes into picture
2) The MethodHashing.methodHash() does some very specific/involved logic. How is it different from a normal method.hashCode()?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4230825#4230825
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4230825
More information about the jboss-dev-forums
mailing list