[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Getting the reference to an annotated class
|
Hi,
I got that doubt only because my other pointcut threw a null pointer exception.
after() : call ( public PersonalDetail.new(..) ){
System.out.println( "Call [" + thisJoinPoint.getThis() + "]");
(( PersonalDetail )thisJoinPoint.getThis())
.setDao( DAOFactory.getDAOFactory
( 2 ).getAddressDAO() );
}
and this one did not match
after( PersonalDetail p ) : call ( public PersonalDetail.new(..) )&& this( p ){
System.out.println( "Call [" + thisJoinPoint.getThis() + "]");
(( PersonalDetail )thisJoinPoint.getThis())
.setDao( DAOFactory.getDAOFactory( 2 ).getAddressDAO() );
}
Thanks,
Mohan
On 2/14/06, Eric Bodden <eric.bodden@xxxxxxxxxxxxxx> wrote:
> but could not write thisJoinPoint.getThis().setDao(
> DAOFactory.getDAOFactory( 2 ).getAddressDAO() ); becuase
> thisJoinPoint.getThis()
> returns an Object.
You have to simply cast it to the interface/class you require.
thisJoinPoint has no knowledge about the class, hence it can only return
Object.
So try:
after( Entity e ) : execution ( PersonalDetail.new(..) ) && annotation(
e ){ .....
PersonalDetail = (PersonalDetail) thisJoinPoint.getThis();
}
You should not use *.new(..) in stat case because that could also bind
"this" to other types if they have the Entity annotation, which would
make your cast fail.
If PersonalDetail is still too specific for you in the signature, then
you have to create some interface in between. You do need some
information about the type you are working on - otherwise you cannot add
a reference.
Eric
--
Eric Bodden
Sable Research Group, McGill University
Montreal, Canada
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users