[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Can I do any of these 3 things with aspectJ
|
Hi Guys
I have 3 questions and would be great if you have any comments or
suggestions on these.
Question 1 : If, my requirement is to return a different instance (say
instantiating overloaded constructor) of an object whose default
constructor is called. Can I do that with aspectJ. The limitation is that
I do not want to use call() pointcut, (as this needs the caller's to be
included in weaving though source or binary and I do not have control
over the usages of my framework).
Question 2 : If we use inter-type declaration's for let us say adding
method's to existing classes, what I understood that you cannot define
methods for more than one class in one decleration. For example (1) is
what is possible, IS (2) possible to achieve somehow.? I do not want to
define the same behaviour for every class. I want every class for a
package to get this method added with same behaviour. To achieve this
kind of result, I also tried private interface, but landed in a problem
again which is question 3.
(1)---- public int Point.getX() { return this.x; }
(2) -- public int com.x.y.*.getX() { return this.x; }
Question 3 : When I tried a private interface, I had a problem again: The
problem is "this" which is explicitly available in the method definition
of the private interface, does seem have limitations. The code I was
trying is below (for simplicity this is the main purpose of code). The
probelm is that, I am using reflection to set instance field
WHICH_IS_PRIVATE and you can only do that from the same class using
"this"(as far as I am aware of), so i thought the below solution might
work.? But it didn't, as the weaving is not done as-is but rather through
references (Obviously I had to de-compile to figure out what's
happening), may be in most cases the waeving works but not in this case
or I am doing something wrong:
private interface MyInterface {}
declare parents: com.x.y.MyComponent implements MyInterface ;
public pointcut populate(java.lang.Object o) : execution(*.new()) && this(o) && within(com.x.y.MyComponent);
public void MyInterface.setMember(Object memberValue){
/**
Using reflection I got the field object of, one of instance field
defined in MyComponent class.And I try to set this with the memberValue
argument using the field.set(this,memberValue)
**/
Field field = SomeService.getField();
try{
field.set(this,memberValue);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
after (java.lang.Object o) : populate(o) {
MyInterface myInterfaceAwareObject = (MyInterface)o;
myInterfaceAwareObject.setMember($some_value);
}
I would really appreciate any comments on these issues or suggestions.
Thanks in advance
Tarun
--
Tarun Sharma
t_sharma@xxxxxxxxxxxx
--
http://www.fastmail.fm - One of many happy users:
http://www.fastmail.fm/docs/quotes.html