[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] (no subject)
|
hi,
That was an intelligent soln.
But, I have annotations on each of the fields( i didnt mention this previously) and during the interception by AOP i would like to access the annotated info also.
Original Class:public class UserAttributes implements Interceptable {
@IN(3)
private List<String> alias;
public int getAge() {
return age;
}
public static void main(String[] argv) {
UserAttributes u = new UserAttributes();
u.alias = new ArrayList();
u.children = new HashMap<String, String>();
}
}
and i tried: pointcut annCut(Interceptable m, IN in):target(m) && set(@IN* (*) * ) && @annotation(in);
pointcut annListCut(Interceptable m, IN in) : cflow(annCut(m,in)) && cflow(listCut()) && target(Interceptable+);
after/ Around (Interceptable m, IN in): annListCut(m,in){
//here i should be able to get the fields annotation + return MYList object System.out.println("point cut + annotation is.." + in.value());
}
But this is cutting off public int getAge() {
return age;
}
method also,
which is not intended. Any ideas please..
regards,
ravi
On Sun, Jun 21, 2009 at 3:40 PM, Simone Gianni
<simoneg@xxxxxxxxxx> wrote:
Hi Ravi,
you can declare a pointcut around the creation of any ArrayList, returning MyArrayList as long as they are assign-compatible.
That means that as long as :
public class MyArrayList extends ArrayList { ...
you can write :
ArrayList around() : call(* ArrayList.new()) {
return new MyArrayList();
}
This will replace do the trick. You can narrow it down to some classes using within, withincode etc..
ArrayList around() : call(* ArrayList.new()) && within(com.mycompany.*) {
return new MyArrayList();
}
And you can add other advice to add parameters :
ArrayList around(int size) : call(* ArrayList.new(int)) && args(size) {
return new MyArrayList(size);
}
etc...
In my Apache Magma Lab I use this kind of advice extensively to offer a simpler alternative to the factory pattern/dependency injection/context pollution.
Hope this helps,
Simone
Ravi Chandra wrote:
hi,
I am trying hard to get a solution to this problem since last 4 days.. but no luck; the issue is as below:
I have java classes of this form
public class UserAttributes implements Interceptable {
private List<String> alias;
private void someMethod(){
*alias = new ArrayList(); // point 1*
.... etc etc
}
}
Now the problem is :
When ever a variable is assigned to new ArrayList() i want it to be changed to new MyArrayList() instead
i.e..: the point 1 above changes to an eqvivalent of
*alias = new MYArrayList();*
I am able to get this done
aspect abc {
pointcut listCut(Interceptable m, IN in):target(m) && set(java.util.List+ *);
after(Interceptable m, IN in):listCut(m,in){
*UserAttributes.setAlias( new MyArrayList());*
}
}
*but the point cut is getting very class specific. *I have abt 1000 classes which have to be modified this way where ever the ArrayList is being used, now with this approach i need to write 1000 files; isnt there a generic way to do this?
Any pointers/ help ? please suggest.
regards,
ravi
------------------------------------------------------------------------
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
Simone Gianni CEO Semeru s.r.l. Apache Committer
http://www.simonegianni.it/
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users