KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > queue > MessageQueueWrapper


1 /*
2   Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.queue;
19
20 import org.aopalliance.intercept.ConstructorInvocation;
21 import org.aopalliance.intercept.MethodInvocation;
22 import org.objectweb.jac.core.AspectComponent;
23 import org.objectweb.jac.core.Interaction;
24 import org.objectweb.jac.core.Wrapper;
25 import org.objectweb.jac.core.rtti.FieldItem;
26 import org.objectweb.jac.core.rtti.MethodItem;
27 import org.objectweb.jac.util.Log;
28
29 public class MessageQueueWrapper extends Wrapper {
30    MessageQueue mqueue;
31    public MessageQueueWrapper(AspectComponent ac) {
32       super(ac);
33       mqueue = ((MessageQueueAC)ac).getMessageQueue();
34    }
35    
36    public Object JavaDoc fieldChange(Interaction interaction) {
37       Log.trace("mqueue","fieldChange: "+interaction);
38       FieldItem[] fields = null;
39       // values of the fields before change
40
Object JavaDoc[] previousValues = null;
41
42       if (interaction.method instanceof MethodItem) {
43          fields = ((MethodItem)interaction.method).getWrittenFields();
44          previousValues = new Object JavaDoc[fields.length];
45          for (int i=0; i<fields.length; i++) {
46             previousValues[i] = fields[i].get(interaction.wrappee);
47          }
48       }
49
50       Object JavaDoc result = proceed(interaction);
51
52       if (fields!=null) {
53          for (int i=0; i<fields.length; i++) {
54             Object JavaDoc newValue = fields[i].get(interaction.wrappee);
55             if ( (newValue!=null &&
56                   !newValue.equals(previousValues[i])) ||
57                   (newValue==null && previousValues[i]!=null) )
58             {
59                mqueue.fieldChanged(interaction.wrappee,fields[i],
60                                    previousValues[i], newValue);
61             }
62          }
63       }
64       return result;
65    }
66
67    public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
68        return fieldChange((Interaction) invocation);
69    }
70
71    public Object JavaDoc construct(ConstructorInvocation invocation)
72        throws Throwable JavaDoc {
73        throw new Exception JavaDoc("Wrapper "+this+" does not support construction interception.");
74    }
75 }
76
Popular Tags