
|
point cut on:: Annotated field + new ArrayList()
hi, Any update on this please. Issue:1. I have a variable defined with annotation 2, This variable is being assigned to an ArrayList Now, i want to intercept this call and execute a logic by AOP. In the interception
1. I should be able to access the annotated value 2. Return a new object called MYLIst The below mail therad is abt the same, 1. If i use set(* *List) then i cant access the annotation 2. If i use the below its (in eclipse) is throwing compilation errors
pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in); ArrayList around( LIST in) :listCut(in){ System.out.println("**annotation " + thisJoinPoint + " ann:"
+ in.value()); return new MyList(); } The java class i want to intercept:: public static void main(String[] argv) { UserAttributes u = new UserAttributes();
u.alias = new ArrayList(); } Any ideas where i am going wrong? Please help.Regards, Ravi ---------- Forwarded message ---------- From: Ravi Chandra <ravi.eze@...>
Date: Sun, Jun 21, 2009 at 7:23 PM Subject: Re: [aspectj-users] (no subject) To: aspectj-users@...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@...> 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@...
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@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
Hi Ravi, I believe that your problem is that the return type for your around advice is ArrayList, whereas it should be Object. The reason is that since you are not specifying that the field being set must be of type List+, the pointcut can theoretically be applied to any field of any type. Hence, the incompatible return type error.
Hope this helps, --a On Mon, Jun 22, 2009 at 10:58 AM, Ravi Chandra <ravi.eze@...> wrote:
Issue: 1. I have a variable defined with annotation 2, This variable is being assigned to an ArrayList
Now, i want to intercept this call and execute a logic by AOP. In the interception
1. I should be able to access the annotated value 2. Return a new object called MYLIst
The below mail therad is abt the same, 1. If i use set(* *List) then i cant access the annotation 2. If i use the below its (in eclipse) is throwing compilation errors
pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in);
ArrayList around( LIST in) :listCut(in){ System.out.println("**annotation " + thisJoinPoint + " ann:"
+ in.value()); return new MyList(); }
The java class i want to intercept::
public static void main(String[] argv) { UserAttributes u = new UserAttributes();
u.alias = new ArrayList(); }
Any ideas where i am going wrong? Please help.
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
hi, its not working. java class:public class UserAttributes implements Interceptable { @LIST(3) private ArrayList<String> alias; public static void main(String[] argv) {
UserAttributes u = new UserAttributes(); u.alias = new ArrayList(); // point 1 } } point cut:public aspect INAspect { pointcut annCut(LIST in) : set(@LIST* (*) * ) && @annotation(in) && target(java.util.List+);
//this should return the new MYList(); I also want the annotation to be accessible here (i.e.. cutting :: point 1). after(LIST in) :annCut(in) && within(com.pg.interceptor.Interceptable+) {
System.out.println("**annotation " + thisJoinPoint + " ann:" + in.value()); // return new PGList(); } any ideas please? :( ravi
On Tue, Jun 23, 2009 at 12:35 AM, Andrew Eisenberg <andrew@...> wrote:
Hi Ravi,
I believe that your problem is that the return type for your around advice is ArrayList, whereas it should be Object.
The reason is that since you are not specifying that the field being set must be of type List+, the pointcut can theoretically be applied to any field of any type. Hence, the incompatible return type error.
Hope this helps, --aOn Mon, Jun 22, 2009 at 10:58 AM, Ravi Chandra <ravi.eze@...> wrote:
Issue: 1. I have a variable defined with annotation 2, This variable is being assigned to an ArrayList
Now, i want to intercept this call and execute a logic by AOP. In the interception
1. I should be able to access the annotated value 2. Return a new object called MYLIst
The below mail therad is abt the same, 1. If i use set(* *List) then i cant access the annotation 2. If i use the below its (in eclipse) is throwing compilation errors
pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in);
ArrayList around( LIST in) :listCut(in){ System.out.println("**annotation " + thisJoinPoint + " ann:"
+ in.value()); return new MyList(); }
The java class i want to intercept::
public static void main(String[] argv) { UserAttributes u = new UserAttributes();
u.alias = new ArrayList(); }
Any ideas where i am going wrong? Please help.
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
hi, Any update please? Am i putting a wrong qn?/ should i be more clear some where?/ is this not possible at all???/ do we have any work arounds for such scenarios? kindly hlep.
On Mon, Jun 22, 2009 at 11:28 PM, Ravi Chandra <ravi.eze@...> wrote:
hi,
Any update on this please.
Issue: 1. I have a variable defined with annotation 2, This variable is being assigned to an ArrayList
Now, i want to intercept this call and execute a logic by AOP. In the interception
1. I should be able to access the annotated value 2. Return a new object called MYLIst
The below mail therad is abt the same, 1. If i use set(* *List) then i cant access the annotation 2. If i use the below its (in eclipse) is throwing compilation errors
pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in);
ArrayList around( LIST in) :listCut(in){ System.out.println("**annotation " + thisJoinPoint + " ann:"
+ in.value()); return new MyList(); }
The java class i want to intercept::
public static void main(String[] argv) { UserAttributes u = new UserAttributes();
u.alias = new ArrayList(); }
Any ideas where i am going wrong? Please help.
Regards, Ravi
---------- Forwarded message ---------- From: Ravi Chandra <ravi.eze@...>
Date: Sun, Jun 21, 2009 at 7:23 PM Subject: Re: [aspectj-users] (no subject) To: aspectj-users@...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@...> 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@...
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@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
Any update please? :( On Mon, Jun 22, 2009 at 11:28 PM, Ravi Chandra <ravi.eze@...> wrote:
hi,
Any update on this please.
Issue: 1. I have a variable defined with annotation 2, This variable is being assigned to an ArrayList
Now, i want to intercept this call and execute a logic by AOP. In the interception
1. I should be able to access the annotated value 2. Return a new object called MYLIst
The below mail therad is abt the same, 1. If i use set(* *List) then i cant access the annotation 2. If i use the below its (in eclipse) is throwing compilation errors
pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in);
ArrayList around( LIST in) :listCut(in){ System.out.println("**annotation " + thisJoinPoint + " ann:"
+ in.value()); return new MyList(); }
The java class i want to intercept::
public static void main(String[] argv) { UserAttributes u = new UserAttributes();
u.alias = new ArrayList(); }
Any ideas where i am going wrong? Please help.
Regards, Ravi
---------- Forwarded message ---------- From: Ravi Chandra <ravi.eze@...>
Date: Sun, Jun 21, 2009 at 7:23 PM Subject: Re: [aspectj-users] (no subject) To: aspectj-users@...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@...> 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@...
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@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
Any update please? :(
Did this not work for you?
On Tue, Jun 23, 2009 at 8:47 AM, Andrew Eisenberg <andrew@...> wrote:
You are using target, where you should be using args.On Mon, Jun 22, 2009 at 7:40 PM, Ravi Chandra <ravi.eze@...> wrote:
pointcut annCut(LIST in) : set(@LIST* (*) * ) && @annotation(in) && target(java.util.List+);
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
Here is a working solution: public aspect INAspect { pointcut listCut(ArrayList value, LIST in ) : set(@LIST * * ) && args(value) && @annotation(in); void around(ArrayList value, LIST in) :listCut(value,in) {
System.out.println("**annotation " + thisJoinPoint + " ann:" + in.value()); proceed(new MyList(),in); } }
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
This way you are pointcutting the field variable. How does it return/ set the variable to new MyList() back?. In other words if i say System.out.println('class::' + u.alias.getClass() );// we are point cutting u.alias variable
its not printing MyList; instead its showing ArrayList. any ideas? Are ther any standard tutorials available on the net by which we can get such problems clarified? Googling hardly helps. Any ideas/ links... kindly help.
ravi On Fri, Jun 26, 2009 at 9:57 PM, Andy Clement <andrew.clement@...> wrote:
Here is a working solution:
public aspect INAspect {
pointcut listCut(ArrayList value, LIST in ) : set(@LIST * * ) && args(value) && @annotation(in);
void around(ArrayList value, LIST in) :listCut(value,in) {
System.out.println("**annotation " + thisJoinPoint + " ann:" + in.value());
proceed(new MyList(),in); }
}
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
Sorry, Its working as i wanted. i added an extra field while experimenting with things and that one is not cutting the field call at all which led to this confusion Andy Clement Thank u for ur help. :)
Sorry for the noise. On Sat, Jun 27, 2009 at 4:55 PM, Ravi Chandra <ravi.eze@...> wrote:
This way you are pointcutting the field variable. How does it return/ set the variable to new MyList() back?. In other words if i say
System.out.println('class::' + u.alias.getClass() );// we are point cutting u.alias variable
its not printing MyList; instead its showing ArrayList.
any ideas?
Are ther any standard tutorials available on the net by which we can get such problems clarified? Googling hardly helps. Any ideas/ links... kindly help.
ravi
Here is a working solution: public aspect INAspect { pointcut listCut(ArrayList value, LIST in ) : set(@LIST * * ) && args(value) && @annotation(in); void around(ArrayList value, LIST in) :listCut(value,in) {
System.out.println("**annotation " + thisJoinPoint + " ann:" + in.value());
proceed(new MyList(),in); } }
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|

|
Re: point cut on:: Annotated field + new ArrayList()
The proceed() call in the around advice proceeds to do whatever was intended at the join point originally. Because it is a 'set' join point, the proceed will proceed to set the field being intercepted, so if we supply a different value in the proceed call, the field will be set to that instead.
Andy 2009/6/27 Ravi Chandra <ravi.eze@...>
This way you are pointcutting the field variable. How does it return/ set the variable to new MyList() back?. In other words if i say
System.out.println('class::' + u.alias.getClass() );// we are point cutting u.alias variable
its not printing MyList; instead its showing ArrayList.
any ideas?
Are ther any standard tutorials available on the net by which we can get such problems clarified? Googling hardly helps. Any ideas/ links... kindly help.
ravi
Here is a working solution: public aspect INAspect { pointcut listCut(ArrayList value, LIST in ) : set(@LIST * * ) && args(value) && @annotation(in); void around(ArrayList value, LIST in) :listCut(value,in) {
System.out.println("**annotation " + thisJoinPoint + " ann:" + in.value());
proceed(new MyList(),in); } }
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users
|