Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] @DeclareParents disallowed

Yes it has.  Check the developer notebook included with the aspectj
distribution, the version on the AJ website hasnt been updated yet. 
Here is a snippet relevant to what you are doing:

 @Aspect
     public class MoodIndicator {

        // this interface can be outside of the aspect
        public interface Moody {
          Mood getMood();
        };

        // this implementation can be outside of the aspect
        public class MoodyImpl implements Moody {
           private Mood mood = Mood.HAPPY;

           public Mood getMood() {
             return mood;
           }
        }

        // here is the actual ITD syntax when using @AspectJ
        // public static is mandatory
        // the field type must be the introduced interface. It can't be a class.
        @DeclareParents("org.xzy..*")
        public static Moody introduced = new MoodyImpl();

        @Before("execution(* *.*(..)) && this(m)")
        void feelingMoody(Moody m) {
           System.out.println("I'm feeling " + m.getMood());
        }
     }


Andy.

On 18/11/05, Alexandru Popescu <the.mindstorm.mailinglist@xxxxxxxxx> wrote:
> I think the semantic of @DeclareParent usage has changed. Please consult the last version of
> Developer Notebook.
>
> ./alex
> --
> .w( the_mindstorm )p.
>
> #: Raoul Pierre changed the world a bit at a time by saying on  11/18/2005 12:08 PM :#
> > Hello,
> >
> > I'm trying to set a DeclareParents annotation with an around advice (see
> > code below) and I get this error:
> >
> > The annotation @DeclareParents is disallowed for this location
> >
> > Is it possible to do such a thing? Or what did I do wrong?
> >
> > I use Eclipse and AJDT under Windows XP
> >
> > Regards
> >
> > Pierre
> >
> > package com.uwyn.ecalendar.aop;
> >
> > import java.util.Locale;
> >
> > import javax.servlet.http.HttpSession;
> >
> > import org.aspectj.lang.ProceedingJoinPoint;
> > import org.aspectj.lang.annotation.Around;
> > import org.aspectj.lang.annotation.Aspect;
> > import org.aspectj.lang.annotation.DeclareParents;
> >
> > import com.uwyn.rife.engine.ElementContext;
> > import com.uwyn.rife.engine.ElementSupport;
> >
> > @Aspect
> > public class Localization {
> >
> >     public interface Localized {
> >         public static final String PARAM_SESSION_LANGUAGE =
> > "sessionLanguage";  // $NON-NLS-1$
> >         public static final String PARAM_SESSION_COUNTRY  =
> > "sessionCountry";   // $NON-NLS-1$
> >         public Void setLocale(Locale locale);
> >         public Locale getLocale();
> >     };
> >
> >     @DeclareParents("com.uwyn.rife.engine.ElementSupport")
> >     class LocalizedImpl implements Localized {
> >
> >         private static final String EMPTY_STRING = "";        // $NON-NLS-1$
> >
> >         private Locale locale = null;
> >         private HttpSession session = null;
> >         {
> >             this.session = ElementContext.getActiveElement()
> >                                     .getHttpServletRequest()
> >                                     .getSession(false);
> >             if (this.session != null) {
> >                 String sessionLanguage = (String)
> > this.session.getAttribute(PARAM_SESSION_LANGUAGE);
> >                 if ((sessionLanguage != null) && (!
> > sessionLanguage.equals(EMPTY_STRING))) {
> >                     String sessionCountry = (String)
> > this.session.getAttribute(PARAM_SESSION_COUNTRY);
> >                     this.locale = new Locale(sessionLanguage,
> > sessionCountry);
> >                 }
> >             }
> >         }
> >
> >         public Void setLocale (Locale locale) {
> >             this.locale = locale;
> >             if (this.session != null) {
> >                 if (this.locale != null) {
> >                     this.session.setAttribute(PARAM_SESSION_LANGUAGE,
> > locale.getLanguage());
> >                     this.session.setAttribute(PARAM_SESSION_COUNTRY,
> > locale.getCountry());
> >                 }
> >                 else {
> >                     this.session.removeAttribute(PARAM_SESSION_LANGUAGE);
> >                     this.session.removeAttribute(PARAM_SESSION_COUNTRY);
> >                 }
> >             }
> >             else {
> >                 if (locale != null) {
> >                     this.session = ElementContext.getActiveElement()
> >                                             .getHttpServletRequest()
> >                                             .getSession(true);
> >                     this.session.setAttribute(PARAM_SESSION_LANGUAGE,
> > locale.getLanguage());
> >                     this.session.setAttribute(PARAM_SESSION_COUNTRY,
> > locale.getCountry());
> >                 }
> >             }
> >         }
> >
> >         public Locale getLocale() {
> >             Locale userLocale = this.locale;
> >             if (userLocale == null) {
> >                 userLocale =
> > ElementContext.getActiveElement().getRequestLocale();
> >             }
> >             return userLocale;
> >         }
> >     }
> >
> >
> >     @Around("execution(public static String
> > com.uwyn.rife.config.RifeConfig.Tools.getDefaultLanguage())" +
> >             " && this(localized)")
> >     public Object getDefaultLanguage(ProceedingJoinPoint thisJoinPoint,
> > Localized localized)
> >     throws Throwable{
> >         return localized.getLocale().getLanguage();
> >     }
> >
> > }
> >
> >
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> >
> >
> > !DSPAM:437da8ec572649624381582!
> >
> >
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top