001 //Copyright (C) 2006 A. Nelson
002 //
003 //This program is free software; you can redistribute it and/or
004 //modify it under the terms of the GNU General Public License
005 //as published by the Free Software Foundation; either version 2
006 //of the License, or (at your option) any later version.
007 //
008 //This program is distributed in the hope that it will be useful,
009 //but WITHOUT ANY WARRANTY; without even the implied warranty of
010 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011 //GNU General Public License for more details.
012 //
013 //You should have received a copy of the GNU General Public License
014 //along with this program; if not, write to the Free Software
015 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
016
017 package pluginCore;
018
019 /**
020 * The base object for communication between plugins.
021 */
022 public class Message {
023
024 /**
025 * Communication protocol A.
026 */
027 public static final int PROTOCOL_A = 1344;
028
029 /**
030 * Communication protocol B.
031 */
032 public static final int PROTOCOL_B = 1345;
033
034 /**
035 * Communication protocol C.
036 */
037 public static final int PROTOCOL_C = 1346;
038
039 /**
040 * The id of the plug-in that sent this message.
041 */
042 public int sourceID;
043
044 /**
045 * The id of the plug-in that is to receive this message.
046 */
047 public int destID;
048
049 /**
050 * The protocol that is being used for this communication.
051 */
052 public int protocol;
053
054 /**
055 * The integer value of a message in the protocol defined by 'protocol'.
056 */
057 public int intMessage;
058
059 /**
060 * An object that is to be sent to another plug-in.
061 */
062 public Object anObject;
063
064 /**
065 * Used when plug-ins wish to store linked lists of messages.
066 */
067 public Message next;
068
069 /**
070 * Blank constructor, ever value is set to 0.
071 */
072 public Message() {
073
074 sourceID = 0;
075 destID = 0;
076 protocol = 0;
077 intMessage = 0;
078 anObject = null;
079 }
080
081 /**
082 * Constructor for regular Message.
083 *
084 * @param srcID
085 * The id of the originating plug-in.
086 * @param deID
087 * The id of the destination plug-in.
088 * @param proto
089 * The protocol with which this message is communicating.
090 * @param msg
091 * The integer value of the message.
092 */
093 public Message(int srcID, int deID, int proto, int msg) {
094
095 sourceID = srcID;
096 destID = deID;
097 protocol = proto;
098 intMessage = msg;
099 anObject = null;
100 }
101
102 /**
103 * Constructor for regular Message with object parameters.
104 *
105 * @param srcID
106 * The id of the originating plug-in.
107 * @param destID
108 * The id of the destination plug-in.
109 * @param proto
110 * The protocol with which this message is communicating.
111 * @param msg
112 * The integer value of the message.
113 * @param par
114 * The Object payload of the message.
115 */
116 public Message(int srcID, int destID, int proto, int msg, Object par) {
117
118 sourceID = srcID;
119 this.destID = destID;
120 protocol = proto;
121 intMessage = msg;
122 anObject = par;
123 }
124
125 /**
126 * Sets the destination plug-in Id.
127 *
128 * @param newDest
129 * The destination plug-in Id.
130 */
131 public void setDest(int newDest) {
132
133 destID = newDest;
134 }
135
136 /**
137 * Gets the destination plug-in Id.
138 *
139 * @return The destination plug-in Id.
140 */
141 public int getDest() {
142
143 return destID;
144 }
145
146 /**
147 * Sets the source plug-in Id.
148 *
149 * @param newSource
150 * The source plug-in Id.
151 */
152 public void setSource(int newSource) {
153
154 sourceID = newSource;
155 }
156
157 /**
158 * Gets the source plug-in Id.
159 *
160 * @return The source plug-in Id.
161 */
162 public int getSource() {
163
164 return sourceID;
165 }
166
167 /**
168 * Sets the Object array that will be carried by the Message.
169 *
170 * @param objIn
171 * An array of objects to be sent with the Message.
172 */
173 public void setAnObject(Object objIn) {
174
175 anObject = objIn;
176 }
177
178 /**
179 * Gets the Object that was carried by the Message.
180 *
181 * @return An object sent with the Message or null.
182 */
183 public Object getAnObject() {
184
185 return anObject;
186 }
187
188 /**
189 * Sets the integer message.
190 *
191 * @param msgIn
192 * The integer message.
193 */
194 public void setIntMessage(int msgIn) {
195
196 intMessage = msgIn;
197 }
198
199 /**
200 * Gets the integer message.
201 *
202 * @return The integer message.
203 */
204 public int getIntMessage() {
205
206 return intMessage;
207 }
208
209 /**
210 * Sets the message protocol.
211 *
212 * @param proto
213 * The message protocol.
214 */
215 public void setProtocol(int proto) {
216
217 protocol = proto;
218 }
219
220 /**
221 * Gets the message protocol.
222 *
223 * @return The message protocol.
224 */
225 public int getProtocol() {
226
227 return protocol;
228 }
229
230 /**
231 * Sets the next Message.
232 *
233 * @param messIn
234 * The next message in the linked list.
235 */
236 public void setNextMessage(Message messIn) {
237
238 next = messIn;
239 }
240
241 /**
242 * Gets the next Message.
243 *
244 * @return The next message in the linked list.
245 */
246 public Message getNextMessage() {
247
248 return next;
249 }
250
251 /**
252 * Returns a String representation of this object.
253 */
254 public String toString() {
255
256 String myString;
257
258 myString = "Source id = " + sourceID;
259 myString += "\nDest id = " + destID;
260 if( anObject != null ) {
261
262 myString += anObject.toString();
263 }
264 myString += "\n";
265 return myString;
266 }
267 }