Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Introducing static member variable - Static Cross cutting concerns : Noob

Thank you,

In the interest of someone else who would like to do something
similar, (comments welcome)

package boxes;

public class Foo {
    private String m_name;

    public Foo(String name) {
	m_name = name;
    }

    public String getName() {
	return m_name;
    }
}

package boxes;

public class Bar {
    private String m_name;

    public Bar(String name) {
	m_name = name;
    }

    public String getName() {
	return m_name;
    }
}

import java.util.logging.Logger;

public aspect FooBarLogger pertypewithin(boxes..*){
    private Logger m_logger;

    pointcut loggedmethods() : within(boxes..*) && execution (* *.*(..));

    after() : within(boxes..*) && staticinitialization(*){
	m_logger = Logger.getLogger(getWithinTypeName());
    }

    before() : loggedmethods(){
	m_logger.entering(thisJoinPointStaticPart.getClass().getName(),
thisJoinPointStaticPart.getSourceLocation().toString());
    }

    after() : loggedmethods(){
	m_logger.exiting(thisJoinPointStaticPart.getClass().getName(),
thisJoinPointStaticPart.getSourceLocation().toString());
    }
}



On Nov 8, 2007 6:28 PM, Ramnivas Laddad <ramnivas@xxxxxxxxxxxxxxx> wrote:
> Take a look at pertypewithin() aspect association introduced in AspectJ5.
>
> -Ramnivas
>
>
>
> On Nov 8, 2007 3:42 PM, Bhaskar Maddala <maddalab@xxxxxxxxx > wrote:
> >
> >
> >
> > Hello,
> >
> >   Is there any way to introduce a static member variable to all
> > classes in a package.
> >
> >   Following is a synopsis of what I would like to accomplish.
> >
> >   Here is the java functionality that I need
> >
> >   package foo;
> >   import crazy.Trace;
> >   class T
> >   {
> >       private static final Trace TRACE = new Trace("$$ foo/T Version
> 2.24");
> >       T(Object... args)
> >       {
> >               TRACE.entering("T(Object... args");
> >               try
> >               {
> >                    ......
> >                    ......
> >               }
> >               finally
> >               {
> >                     TRACE.exiting("T(Object... args");
> >               }
> >       }
> >
> >       void dooT(Object... args)
> >       {
> >               TRACE.entering("dooT(Object... args");
> >               try
> >               {
> >                    ......
> >                    ......
> >               }
> >               finally
> >               {
> >                     TRACE.exiting("dooT(Object... args");
> >               }
> >       }
> >   }
> >   // similar class P
> >
> >   Here is how I would like to achieve it using aspects
> >
> >  class T
> >   {
> >       T(Object... args)
> >       {
> >             ......
> >             ......
> >       }
> >
> >       void dooT(Object... args)
> >       {
> >               ......
> >               ......
> >       }
> >   }
> >
> >   // similar class P
> >
> >   package foo;
> >   aspect L
> >   {
> >       pointcut scope() : within(foo..*);
> >       pointcut methods() : scope() && execution(* *.*(..));
> >
> >       before() : methods()
> >       {
> >
> TRACE.entering(thisJoinPointStaticPart.getSignature().toLongString(),
> > thisJoinPoint.getArgs());
> >       }
> >
> >       after() : methods()
> >       {
> >           TRACE.exiting(thisJoinPointStaticPart.getSignature
> ().toLongString());
> >       }
> >   }
> >
> >    The part of this that has been stumped is how would I introduce
> > the private static final Trace reference in all classes in the
> > package.
> >
> > Thanks
> > Bhaskar
> > _______________________________________________
> > 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
>
>


Back to the top