KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > message > AggregateMessageImpl


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.message;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * Extensible message implementation specialized for aggregate message (ie.
33  * message containing only sub messages).
34  */

35 public class AggregateMessageImpl
36     implements
37       ExtensibleMessage,
38       MessageReferenceCounter
39 {
40   final List JavaDoc subMessages = new ArrayList JavaDoc();
41   transient short messageManagerId;
42   transient int referenceCounter;
43
44   // ---------------------------------------------------------------------------
45
// Implementation of the ExtensibleMessage interface
46
// ---------------------------------------------------------------------------
47

48   /**
49    * Throws a {@link UnsupportedOperationException}.
50    *
51    * @see ExtensibleMessage#addChunk(String, ChunkType, Object)
52    */

53   public void addChunk(String JavaDoc name, ChunkType chkType, Object JavaDoc chunk)
54       throws ChunkAlreadyExistsException
55   {
56     throw new UnsupportedOperationException JavaDoc();
57   }
58
59   /**
60    * Always return <code>null</code>.
61    *
62    * @see ExtensibleMessage#removeChunk(String)
63    */

64   public Object JavaDoc removeChunk(String JavaDoc name)
65   {
66     return null;
67   }
68
69   /**
70    * @see ExtensibleMessage#addSubMessage(Message)
71    */

72   public void addSubMessage(Message message)
73   {
74     subMessages.add(message);
75   }
76
77   /**
78    * @see ExtensibleMessage#removeSubMessage(Message)
79    */

80   public boolean removeSubMessage(Message message)
81   {
82     return subMessages.remove(message);
83   }
84
85   /**
86    * @see ExtensibleMessage#removeSubMessages()
87    */

88   public void removeSubMessages()
89   {
90     subMessages.clear();
91   }
92
93   // ---------------------------------------------------------------------------
94
// Implementation of the Message interface
95
// ---------------------------------------------------------------------------
96

97   /**
98    * @see Message#getMessageManagerId()
99    */

100   public short getMessageManagerId()
101   {
102     return messageManagerId;
103   }
104
105   /**
106    * @see Message#setMessageManagerId(short)
107    */

108   public void setMessageManagerId(short id)
109   {
110     messageManagerId = id;
111   }
112
113   /**
114    * @see Message#getChunk(String)
115    */

116   public Object JavaDoc getChunk(String JavaDoc name)
117   {
118     return null;
119   }
120
121   /**
122    * @see Message#getSubMessageIterator()
123    */

124   public Iterator JavaDoc getSubMessageIterator()
125   {
126     return subMessages.iterator();
127   }
128
129   /**
130    * @see Message#getSubMessages()
131    */

132   public Message[] getSubMessages()
133   {
134     Message[] subMessageArray = new Message[subMessages.size()];
135     return (Message[]) subMessages.toArray(subMessageArray);
136   }
137
138   /**
139    * Throws a {@link UnsupportedOperationException}.
140    *
141    * @see Message#getMessageType()
142    */

143   public MessageType getMessageType()
144   {
145     throw new UnsupportedOperationException JavaDoc();
146   }
147
148   /**
149    * @see Message#transfertChunkStates(Message)
150    */

151   public void transfertChunkStates(Message newInstance)
152   {
153     // nothing to do since this message contains no chunk
154
}
155
156   /**
157    * @see Message#recycle()
158    */

159   public void recycle()
160   {
161     subMessages.clear();
162   }
163
164   // ---------------------------------------------------------------------------
165
// Implementation of the MessageReferenceCounter interface
166
// ---------------------------------------------------------------------------
167

168   /**
169    * @see MessageReferenceCounter#incrementReferenceCounter()
170    */

171   public void incrementReferenceCounter()
172   {
173     referenceCounter++;
174   }
175
176   /**
177    * @see MessageReferenceCounter#decrementReferenceCounter()
178    */

179   public boolean decrementReferenceCounter()
180   {
181     synchronized (this)
182     {
183       referenceCounter--;
184       return (referenceCounter == 0);
185     }
186   }
187
188 }
Popular Tags