001    /*
002      Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public License
015      along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
017    
018    package org.objectweb.jac.aspects.queue;
019    
020    import org.objectweb.jac.core.AspectComponent;
021    import org.objectweb.jac.core.rtti.ClassItem;
022    import org.objectweb.jac.core.rtti.FieldItem;
023    import org.objectweb.jac.core.rtti.MethodItem;
024    import java.util.HashSet;
025    import java.util.Iterator;
026    import java.util.Map;
027    import java.util.Set;
028    import org.objectweb.jac.util.Log;
029    
030    
031    public class MessageQueueAC extends AspectComponent implements MessageQueueConf  {
032    
033       MessageQueue mqueue = new MessageQueue();
034    
035       public void registerField(ClassItem cli, String fieldName, MethodItem callback) {
036          mqueue.registerFieldChange(cli.getField(fieldName),callback);
037       }
038    
039       public void whenConfigured() {
040          Log.trace("mqueue",this+".whenConfigured");
041          super.whenConfigured();
042          Set treatedFields = new HashSet();
043          Map fieldClients = mqueue.getFieldClients();
044          Iterator it = fieldClients.keySet().iterator();
045          while (it.hasNext()) {
046             FieldItem field = (FieldItem)it.next();
047             if (!treatedFields.contains(field)) {
048                Log.trace("mqueue","installing pointcut for "+field.getLongName());
049                pointcut("ALL",field.getClassItem().getName(),"WRITERS("+field.getName()+")",
050                         MessageQueueWrapper.class.getName(),null,SHARED);
051                treatedFields.add(field);
052             }
053          }
054       }
055    
056       public MessageQueue getMessageQueue() {
057          return mqueue;
058       }
059    }