Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] static introduction in interfaces

Hi all,


I wrote a persistence managing aspect for entity beans in a J2EE environment for my master thesis. It uses bean managed persistence but all code to do this is contained in an aspect written in AspectJ.

While reviewing my code I came across the following problem: it isn't possible to declare static fields in an interface. I would use it like this:

declare parents : (LoanerBean || CdBean || BookBean ||
       ItemBean || LoanBean || LoanableBean)
	implements PersistentEntityBean;

// PersistentEntityBean is an interface
static String PersistentEntityBean.dbName = null;

1) If I don't declare it static, every EJB that implements PersistentEntityBean has its own field dbName.

2) If I make PersistentEntityBean an empty class with all the beans extending this class, all beans share the same field dbName (e.g. always BookBean.dbName == CdBean.dbName).

3) Declaring a static field on an interface could make it possible to introduce this field in all beans, but with every bean having a different static field dbName. All instances of a particular bean (e.g. CdBean) would share the static dbName, but CdBean.dbName would be different from BookBean.dbName.

An alternative approach could be to be able to do something like this:

static String (BookBean || CdBean || [other classes]).dbName = null;

This is however also not possible (and would imply the use of reflection).


Using solution 2 with the empty class, but with dbName not declared static, it is possible to do something like this:

Collection around (PersistentEntityBean eb) : execution(Collection ejbFind*(..)) && target (eb){
   System.out.println(eb.dbName);
}

Since the field dbName is declared on the parent class PersistentEntityBean. Would this also be possible if the dbName field were declared static in an interface (if that was possible)?
If not, it would still be possible to get the dbName with reflection:

System.out.println(eb.getClass().getField("dbName").get(eb));

But that is not preferable.


Thanks in advance,
Jan.


Back to the top