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

I am trying to create a set of aspects, which could turn any swing
application into fully voice controllable. I cannot add methods to
subclasses, simply because I don't know their names.

I will try your second approach, although I fear it will ruin the
original idea to add voice control with minimum effort.

Thank you for your time and help.

2007/10/4, Ron Bodkin <rbodkin@xxxxxxxxxxxxxx>:
> If you can weave into EnhancedButton, then you ought to be able to use a
> hybrid approach: subclass core Swing classes and use ITD's add behavior to
> those in your own hierarchy.
>
> With respect to my other idea, let me provide a little more detail:
> 1) Create an aspect library jar that has your aspects that weave Spring
> (e.g., compile your sources with the -outjar option)
> 2) When you install your application, use the AspectJ weaver with -injar
> <path to>/rt.jar -outjar <path>/wovenRt.jar.  Note that the ajc command line
> has a tiny default memory limit (-Xmx64m), you need a lot more, somewhere
> between 512m and 1024m as I recall, to weave into the Java runtime jar.
> You need to weave into the version of the jar that your users are using for
> Java: you can't reliably use the rt.jar for one version of Java with a
> different version
> 3) Run your application using -Xbootclasspath/p: <path>/wovenRt.jar
>
> I don't know of anyone who's documented this approach in more detail...
>
> Ron
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tomas KRAMAR
> Sent: Thursday, October 04, 2007 11:50 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: 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
> _______________________________________________
> 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