Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Adding methods to all subclasses

This was my first approach to the problem. However, there is a problem
replacing the components which are already subclassed swing
components. Let me demonstrate it:

class ButtonSubclass extends JButton {}
class EnhancedButton extends JButton {
   public void doSomethingExtra() {}
}

and somewhere in the code is a declaration

ButtonSubclass button = new ButtonSubclass();

Now, if I would advise the ButtonSubclass construction and return the
EnhancedButton, I would get:

ButtonSubclass button = new EnhancedButton();

which is a total nonsense.

The only solution I have found so far is introducing new methods to
each of the component's subclass.

Could you please tell me more about your first solution?
You mean I could create an archive with already woven swing classes,
add it to the classpath and somehow override those in rt.jar? Do you
have any link, where I can read more?

Thanks in advance

Regards

2007/10/4, Ron Bodkin <rbodkin@xxxxxxxxxxxxxx>:
> You can't use load-time weaving because it won't weave into classes in
> java..*  You could distribute a script that creates a woven set of Swing
> classes to prepend to the bootstrap classpath, weaving rt.jar. There are
> some licensing restrictions to consider, though I think if you suggest users
> use the open jdk you'd probably be fine.
>
> Another option to consider is to use around advice on calls to construct the
> base swing components and replace them with your own enhanced subclasses,
> which you could have woven freely.
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tomas KRAMAR
> Sent: Thursday, October 04, 2007 11:25 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Adding methods to all subclasses
>
> No, this is not what I meant. I need to add few new methods to each of
> the swing components (JButton, JCheckBox, JFrame etc.), which will
> provide new functionality.
>
> 2007/10/4, Ron Bodkin <rbodkin@xxxxxxxxxxxxxx>:
> > You could advise calls to the Swing methods, as long as they're not being
> > done through reflection.
> >
> > -----Original Message-----
> > From: aspectj-users-bounces@xxxxxxxxxxx
> > [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tomas KRAMAR
> > Sent: Thursday, October 04, 2007 10:15 AM
> > To: aspectj-users
> > Subject: [aspectj-users] Adding methods to all subclasses
> >
> > Hello,
> >
> > I need to add methods to all subclasses of various swing components.
> > The simplest solution seems to be simply adding those methods to the
> > component itself, but that would require weaving the swing classes;
> > something I cannot afford if I want to keep the application
> > distributable.
> >
> > I hoped I could use a similar construction like:
> >
> > public void JFrame+.doSomething() {}
> >
> > Is it possible to use some kind of pattern instead of a class name,
> > when introducing new methods?
> >
> > Regards
> > Tomas Kramar
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
>
>
> --
> Tomas Kramar
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


-- 
Tomas Kramar


Back to the top