[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] advising jsp's for i18n (because of problemwithhibernate property)

Ron's suggestion is a good one... in past we used a similar approach to let
Hibernate have unadvised access to data when we were wrapping collections to
provide data security. If you aren't weaving into the Hibernate jar, you'll
probably want to use !cflow(call(* org.hibernate..*(..)), assuming that the
call to Hibernate occurs in code you are weaving into.  If it does not, you
might consider using execution of Hibernate and weave into Hibernate (either
with load-time weaving or by building a woven Hibernate jar). From the code
snippet you provided the JSP is surely using reflection to access the


Another option to consider is to have Hibernate map to fields directly,
possibly using a tupleizer, instead of getters and setters. Obviously if you
have hand-written mapping files this is an unpleasant change to make, but in
some scenarios it might be worth pursuing.



From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Ron DiFrango
Sent: Wednesday, April 05, 2006 10:55 AM
To: aspectj-users@xxxxxxxxxxx
Subject: RE: [aspectj-users] advising jsp's for i18n (because of
problemwithhibernate property)




Are the JSP tags also using reflection to get access to the underlying data
hence the problem picking out via a call join point?


What about converting it back into execution join point and use something
like cflow to exclude calls from Hibernate?


I assume then given your structure you have no Value Objects that sit on top
of your Hibernate objects?  If you did you could wire it in at that level





From: aspectj-users-bounces@xxxxxxxxxxx on behalf of Raoul Schmidiger
Sent: Wed 4/5/2006 1:30 PM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] advising jsp's for i18n (because of problem
withhibernate property)

Hi aspectj users,

i have a problem with advising jsp's: in our app, we have some "dynamic i18n
data". this is not the "static" stuff in the jsp's that can be translated
through jsp tags. but instead, it is a buisness object that has multilingual
descriptions of some sort.

the idea is to have i18n unaware business objects:

    public String getProductName() {
        return productName;

instead of

    public String getProductName(Locale loc) {
        if(loc.getLanguage().equals("en") {
            return productNameEnglish;
        return productNameDefault;

So i thought, i would use an aspect:

        String around(): callGetProductName() {
                final I18NInfo info = I18NInfo.get();
                final Locale locale = info.getLocale();
                final String language = locale.getLanguage();
                System.out.println("GETTER: language: " + language);
                if(!language.equals("en")) {
                        return fetchLanguageFromDB(language);
                return proceed();

With a execution pointcut, this workes fine but since this property is
mapped also by Hibernate, it doesn't. hibernate thinks, the value english
value changed, when i return the french version and afterwards i have my
french text in the db where the english should be.

To solve this i did the same with a call pointcut, since hibernate is
accessing the method through refelction, it would not be touched by it. So i
went on to precompile my JSP's and tried to advise the servlets:

This is what the compiled JSP, the servlet code looks like when accessing :

ductName}", java.lang.String.class, (PageContext)_jspx_page_context, null,

so my pointcut is not hooking in here...

pointcut callGetProductName():         
                call(public String

Any ideas how to solve my problem?

Thanks, raoul 

<<attachment: winmail.dat>>