[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-dev] Introducing a method to classes that are in the JRE
|
You could set up a map from the object to its encoding.
The aspect would set up the map, use advice to make the
association, and then use advice to change to
locale-specific behavior. Unfortunately, this costs
a map lookup for all instances of the type for
the association and for any uses.
Wes
P.S. - If the locale is always the same for a given
control flow, you can also make that association with a
percflow aspect, and avoid the map lookup.
aspect ManagingStringsWithLocale { // untested
// warning: sync, map, intern, memory issues
// with this code - consider before use!
final Map stringToLocale = new HashMap();
before(Locale locale, String s) : ... {
if (null == stringToLocal.get(s)) {
stringToLocal.put(s, locale);
}
}
String around(String s) : target(s) &&
call(String toLowerCase()) {
Locale locale = (Locale) stringToLocal.get(s);
if (null == locale) {
return proceed(s);
} else {
return s.toLowerCase(locale);
}
}
}
On Tue, 2 Dec 2003 15:51:54 -0800
jerry_liu@xxxxxxxxxxx wrote:
> What I had wanted to do was be able to annotate instances
> of Java classes and then act on these instances based on
> the annotation. The actual application is too complex to
> describe, but here's a contrived example which captures
> the flavor.
>
> Say I have a text processing system where String
> (java.lang.String) objects were being passed around. I
> want to be able to tag the language encoding of the
> String to the String object. Since String is final, I
> can't subclass it, and since all my processing code act
> on 'String', I can't make a MyString object which wraps a
> String.
>
> I was hoping to be able to use AspectJ to introduce a
> 'language' attribute, and associated methods, to the
> String class, and in effect add this little bit of
> annotation to the String objects. Getting around the
> 'final' keyword, so to speak...
>
> Is there another way to do this with Aspects?
>
> Thanks,
>
> Jerry
>
> > -----Original Message-----
> > From: aspectj-dev-admin@xxxxxxxxxxx
> > [mailto:aspectj-dev-admin@xxxxxxxxxxx]On Behalf Of Wes
> Isberg
> > Sent: Tuesday, December 02, 2003 12:39 PM
> > To: aspectj-dev@xxxxxxxxxxx
> > Subject: Re: [aspectj-dev] Introducing a method to
> classes that are in
> > the JRE
> >
> >
> > The mechanics of doing something like this are
> > described in the Programmer's Guide discussion of
> > inter-type declaration and the Development Environment
> > Guide section on the ajc tool -injars option. Both
> > are linked off the AspectJ documentation page.
> >
> > But we recommend against modifying Java classes because
>
> > doing violates the spirit and perhaps the letter of
> Sun's
> > license. Further, I think it unwise to modify final
> > classes, and believe that AspectJ should avoid this
> > (perhaps permitting it under the rubric of privilege):
> >
> > https://bugs.eclipse.org/bugs/show_bug.cgi?id=47919
> >
> > If you can specify the code you'd actually like to
> > write and what you're trying to do, then perhaps
> > someone can help you do it another way.
> >
> > Wes
> >
> > On Tue, 2 Dec 2003 10:56:59 -0800
> > jerry_liu@xxxxxxxxxxx wrote:
> > > Are there any tips on how I can introduce methods and
> > > attributes to a class like java.lang.Integer which is
> > > packaged in the Java runtime? Or pointers to a FAQ
> if
> > > this is a known question. I'm new to this. :-)
> > >
> > > Thanks,
> > >
> > > Jerry
> > > _______________________________________________
> > > aspectj-dev mailing list
> > > aspectj-dev@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-dev
> >
> > _______________________________________________
> > aspectj-dev mailing list
> > aspectj-dev@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-dev
> >
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-dev