KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > router > RouterChunkNameImpl


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.router;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.Push;
31 import org.objectweb.dream.PushException;
32 import org.objectweb.dream.message.Message;
33 import org.objectweb.fractal.api.NoSuchInterfaceException;
34 import org.objectweb.fractal.api.control.IllegalBindingException;
35 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
36
37 /**
38  * A basic router implementation with two outputs :
39  * <code>out-push-with-chunk</code> and <code>out-push-without-chunk</code>.
40  * The first one is used if pushed messages contain a specified chunk name, the
41  * secone one is used otherwise. The chunk name to test is specified as
42  * attribute. <br>
43  * <b>Warning </b>: This router may not work correctly if it is used with
44  * unextensible message implementations that simply return <code>this</code>
45  * in the {@link Message#getChunk(String) }method. In this case messages will
46  * always be routed through the <code>out-push-with-chunk</code> output.
47  */

48 public class RouterChunkNameImpl extends AbstractComponent
49     implements
50       Push,
51       RouterChunkNameAttributeController
52 {
53
54   /**
55    * The name of client interface used to push messages with the specified chunk
56    * name.
57    */

58   public static final String JavaDoc OUTPUSH_WITH_CHUNK_ITF_NAME = "out-push-with-chunk";
59
60   /**
61    * The name of client interface used to push messages without the specified
62    * chunk name.
63    */

64   public static final String JavaDoc OUTPUSH_WITHOUT_CHUNK_ITF_NAME = "out-push-without-chunk";
65
66   /** The interface used to push messages with the specified chunk name. */
67   protected Push outPushWithChunkItf;
68   /** The interface used to push messages without the specified chunk name. */
69   protected Push outPushWithoutChunkItf;
70   /** the chunk name to test */
71   protected String JavaDoc chunkName;
72
73   /**
74    * @see Push#push(Message, Map)
75    */

76   public void push(Message message, Map JavaDoc context) throws PushException
77   {
78     if (message.getChunk(chunkName) == null)
79     {
80       outPushWithoutChunkItf.push(message, context);
81     }
82     else
83     {
84       outPushWithChunkItf.push(message, context);
85     }
86   }
87
88   // ---------------------------------------------------------------------------
89
// Implementation of RouterChunkNameAttributeController interface
90
// ---------------------------------------------------------------------------
91

92   /**
93    * @see RouterChunkNameAttributeController#getChunkName()
94    */

95   public String JavaDoc getChunkName()
96   {
97     return chunkName;
98   }
99
100   /**
101    * @see RouterChunkNameAttributeController#setChunkName(String)
102    */

103   public void setChunkName(String JavaDoc chunkName)
104   {
105     this.chunkName = chunkName;
106   }
107
108   // ---------------------------------------------------------------------------
109
// Implementation of BindingController interface
110
// ---------------------------------------------------------------------------
111

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

115   public String JavaDoc[] listFc()
116   {
117     return new String JavaDoc[]{OUTPUSH_WITH_CHUNK_ITF_NAME,
118         OUTPUSH_WITHOUT_CHUNK_ITF_NAME};
119   }
120
121   /**
122    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
123    * Object)
124    */

125   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
126       throws NoSuchInterfaceException, IllegalBindingException,
127       IllegalLifeCycleException
128   {
129     super.bindFc(clientItfName, serverItf);
130     if (clientItfName.equals(OUTPUSH_WITH_CHUNK_ITF_NAME))
131     {
132       outPushWithChunkItf = (Push) serverItf;
133     }
134     else if (clientItfName.equals(OUTPUSH_WITHOUT_CHUNK_ITF_NAME))
135     {
136       outPushWithoutChunkItf = (Push) serverItf;
137     }
138   }
139 }
Popular Tags