Hello,

I am writing my masther's thesis about aop and I am about to write a definitions and 
overview chapter. In that chapter I am giving an overview over existing AOP systems, 
and JBoss AOP is surely a candidate I want to be in that chapter.  My plans were to 
create a common example and to show how and why the implementation of the example 
differ.

For that reason I have a simple example, a stack class:

public class Stack
  | {
  |    private class StackObject
  |    {
  |       private Object content;
  |       private StackObject next = null;
  | 
  |       public StackObject ( Object o, StackObject s )
  |       {
  |          this.content = o;
  |          this.next = s;
  |       }
  | 
  |       public StackObject getNext ()
  |       {
  |          return this.next;
  |       }
  | 
  |       public Object getContent ()
  |       {
  |          return this.content;
  |       }
  |    }
  | 
  |    private StackObject top = null;
  |    private int height = 0;
  | 
  |    public Stack () {}
  | 
  |    public synchronized Object pop ()
  |    {
  |       if ( this.top == null )
  |       {
  |           // contract violation - a real program would throw an exception
  |           return null;
  |       }
  | 
  |       -- this.height;
  | 
  |       StackObject temp = this.top;
  |       this.top = temp.getNext ();
  | 
  |       return temp.getContent ();
  |    }
  | 
  |    public synchronized void push ( Object o )
  |    {
  |       this.top = new StackObject ( o, this.top );
  | 
  |       ++ this.height;
  |    }
  | 
  |    public synchronized int size ()
  |    {
  |       return this.height;
  |    }
  | }

Now I have "identified" two aspects:
* Size
* Synchronization

Contract Enforcement would be a candidate, too, but I didn't want to overcomplicate 
the example. So my AspectJ implementation is (untested, but compiles):

Stripped down stack class:
public class Stack
  | {
  |    private class StackObject
  |    {
  |       private Object content;
  |       private StackObject next = null;
  | 
  |       public StackObject ( Object o, StackObject s )
  |       {
  |          this.content = o;
  |          this.next = s;
  |       }
  | 
  |       public StackObject getNext ()
  |       {
  |          return this.next;
  |       }
  | 
  |       public Object getContent ()
  |       {
  |          return this.content;
  |       }
  |    }
  | 
  |    private StackObject top = null;
  | 
  |    public Stack () {}
  | 
  |    public Object pop ()
  |    {
  |       if ( this.top == null )
  |       {
  |           // contract violation - a real program would throw an exception
  |           return null;
  |       }
  | 
  |       Object temp = this.top.getContent ();
  |       this.top = this.top.getNext ();
  | 
  |       return temp;
  |    }
  | 
  |    public void push ( Object o )
  |    {
  |       this.top = new StackObject ( o, this.top );
  |    }
  | }

The size aspect:
public aspect StackHeight
  | {
  |    private int Stack.height = 0;
  | 
  |    public int Stack.size ()
  |    {
  |       return this.height;
  |    }
  | 
  |    after ( Stack s ) returning: target ( s ) &&
  |       call( public void Stack.push(..) )
  |    {
  |       ++ s.height;
  |    }
  | 
  |    after ( Stack s ) returning: target ( s ) &&
  |       call( public * Stack.pop(..) )
  |    {
  |       if ( s.height > 0 )
  |       {
  |          -- s.height;
  |       }
  |    }
  | }

And the synchronization aspect:
public aspect StackSynchronization
  | {
  |    // 1:
  |    private boolean Stack.semaphore = false;
  | 
  |    // 2:
  |    before ( Stack s ): target ( s ) &&
  |       call( public * Stack.*(..) ) && within( Stack )
  |    {
  |       synchronized ( s )
  |       {
  |          if ( s.semaphore == true )
  |          {
  |              try {
  |                  s.wait ();
  |              } catch(InterruptedException e) {}
  |          }
  | 
  |          s.semaphore = true;
  |       }
  |    }
  | 
  |    // 3:
  |    after ( Stack s ): target ( s ) &&
  |       call( public * Stack.*(..) ) && within( Stack )
  |    {
  |       s.semaphore = false;
  |       s.notify ();
  |    }
  | }

My problem here is that I use static introductions and I wasn't able to figure out how 
this is done in JBoss AOP. I know how changes in the hierarchy and the type system are 
done, but not how I can change the static structure of a class with JBoss AOP. - Is 
this even impossible with JBoss AOP?

Any help appriciated.

Many thanks in advance,
Franz

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3840580#3840580

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3840580


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to