Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Intercept class loading
Intercept class loading [message #55297] Tue, 27 December 2005 10:14 Go to next message
Eclipse UserFriend
Originally posted by: scheglov_ke.nlmk.ru

I have some model beans that have getter/setter. Setter always should
do this steps for simple field assignment setter:

1) remember old value;
2) change field;
3) invoke firePropertyChange with old and new values.

I want remove 1) and 3) from beans and add them in runtime during
class loading. So, I have questions:

1. Is it possible in Eclipse? (I know one not very nice way - Java5 java
agent, but I don't like changing Java launch line).

2. May be there is already some better solution for property change
notifying?

--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)
Re: Intercept class loading [message #55324 is a reply to message #55297] Tue, 27 December 2005 11:03 Go to previous messageGo to next message
ted stockwell is currently offline ted stockwellFriend
Messages: 123
Registered: July 2009
Senior Member
Konstantin Scheglov wrote:
>
> I have some model beans that have getter/setter. Setter always should
> do this steps for simple field assignment setter:
>
> 1) remember old value;
> 2) change field;
> 3) invoke firePropertyChange with old and new values.
>
> I want remove 1) and 3) from beans and add them in runtime during
> class loading. So, I have questions:
>
> 1. Is it possible in Eclipse? (I know one not very nice way - Java5 java
> agent, but I don't like changing Java launch line).
>
> 2. May be there is already some better solution for property change
> notifying?
>

AspectJ is a good way to do this.
With AspectJ you can develop an 'aspect' that will perform steps 1) and 3).
AspectJ will then add the aspect to all your beans.

The AspectJ web page, http://eclipse.org/aspectj/, describes the AspectJ language.

The AspectJ Development Tools (AJDT) web page, http://www.eclipse.org/ajdt/, is an Eclipse plugin that makes it easy to use
AspectJ in the Eclipse IDE.
Re: Intercept class loading [message #55352 is a reply to message #55324] Tue, 27 December 2005 11:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: scheglov_ke.nlmk.ru

ted stockwell wrote:

>> I have some model beans that have getter/setter. Setter always
>> should do this steps for simple field assignment setter:
>>
>> 1) remember old value;
>> 2) change field;
>> 3) invoke firePropertyChange with old and new values.
>>
>> I want remove 1) and 3) from beans and add them in runtime during
>> class loading. So, I have questions:
>>
>> 1. Is it possible in Eclipse? (I know one not very nice way - Java5
>> java agent, but I don't like changing Java launch line).
>>
>> 2. May be there is already some better solution for property change
>> notifying?
>>
>
> AspectJ is a good way to do this.
> With AspectJ you can develop an 'aspect' that will perform steps 1) and 3).
> AspectJ will then add the aspect to all your beans.
>
> The AspectJ web page, http://eclipse.org/aspectj/, describes the AspectJ
> language.
>
> The AspectJ Development Tools (AJDT) web page,
> http://www.eclipse.org/ajdt/, is an Eclipse plugin that makes it easy to
> use AspectJ in the Eclipse IDE.

Ah, yes. How could I forget about aspects! I know about aspects, but
don't have any experience.

I think that AspectJ can help in 1) and 3), but now I have one dream -
don't have getters/setters at all. :-)
May be you know, is it possible generate new methods using AspectJ? I
see several possible problems:

1. I don't know if I can then use these generated method in my code. Not
using reflection, but just direct calls.

2. I use Hibernate, so would be good if I could still use it. May be add
annotations to fields plus one more annotation that tells AspectJ that I
need getter/setter for these fields.

All this is just dreams, I did not read documentation yet. :-)


--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)
Re: Intercept class loading [message #55379 is a reply to message #55352] Tue, 27 December 2005 12:06 Go to previous messageGo to next message
ted stockwell is currently offline ted stockwellFriend
Messages: 123
Registered: July 2009
Senior Member
Konstantin Scheglov wrote:
>
> 1. I don't know if I can then use these generated method in my code. Not
> using reflection, but just direct calls.
>

No. Because the methods will not exist at compile time.

What I do is just create the class variables for all the property and then use Eclipse to generate all the getters and setters.


> 2. I use Hibernate, so would be good if I could still use it. May be add
> annotations to fields plus one more annotation that tells AspectJ that I
> need getter/setter for these fields.
>
> All this is just dreams, I did not read documentation yet. :-)
>
>

It is also possible to configure Hibernate to map directly to the fields instead of using getters and setters.
Re: Intercept class loading [message #55406 is a reply to message #55379] Tue, 27 December 2005 12:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: scheglov_ke.nlmk.ru

ted stockwell wrote:

>> 1. I don't know if I can then use these generated method in my code.
>> Not using reflection, but just direct calls.
>>
>
> No. Because the methods will not exist at compile time.

Hm... With Eclipse 3.1.1 and AJDT I can add new methods, try "Bean
Example" project.

> What I do is just create the class variables for all the property and
> then use Eclipse to generate all the getters and setters.

Yes, I do same right now.

>> 2. I use Hibernate, so would be good if I could still use it. May be
>> add annotations to fields plus one more annotation that tells AspectJ
>> that I need getter/setter for these fields.
>>
>> All this is just dreams, I did not read documentation yet. :-)
>>
>>
>
> It is also possible to configure Hibernate to map directly to the fields
> instead of using getters and setters.

Yes, I know. But this looks a little dirty.

Thank you for advice, at least now I have property change listeners
using aspects. ;-)

--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)
Re: Intercept class loading [message #55459 is a reply to message #55406] Tue, 27 December 2005 14:36 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
AspectJ weaves aspects at byte-code level. Ofcourse the idea of Aspect was to be able to seperate concerns at java code level. But it becomes pretty difficult to debug/test java-code woven at bytecode level. We have developed a java weaving-specification on similar lines of AspectJ but this one weaves at javacode level making use of Eclipse's JDT API. I think using JDT refactoring API to arrive at custom refactoring tools like a weaver is a pretty eask task given the fanstastic support from JDT.

Thanks
~Venkat
Re: Intercept class loading [message #55485 is a reply to message #55459] Wed, 28 December 2005 10:50 Go to previous message
Eclipse UserFriend
Originally posted by: scheglov_ke.nlmk.ru

Venkataramana M wrote:

> AspectJ weaves aspects at byte-code level. Ofcourse the idea of
> Aspect was to be able to seperate concerns at java code level.
> But it becomes pretty difficult to debug/test
> java-code woven at bytecode level. We have developed a java

Hm... I am not going to debug my setters. :-)

I am absolutely happy with aspects - just one screen of code and I
automatically have property change notifications in all my beans.

> weaving-specification on similar lines of AspectJ but this one
> weaves at javacode level making use of Eclipse's JDT API.
> I think using JDT refactoring API to arrive at
> custom refactoring tools like a weaver is a pretty eask
> task given the fanstastic support from JDT.

I don't want dirty code.

--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)
Previous Topic:org.eclipse.equinox.registry refactoring observation
Next Topic:"pure" OSGi application in Equinox
Goto Forum:
  


Current Time: Fri Apr 26 04:50:59 GMT 2024

Powered by FUDForum. Page generated in 0.03684 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top