KickJava   Java API By Example, From Geeks To Geeks.

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


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, Vivien Quema
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.message;
26
27 import java.io.Serializable JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import org.objectweb.dream.util.EmptyIterator;
31 import org.objectweb.dream.util.Error;
32
33 /**
34  * Basic implementation of a non-extensible message. This class is intended to
35  * be extended by specific non-extensible message implementations. It implements
36  * the {@link org.objectweb.dream.message.Message}and
37  * {@link org.objectweb.dream.message.MessageType}interfaces.
38  */

39 public abstract class AbstractNonExtensibleMessage
40     implements
41       Message,
42       MessageType,
43       MessageReferenceCounter,
44       Cloneable JavaDoc,
45       Serializable JavaDoc
46 {
47
48   /** The id of the message manager that created this message. */
49   transient short messageManagerId;
50   /** The number of reference to this message. */
51   transient short referenceCounter = 0;
52
53   // ---------------------------------------------------------------------------
54
// Implementation of the Message interface
55
// ---------------------------------------------------------------------------
56

57   /**
58    * This class implements every chunk so it allways returns this. Warning : the
59    * given chunk name is not checked
60    *
61    * @see Message#getChunk(String)
62    */

63   public Object JavaDoc getChunk(String JavaDoc name)
64   {
65     return this;
66   }
67
68   /**
69    * Allways returns {@link Message#EMPTY_MESSAGE_ARRAY}
70    *
71    * @see Message#getSubMessages()
72    */

73   public Message[] getSubMessages()
74   {
75     return EMPTY_MESSAGE_ARRAY;
76   }
77
78   /**
79    * @see Message#getSubMessageIterator()
80    */

81   public Iterator JavaDoc getSubMessageIterator()
82   {
83     return EmptyIterator.INSTANCE;
84   }
85
86   /**
87    * @see Message#getMessageType()
88    */

89   public MessageType getMessageType()
90   {
91     return this;
92   }
93
94   /**
95    * @see Message#getMessageManagerId()
96    */

97   public short getMessageManagerId()
98   {
99     return messageManagerId;
100   }
101
102   /**
103    * @see Message#setMessageManagerId(short)
104    */

105   public void setMessageManagerId(short id)
106   {
107     messageManagerId = id;
108   }
109
110   // ---------------------------------------------------------------------------
111
// Implementation of the MessageType interface
112
// ---------------------------------------------------------------------------
113

114   /**
115    * @see MessageType#getSubMessageTypes()
116    */

117   public MessageType[] getSubMessageTypes()
118   {
119     Error.error("This method is not implemented", null);
120     return EMPTY_MESSAGE_TYPE_ARRAY;
121   }
122
123   /**
124    * @see MessageType#getSubMessageTypesIterator()
125    */

126   public Iterator JavaDoc getSubMessageTypesIterator()
127   {
128     Error.error("This method is not implemented", null);
129     return EmptyIterator.INSTANCE;
130   }
131
132   /**
133    * @see MessageType#isEmpty()
134    */

135   public boolean isEmpty()
136   {
137     Error.error("This method is not implemented", null);
138     return false;
139   }
140
141   /**
142    * @see MessageType#isSubTypeOf(MessageType)
143    */

144   public boolean isSubTypeOf(MessageType t)
145   {
146     Error.error("This method is not implemented", null);
147     return false;
148   }
149
150   /**
151    * @see MessageType#getChunkNames()
152    */

153   public String JavaDoc[] getChunkNames()
154   {
155     Error.error("This method is not implemented", null);
156     return null;
157   }
158
159   /**
160    * @see MessageType#getChunkNamesIterator()
161    */

162   public Iterator JavaDoc getChunkNamesIterator()
163   {
164     Error.error("This method is not implemented", null);
165     return null;
166   }
167
168   /**
169    * @see MessageType#getChunkType(String)
170    */

171   public ChunkType getChunkType(String JavaDoc name)
172   {
173     Error.error("This method is not implemented", null);
174     return null;
175   }
176
177   // ---------------------------------------------------------------------------
178
// Implementation of the MessageReferenceCounter interface
179
// ---------------------------------------------------------------------------
180

181   /**
182    * @see MessageReferenceCounter#incrementReferenceCounter()
183    */

184   public void incrementReferenceCounter()
185   {
186     referenceCounter++;
187   }
188
189   /**
190    * @see MessageReferenceCounter#decrementReferenceCounter()
191    */

192   public boolean decrementReferenceCounter()
193   {
194     synchronized (this)
195     {
196       referenceCounter--;
197       return (referenceCounter == 0);
198     }
199   }
200 }
Popular Tags