KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > aggregator > PushPushDeAggregatorImpl


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact : dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s): Vivien Quema
23  */

24
25 package org.objectweb.dream.aggregator;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.objectweb.dream.PushException;
31 import org.objectweb.dream.PushPushDreamComponent;
32 import org.objectweb.dream.message.ExtensibleMessage;
33 import org.objectweb.dream.message.Message;
34 import org.objectweb.dream.message.manager.MessageManager;
35 import org.objectweb.fractal.api.NoSuchInterfaceException;
36 import org.objectweb.fractal.api.control.IllegalBindingException;
37 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
38
39 /**
40  * Basic implementation of a Push/Push de-aggregator. Each sub message in the
41  * pushed message is sent on the output. The pushed message is then deleted.
42  */

43 public class PushPushDeAggregatorImpl extends PushPushDreamComponent
44 {
45
46   /** the message manager client interface of this component. */
47   protected MessageManager messageManagerItf;
48
49   /**
50    * @see org.objectweb.dream.Push#push(Message, Map)
51    */

52   public void push(Message message, Map JavaDoc context) throws PushException
53   {
54     if (!(message instanceof ExtensibleMessage))
55     {
56       throw new PushException(
57           "Invalid aggregated message, not an extensible message");
58     }
59     Iterator JavaDoc iterator = message.getSubMessageIterator();
60     while (iterator.hasNext())
61     {
62       outPushItf.push((Message) iterator.next(), context);
63     }
64     ((ExtensibleMessage) message).removeSubMessages();
65     messageManagerItf.deleteMessage(message);
66   }
67
68   // ---------------------------------------------------------------------------
69
// Implementation of BindingController interface
70
// ---------------------------------------------------------------------------
71

72   /**
73    * @see org.objectweb.fractal.api.control.BindingController#listFc()
74    */

75   public String JavaDoc[] listFc()
76   {
77     return new String JavaDoc[]{OUT_PUSH_ITF_NAME, MessageManager.ITF_NAME};
78   }
79
80   /**
81    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
82    * Object)
83    */

84   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
85       throws NoSuchInterfaceException, IllegalBindingException,
86       IllegalLifeCycleException
87   {
88     super.bindFc(clientItfName, serverItf);
89     if (clientItfName.equals(MessageManager.ITF_NAME))
90     {
91       messageManagerItf = (MessageManager) serverItf;
92     }
93   }
94
95 }
Popular Tags