KickJava   Java API By Example, From Geeks To Geeks.

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


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):
23  */

24
25 package org.objectweb.dream.aggregator;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.Pull;
31 import org.objectweb.dream.PullException;
32 import org.objectweb.dream.message.ExtensibleMessage;
33 import org.objectweb.dream.message.Message;
34 import org.objectweb.dream.message.MessageTypeImpl;
35 import org.objectweb.dream.message.manager.MessageManager;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.fractal.api.control.IllegalBindingException;
38 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
39
40 /**
41  * TODO Add class comment
42  */

43 public class PullPullAggregatorWhileNotNullImpl extends AbstractComponent
44     implements
45       Pull,
46       PullPullAggregatorWhileNotNullAttributeController
47 {
48   // ---------------------------------------------------------------------------
49
// Attributes fields
50
// ---------------------------------------------------------------------------
51

52   boolean pullEmptyMessagePolicy;
53
54   // ---------------------------------------------------------------------------
55
// Client interfaces
56
// ---------------------------------------------------------------------------
57

58   protected Pull inPullItf;
59   protected MessageManager messageManagerItf;
60
61   // ---------------------------------------------------------------------------
62
// Implementation of the Pull interface
63
// ---------------------------------------------------------------------------
64

65   /**
66    * @see Pull#pull(Map)
67    */

68   public Message pull(Map JavaDoc context) throws PullException
69   {
70     Message inMessage = inPullItf.pull(context);
71     if (inMessage == null && (!pullEmptyMessagePolicy))
72     {
73       return null;
74     }
75     ExtensibleMessage outMessage = null;
76     outMessage = (ExtensibleMessage) messageManagerItf
77         .createMessage(MessageTypeImpl.EMPTY_MESSAGE_TYPE);
78     while (inMessage != null)
79     {
80       outMessage.addSubMessage(inMessage);
81       inMessage = inPullItf.pull(context);
82     }
83     return outMessage;
84   }
85
86   // ---------------------------------------------------------------------------
87
// Implementation of the AttributeController interface
88
// ---------------------------------------------------------------------------
89

90   /**
91    * @see PullPullAggregatorWhileNotNullAttributeController#getPullEmptyMessagePolicy()
92    */

93   public boolean getPullEmptyMessagePolicy()
94   {
95     return pullEmptyMessagePolicy;
96   }
97
98   /**
99    * @see PullPullAggregatorWhileNotNullAttributeController#setPullEmptyMessagePolicy(boolean)
100    */

101   public void setPullEmptyMessagePolicy(boolean policy)
102   {
103     pullEmptyMessagePolicy = policy;
104   }
105
106   // ---------------------------------------------------------------------------
107
// Implementation of the BindingController interface
108
// ---------------------------------------------------------------------------
109

110   /**
111    * @see org.objectweb.fractal.api.control.BindingController#listFc()
112    */

113   public String JavaDoc[] listFc()
114   {
115     return new String JavaDoc[]{MessageManager.ITF_NAME, Pull.IN_PULL_ITF_NAME};
116   }
117
118   /**
119    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
120    * Object)
121    */

122   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
123       throws NoSuchInterfaceException, IllegalBindingException,
124       IllegalLifeCycleException
125   {
126     super.bindFc(clientItfName, serverItf);
127     if (clientItfName.equals(MessageManager.ITF_NAME))
128     {
129       messageManagerItf = (MessageManager) serverItf;
130     }
131     else if (clientItfName.equals(Pull.IN_PULL_ITF_NAME))
132     {
133       inPullItf = (Pull) serverItf;
134     }
135
136   }
137 }
Popular Tags