|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
EMF and AOP (spring like?)Hi,
currently, I am adding what some AOP like features too my EMF (http://www.eclipse.org/modeling/emf/) application. I realized I am reinventing aspectJ and I wonder if I can use aspectJ. A simplified view of EMF: a ECore model defines objects with attributes: class Person { attr String name; } EMF can run in two modes: generated code and reflective. In case of code generation the following code would be generated for the above ecore model: public class Person { protected String name; public String getName() { return name; } public setName(String newName) { name=newName; // some code to notify listeners } } Here one could use normal aspectJ. What interests me more is the reflective case. In the case of reflective EMF instance would have to be used like this (simplified version): name=person.eGet("name"); // in reality the attribute name is not string person.eSet("name", "Michael"); Essentially, any access of EMF objects funneled through the eGet/eSet methods. I want to define some advices for some of the getters and setters. E.g. an advice for supplying some calculated default value on the getter: @Aspect public class DefaultExample { @Around("com.xyz.myapp.Person.getName()") public Object addDefault(ProceedingJoinPoint jp) throws Throwable { EObject target=(EObject)jp.getTarget(); // I somehow need to get to the structurel feature representing // the "name" attribute EStructuralFeature attribute=EMFAspectJHelper.getAttribute(jp) if(!target.eIsSet(attribute) return "My calculated default Value"; return jp.proceed(); } } I have found the docu for spring AOP http://static.springframework.org/spring/docs/2.5.x/reference/aop.html I have never used spring but it seems they use some aspectJ library to implement AOP for spring. So, here is my question: Is it possible to use AOP in way that I could add aspects to some reflective API like EMF? I mean is there some calls I could make in the eGet/eSet methods to weave in aspects? Here is how envision how this could work: Suppose I create a subclass of EObjectImpl (the class that defines eGet/eSet). All eSet/eGet would be handeled by my class. This class would then be used for all dynamic access eGet/eSet: // a class that adds AOP to dynamic EMF class AopEObjectImpl extends EObjectImpl { // the magic from aspectJ MagicAspectJ aspectj; @Override public Object eGet(EStructuralFeature feature) { // let aspecJ doo the call for me. In case // the original method is needed // (JointPoint.proceed()), call eOriginalGet. return aspectj.call(buildGetSignature(feature)); } // this calls the original get method public Object eOriginalGet(EStructuralFeature feature) { return super.eGet(feature); } private Signature buildGetSignature(EStructuralFeature feature) { // somehow create the signature like "com.xyz.myapp.Person.getName()" return signature; } } The MagicAspectJ would then do the magic for me of looking for aspects and call the aspects that I have registered with MagicAspectJ... Am I dreaming here? Does aspectJ provide a way of using aspects for dynamically called methods? Any docu or example I can start with? Michael -- Michael Scharf Wind River Systems GmbH http://www.WindRiver.com http://MichaelScharf.blogspot.com/ _______________________________________________ aspectj-users mailing list aspectj-users@... https://dev.eclipse.org/mailman/listinfo/aspectj-users |
|
|
Re: EMF and AOP (spring like?)Hi Michael,
If I understand you correctly, you would like to use AspectJ on an EMF-generated library. You would like to advise the eGet and eSet methods on the generated classes that are accessed using reflection. If this is what you are looking to do, then there shouldn't be any problem using AspectJ. Write your advice to advise the execution of the desired eGet and eSet methods. Place the generated EMF code on the inpath of your aspect library. This will perform binary weaving of the EMF code. I am not exactly sure how EMF works in reflective mode, but perhaps your advice will look something like: Object around(EStructuralFeature feature) : EObjectImpl.eGet(EStructuralFeature) && args(feature) : { ... } --a On Fri, Oct 3, 2008 at 7:18 PM, Michael Scharf <Michael-Scharf@...> wrote: > Hi, > > currently, I am adding what some AOP like features > too my EMF (http://www.eclipse.org/modeling/emf/) > application. I realized I am reinventing aspectJ > and I wonder if I can use aspectJ. > > A simplified view of EMF: a ECore model defines objects with > attributes: > > class Person { > attr String name; > } > > EMF can run in two modes: generated code and reflective. > In case of code generation the following code would be > generated for the above ecore model: > > public class Person { > protected String name; > public String getName() { > return name; > } > public setName(String newName) { > name=newName; > // some code to notify listeners > } > > } > > Here one could use normal aspectJ. What interests me more is > the reflective case. In the case of reflective EMF instance > would have to be used like this (simplified version): > > name=person.eGet("name"); // in reality the attribute name is not string > person.eSet("name", "Michael"); > > Essentially, any access of EMF objects funneled through the eGet/eSet > methods. > > I want to define some advices for some of the getters and setters. > E.g. an advice for supplying some calculated default value on the > getter: > > @Aspect > public class DefaultExample { > > @Around("com.xyz.myapp.Person.getName()") > public Object addDefault(ProceedingJoinPoint jp) throws Throwable { > EObject target=(EObject)jp.getTarget(); > // I somehow need to get to the structurel feature representing > // the "name" attribute > EStructuralFeature attribute=EMFAspectJHelper.getAttribute(jp) > if(!target.eIsSet(attribute) > return "My calculated default Value"; > return jp.proceed(); > } > } > > I have found the docu for spring AOP > http://static.springframework.org/spring/docs/2.5.x/reference/aop.html > I have never used spring but it seems they use some aspectJ library > to implement AOP for spring. > > So, here is my question: Is it possible to use AOP in way that I > could add aspects to some reflective API like EMF? I mean is there > some calls I could make in the eGet/eSet methods to weave in aspects? > > Here is how envision how this could work: Suppose I create a subclass > of EObjectImpl (the class that defines eGet/eSet). All eSet/eGet > would be handeled by my class. This class would then be used > for all dynamic access eGet/eSet: > > // a class that adds AOP to dynamic EMF > class AopEObjectImpl extends EObjectImpl { > // the magic from aspectJ > MagicAspectJ aspectj; > @Override > public Object eGet(EStructuralFeature feature) { > // let aspecJ doo the call for me. In case > // the original method is needed > // (JointPoint.proceed()), call eOriginalGet. > return aspectj.call(buildGetSignature(feature)); > } > // this calls the original get method > public Object eOriginalGet(EStructuralFeature feature) { > return super.eGet(feature); > } > private Signature buildGetSignature(EStructuralFeature feature) { > // somehow create the signature like "com.xyz.myapp.Person.getName()" > return signature; > } > } > > The MagicAspectJ would then do the magic for me of looking for > aspects and call the aspects that I have registered with > MagicAspectJ... > > Am I dreaming here? Does aspectJ provide a way of using > aspects for dynamically called methods? > Any docu or example I can start with? > > Michael > > -- > Michael Scharf > Wind River Systems GmbH > http://www.WindRiver.com > http://MichaelScharf.blogspot.com/ > > _______________________________________________ > 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: EMF and AOP (spring like?)Hi Andrew,
maybe my question is more for the aspectj-dev list: I want to implement a new type of advice that does not act at the level of java interfaces. Instead I'd like to add it to the objects created and defined by EMF. This is probably similar to adding aspects to a scripting language embedded in java. I know how to add advice to the eGet/eSet methods. But I want to use the aspectj pointcut syntax to access methods that are dynamically called. The methods may exist as java methods. They are only available reflectively by the eGet/eSet methods... Michael > Hi Michael, > > If I understand you correctly, you would like to use AspectJ on an > EMF-generated library. You would like to advise the eGet and eSet > methods on the generated classes that are accessed using reflection. > If this is what you are looking to do, then there shouldn't be any > problem using AspectJ. > > Write your advice to advise the execution of the desired eGet and eSet > methods. Place the generated EMF code on the inpath of your aspect > library. This will perform binary weaving of the EMF code. > > I am not exactly sure how EMF works in reflective mode, but perhaps > your advice will look something like: > > Object around(EStructuralFeature feature) : > EObjectImpl.eGet(EStructuralFeature) && args(feature) : { ... } > > --a > > On Fri, Oct 3, 2008 at 7:18 PM, Michael Scharf <Michael-Scharf@...> wrote: >> Hi, >> >> currently, I am adding what some AOP like features >> too my EMF (http://www.eclipse.org/modeling/emf/) >> application. I realized I am reinventing aspectJ >> and I wonder if I can use aspectJ. >> >> A simplified view of EMF: a ECore model defines objects with >> attributes: >> >> class Person { >> attr String name; >> } >> >> EMF can run in two modes: generated code and reflective. >> In case of code generation the following code would be >> generated for the above ecore model: >> >> public class Person { >> protected String name; >> public String getName() { >> return name; >> } >> public setName(String newName) { >> name=newName; >> // some code to notify listeners >> } >> >> } >> >> Here one could use normal aspectJ. What interests me more is >> the reflective case. In the case of reflective EMF instance >> would have to be used like this (simplified version): >> >> name=person.eGet("name"); // in reality the attribute name is not string >> person.eSet("name", "Michael"); >> >> Essentially, any access of EMF objects funneled through the eGet/eSet >> methods. >> >> I want to define some advices for some of the getters and setters. >> E.g. an advice for supplying some calculated default value on the >> getter: >> >> @Aspect >> public class DefaultExample { >> >> @Around("com.xyz.myapp.Person.getName()") >> public Object addDefault(ProceedingJoinPoint jp) throws Throwable { >> EObject target=(EObject)jp.getTarget(); >> // I somehow need to get to the structurel feature representing >> // the "name" attribute >> EStructuralFeature attribute=EMFAspectJHelper.getAttribute(jp) >> if(!target.eIsSet(attribute) >> return "My calculated default Value"; >> return jp.proceed(); >> } >> } >> >> I have found the docu for spring AOP >> http://static.springframework.org/spring/docs/2.5.x/reference/aop.html >> I have never used spring but it seems they use some aspectJ library >> to implement AOP for spring. >> >> So, here is my question: Is it possible to use AOP in way that I >> could add aspects to some reflective API like EMF? I mean is there >> some calls I could make in the eGet/eSet methods to weave in aspects? >> >> Here is how envision how this could work: Suppose I create a subclass >> of EObjectImpl (the class that defines eGet/eSet). All eSet/eGet >> would be handeled by my class. This class would then be used >> for all dynamic access eGet/eSet: >> >> // a class that adds AOP to dynamic EMF >> class AopEObjectImpl extends EObjectImpl { >> // the magic from aspectJ >> MagicAspectJ aspectj; >> @Override >> public Object eGet(EStructuralFeature feature) { >> // let aspecJ doo the call for me. In case >> // the original method is needed >> // (JointPoint.proceed()), call eOriginalGet. >> return aspectj.call(buildGetSignature(feature)); >> } >> // this calls the original get method >> public Object eOriginalGet(EStructuralFeature feature) { >> return super.eGet(feature); >> } >> private Signature buildGetSignature(EStructuralFeature feature) { >> // somehow create the signature like "com.xyz.myapp.Person.getName()" >> return signature; >> } >> } >> >> The MagicAspectJ would then do the magic for me of looking for >> aspects and call the aspects that I have registered with >> MagicAspectJ... >> >> Am I dreaming here? Does aspectJ provide a way of using >> aspects for dynamically called methods? >> Any docu or example I can start with? >> >> Michael >> >> -- >> Michael Scharf >> Wind River Systems GmbH >> http://www.WindRiver.com >> http://MichaelScharf.blogspot.com/ >> >> _______________________________________________ >> 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 > -- Michael Scharf Wind River Systems GmbH http://www.WindRiver.com http://MichaelScharf.blogspot.com/ _______________________________________________ aspectj-users mailing list aspectj-users@... https://dev.eclipse.org/mailman/listinfo/aspectj-users |
|
|
|
| Free Forum Powered by Nabble | Forum Help |