Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] A question about advice

In the form of Java and AspectJ code:

public class UserRecord
{
   public static void main(String args[])
   {
        UserList usrlist = new UserList();
        ... ...
        User u1 = new User(Alice);
        User u2 = new User(Bob);
        ... ...        
    }
}

class User 
{
  ...
}

class UserList 
{
  ...
}

Now I want to add an aspect like

public aspect Aspect_one
{
  pointcut test(User usr) :
    execution(public User.new(String)) && this(usr);
  
  after(User usr) : test(usr)
  {
	System.out.println("hello there");
    if (usrlist.isMember(usr))
	  System.out.println("The user is already in the list!");
   }
}

This aspect contains an error - usrlist is not defined. And my
question is that is there anyway for the aspect code to get the
reference of the usrlist object defined in the main()?

Thank you for your help.

Cong

On Mon, 14 Mar 2005 17:19:37 -0800, Wes Isberg <wes@xxxxxxxxxxxxxx> wrote:
> Your question is not clear.  What objects?
> You want a general facility for finding a reference
> to any object anywhere?  Can you state the problem
> in the language presented by the AspectJ programming
> guide?
> 
> Wes
> 
> On Mon, 14 Mar 2005 17:30:47 -0500
> Cong <yuncong@xxxxxxxxx> wrote:
> > Anyone has any idea?
> >
> > Thanks!
> >
> >
> >
> > __________________
> > In Java, the references of objects can be passed in
> > parameters of a
> > method. However, in the advice code, if it needs to use
> > other objects
> > which don't appear in the join point, how could the
> > advice get the
> > reference to those objects?
> >
> > Hope my question is clear. Thank you in advance.
> >
> > Cong
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top