KickJava   Java API By Example, From Geeks To Geeks.

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


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.objectweb.jac.core.AspectComponent;
21 import org.objectweb.jac.core.rtti.ClassItem;
22 import org.objectweb.jac.core.rtti.FieldItem;
23 import org.objectweb.jac.core.rtti.MethodItem;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28 import org.objectweb.jac.util.Log;
29
30
31 public class MessageQueueAC extends AspectComponent implements MessageQueueConf {
32
33    MessageQueue mqueue = new MessageQueue();
34
35    public void registerField(ClassItem cli, String JavaDoc fieldName, MethodItem callback) {
36       mqueue.registerFieldChange(cli.getField(fieldName),callback);
37    }
38
39    public void whenConfigured() {
40       Log.trace("mqueue",this+".whenConfigured");
41       super.whenConfigured();
42       Set JavaDoc treatedFields = new HashSet JavaDoc();
43       Map JavaDoc fieldClients = mqueue.getFieldClients();
44       Iterator JavaDoc it = fieldClients.keySet().iterator();
45       while (it.hasNext()) {
46          FieldItem field = (FieldItem)it.next();
47          if (!treatedFields.contains(field)) {
48             Log.trace("mqueue","installing pointcut for "+field.getLongName());
49             pointcut("ALL",field.getClassItem().getName(),"WRITERS("+field.getName()+")",
50                      MessageQueueWrapper.class.getName(),null,SHARED);
51             treatedFields.add(field);
52          }
53       }
54    }
55
56    public MessageQueue getMessageQueue() {
57       return mqueue;
58    }
59 }
60
Popular Tags