Defining metadata in jboss-aop.xml
sushmam Dec 13, 2004 7:36 AMHi,
I have two classes - POJO.java, and TEST.java. I have only one interceptor class which just gets the metadata associated with the invocation object and prints it.
I have defined a constructor level metadata only for the POJO class, but this gets called, even for the TEST class. How can I make the constructor-metadata specific only to POJO class?
Given below are the extracts from jboss-aop.xml, BillingInterceptor class, POJO and TEST classes.
a) jboss-aop.xml
<?xml version="1.0" encoding="UTF-8"?> <aop> <!-- Metadata --> <metadata tag="mdTest" class="*"> <constructor class="POJO" expr="POJO()"> <my-attribute># Pojo constructor</my-attribute> </constructor> <method name="someMethod"> <my-attribute>Let us start</my-attribute> </method> <method name="secondMethod"> <my-attribute>secondMethod</my-attribute> </method> </metadata> <!-- Pointcuts --> <bind pointcut="execution(POJO->new())"> <interceptor class="BillingInterceptor"/> </bind> <bind pointcut="execution(* POJO->someMethod(..))"> <interceptor class="BillingInterceptor"/> </bind> <bind pointcut="execution(TEST->new())"> <interceptor class="BillingInterceptor"/> </bind> <bind pointcut="execution(* TEST->secondMethod(..))"> <interceptor class="BillingInterceptor"/> </bind> </aop>
b) BillingInterceptor.java
public class BillingInterceptor implements Interceptor { public String getName() { return "BillingInterceptor"; } public Object invoke(Invocation invocation) throws Throwable { System.out.println("my-attribute : " + invocation.getMetaData("mdTest", "my-attribute")); return invocation.invokeNext(); } }
c) POJO.java
public class POJO { public POJO() { System.out.println("pojo empty constructor"); } public void someMethod(String str, int i, long l){ System.out.println("someMethod: str=" + str + ", int=" + i + ", long=" + l); } }
d) TEST.java
public class TEST { public TEST() { System.out.println("testcons"); } public void secondMethod(int newfoo) { System.out.println("in second Method --> " + newfoo); } }
The o/p when I run the above program is:
[java] --- new POJO(); --- [java] my-attribute : # Pojo constructor [java] pojo empty constructor [java] my-attribute : Let us start [java] someMethod: str=testSTr, int=5, long=55 [java] --- new TEST(); --- [java] my-attribute : # Pojo constructor [java] testcons [java] my-attribute : secondMethod [java] in second Method --> 567
The attribute # Pojo constructor is being printed out by both the constructors. How to make this specific to only POJO class? Any pointers in this regard will be greatly appreciated.
Thanks,
Sushma.