-
1. Re: A single AspectFactory across multiple Aspects?
flaviarnn Jun 6, 2005 9:37 PM (in response to neil_g_avery)Hi, Neil,
I think meta data could do the trick, but there is a simpler way.
Your aspect factory could implement the org.jboss.util.xml.XmlLoadable interface.
This interface contains the method
public void importXml(org.w3c.dom.Element element)
If you do this, JBoss AOP will call this method after instatiating your Aspect Factory, passing as argument the xml element used to declare your aspect factory in the jboss-aop.xml file.
This way, your jboss-aop.xml could look like this:<aspect name="Aspect1" class "my.aspect1l" factory="MyJBossAOPFactory" scope="PER_CLASS"> <anyTagy>Aspect1</anyTag> </aspect> <aspect name="Aspect2" class "my.aspect2" factory="MyJBossAOPFactory" scope="PER_CLASS"> <anyTag>Aspect2</anyTag> </aspect>
And your MyJBossAOPFactory.importXml method could retrieve the "anyTag" contents in order to determine the aspect context (i.e. the class).
Regards
Flavia -
2. Re: A single AspectFactory across multiple Aspects?
neil_g_avery Jun 7, 2005 4:26 AM (in response to neil_g_avery)Excellent - thats exactly what I need,
Thankyou. -
3. Re: A single AspectFactory across multiple Aspects?
flaviarnn Jun 7, 2005 9:02 AM (in response to neil_g_avery)You're welcome, but... it seems that I gave you a redundant solution.
Actually, you don't need to place 'anyTag' inside the 'aspect' element, because you can retrieve the aspect name from your MyJBossAOPFactory.importXml method. If you convention that the aspect name is always the name of the aspect class (the context you want to access), the anyTag is redundant. Just add tags inside aspect elements if it adds useful information to your MyJBossAOPFactory.
Besides, you should remove the class attribute from the aspect element, otherwise JBoss AOP will throw an exception, warning that you cannot define both class and factory attributes (the first one should be used to define an aspect class, not an aspect factory).
So, your jboss-aop.xml file should look like this:<aspect name="Aspect1" factory="MyJBossAOPFactory" scope="PER_CLASS"/> <aspect name="Aspect2" factory="MyJBossAOPFactory" scope="PER_CLASS"/>
Or like this, if you need package information (which probably you do):<aspect name="yourPackage.Aspect1" factory="MyJBossAOPFactory" scope="PER_CLASS"/> <aspect name="yourPackage.Aspect2" factory="MyJBossAOPFactory" scope="PER_CLASS"/>
Regards
Flavia