[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] initialising instance variables
|
You tried:
> abstract aspect LoggingAspect
> {
> proctected static int callDepth;
> proctected static Log log;
>
> static
> {
> callDepth = 2;
> log =
> LogFactory.getLogger(LoggingAspect.class)
> }
Can you try making the variables instance again and using a non-static
initializer? Does that work?
> I would like to have multiple instances of loggers, so
> that I can customise logging per class, and have one
> log file per class if needed.
>
> Regarding the production aspect, do you mean by saying
> that
>
> 'private PropertyChangeSupport Point.support = new
> PropertyChangeSupport(this);'
>
> being intialised in a constructor or initialiser, that
> the compiler adds the initialisation of support to
> Point's constructor?
What I mean is, given the following plain java classes:
public class Foo {
int a = 5;
}
class Bar extends Foo{
a = 3;//problem here
}
a = 3 is illegal. Thus it's also illegal in AspectJ.
class Bar extends Foo{
{
a = 3;//now legal
}
}
Cheers,
Nick
--- Aaron Blishen <aaron_blishen@xxxxxxxxx> wrote:
> Hi All,
>
> Sorry for not being clear on this. If I change the
> instance variables in the abstract aspect to be static
> and initialise them as follows:
>
> abstract aspect LoggingAspect
> {
> proctected static int callDepth;
> proctected static Log log;
>
> static
> {
> callDepth = 2;
> log =
> LogFactory.getLogger(LoggingAspect.class)
> }
>
>
> public abstract pointcut cutClass(Object o);
> ...
>
> }
>
> public aspect MyClassLogger extends LoggingAspect
> {
> public pointcut cutClass(Object o) : this(o)
> && within(MyClass);
>
> // custom logging for MyClass
> }
>
> This compiles and runs fine, but this does not:
>
>
> abstract aspect LoggingAspect
> {
> proctected int callDepth;
> proctected Log log;
>
> public abstract pointcut cutClass(Object o);
> ...
>
> }
>
> public aspect MyClassLogger extends LoggingAspect
> {
> public pointcut cutClass(Object o) : this(o)
> && within(MyClass);
>
> public MyClassLogger()
> {
> callDepth = 2;
> log =
> LogFactory.getLog(MyClassLogger.class);
> }
>
> // custom logging for MyClass
>
> }
>
> The compiler gives the error:
>
> inherited abstract pointcut
> LoggingAspect.cutClass(java.lang.Object) is not made
> concrete in MyClassLogger
>
>
> I would like to have multiple instances of loggers, so
> that I can customise logging per class, and have one
> log file per class if needed.
>
> Regarding the production aspect, do you mean by saying
> that
>
> 'private PropertyChangeSupport Point.support = new
> PropertyChangeSupport(this);'
>
> being intialised in a constructor or initialiser, that
> the compiler adds the initialisation of support to
> Point's constructor?
>
> Cheers,
>
> Aaron.
>
>
> --- Lesiecki Nicholas <ndlesiecki@xxxxxxxxx> wrote:
> > From memory only, I believe that you had:
> >
> > b = new Foo();
> >
> > where b was some inherited instance variable. That
> > has to be in a
> > constructor or initialier because it's not part of a
> > member declaration.
> >
> > This:
> >
> > > private PropertyChangeSupport Point.support =
> > new
> > > PropertyChangeSupport(this);
> >
> > is part of one.
> >
> > That is (I *think*) the answer to the first implicit
> > problem.
> >
> > As to your follow-on question, I need a
> > clarification:
> >
> > > If I make the instance variables static and add a
> > > static constructor to LoggingAspect, it compiles
> > (and
> > > works) fine.
> >
> > What do you mean by "static constructor"?
> >
> > Cheers,
> > Nick
> > --- Aaron Blishen <aaron_blishen@xxxxxxxxx> wrote:
> > > Hi All,
> > >
> > > I have tried to intialise the intance variables in
> > a
> > > constructor (I assumed that one was not needed as
> > some
> > > of the examples in the programming guide do not
> > have
> > > one) i.e:
> > >
> > > aspect BoundPoint {
> > > private PropertyChangeSupport Point.support =
> > new
> > > PropertyChangeSupport(this);
> > >
> > > ....
> > >
> > > }
> > > Is this becuase the aspect is adding an instance
> > > variable to the class Point, and adds
> > initialisation
> > > of support into the Point constructor?
> > >
> > > Here is my problem when I add a constructor:
> > >
> > > public abstract aspect LoggingAspect
> > > {
> > > // call depth per logger
> > > protected int callDepth;
> > >
> > > // (commons) Log4j logger
> > > protected Log log;
> > >
> > > // class unspecified
> > > public abstract pointcut cutClass(Object o);
> > >
> > > // pointcuts and advice for intercepting
> > constructor
> > > and
> > > // method calls based on unspecified class
> > > }
> > >
> > > public aspect myClassLogger extends LoggingAspect
> > > {
> > > // initialise logger and calldepth
> > > public myClassLogger()
> > > {
> > > callDepth = 2;
> > > log = LogFactory.getLogger
> > > (myClassLogger.class);
> > > }
> > >
> > > public pointcut cutClass(Object o) : this(o)
> > > && within(com.foo.myClass);
> > >
> > > // custom logging methods for myClass
> > > }
> > >
> > > The compiler complains:
> > >
> > > inherited abstract pointcut
> > > LoggingAspect.cutClass(java.lang.Object) is not
> > made
> > > concrete in com.foo.myClassLogger
> > >
> > > If I make the instance variables static and add a
> > > static constructor to LoggingAspect, it compiles
> > (and
> > > works) fine.
> > >
> > > Cheers,
> > >
> > > Aaron.
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! SiteBuilder - Free, easy-to-use web site
> > design software
> > > http://sitebuilder.yahoo.com
> > > _______________________________________________
>
=== message truncated ===