KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > objects > ChannelDescription


1 /* ----- BEGIN LICENSE BLOCK -----
2  * Version: MPL 1.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the DataShare server.
15  *
16  * The Initial Developer of the Original Code is
17  * Ball Aerospace & Technologies Corp, Fairborn, Ohio
18  * Portions created by the Initial Developer are Copyright (C) 2001
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s): Charles Wood <cwood@ball.com>
22  *
23  * ----- END LICENSE BLOCK ----- */

24 /* RCS $Id: ChannelDescription.java,v 1.2 2002/02/04 13:52:48 lizellaman Exp $
25  * $Log: ChannelDescription.java,v $
26  * Revision 1.2 2002/02/04 13:52:48 lizellaman
27  * Remove all references to past product names (or)
28  * Add PublicAPI for creating Rendezvous Sessions
29  *
30  * Revision 1.1.1.1 2001/10/23 13:37:20 lizellaman
31  * initial sourceforge release
32  *
33  */

34
35 package org.datashare.objects;
36
37 import java.util.Vector JavaDoc;
38
39 /**
40  * Used to describe a Channel that a Client should use to communicate with
41  * the DataShareServer. The Channel described is a data channel that the
42  * DataShareServer will use to exchange data between clients that are connected
43  * to it. This object is not sent directly, but instead is sent by the
44  * DataShareServer over the commandStatusChannel as part of a
45  * ChannelDescriptionArray object.
46  *
47  * @since Version 2
48  * @author Charles Wood
49  * @see ChannelDescriptionArray
50  */

51 public class ChannelDescription implements java.io.Serializable JavaDoc
52    {
53    /**
54     * this allows us to serialize this class without 'marshalling' errors.
55     *
56     */

57    static final long serialVersionUID = 9030546546411490936L;
58
59    // valid values for the 'type' field
60
/**
61     * valid value for the 'type' attribute used when the connection is unknown
62     */

63    public final static int UNKNOWN = 0;
64
65    /**
66     * valid value for the 'type' attribute, used for TCP type connections
67     *
68     */

69    public final static int TCP = 1;
70
71    /**
72     * valid value for the 'type' attribute, used for UDP type connections
73     *
74     */

75    public final static int UDP = 2;
76
77    /**
78     * valid value for the 'type' attribute, used for Multicast type connections
79     *
80     */

81    public final static int MULTICAST = 3;
82
83    /**
84     * Used when a String representation of the type attribute is desired, the type value
85     * is the index into this array.
86     *
87     */

88    public static final String JavaDoc[] validTypes = {"Unknown","TCP","UDP","MultiCast"};
89
90    /**
91     * Provides the name of this Channel
92     *
93     */

94    public String JavaDoc channelName;
95
96    /**
97     * Provides Clients with the the class used to handle data for this Channel
98     * (the class of the Rendezvous function), applies only to data channels for Rendezvous Functions,
99     * otherwise, not used. Note that the full package name is required.
100     *
101     */

102    public String JavaDoc channelClass; // class for function that uses this Channel, full package needed
103

104    /**
105     * descriptive comment about the Channel, used for display purposes only
106     *
107     */

108    public String JavaDoc channelDescription;
109
110    /**
111     * describes the type of Channel, valid values are TCP, UDP, and MULTICAST
112     *
113     */

114    public int type; // defined above
115

116    /**
117     * provides the Client with the name of the jar file in which to look for the
118     * channelClass, used only for Rendezvous functions.
119     *
120     */

121    public String JavaDoc channelJarFileName; // jar file that has classes needed by channelClass
122

123    /**
124     * indicates if DataShareServer is persisting the data in this Channel to EJBs
125     *
126     */

127    public boolean persist; // user will have a chance to change this before creating the Channel
128

129    /**
130     * indicates if this function is allowed to persist data, true indicates that it is,
131     * false indicates that this function should never save any data (persist will be set to
132     * false and the user should not be offered the persist data option)
133     */

134    public boolean allowPersistSelection = true; // preset to true for backward compatibility
135

136    /**
137     * indicates that the Client should this Channel's checkBox pre-checked in the
138     * New Session Dialog Frame, indicating a desire to have this type of Channel
139     * in a Session. The user has to de-select the check box to avoid putting this
140     * type of Channel into a Session.
141     *
142     */

143    public boolean selectionPreSet; // if true, the dialog box will have this channel pre-selected
144

145    /**
146     * used to set the delay that the server inserts between each packet sent to a client when
147     * history has been requested.
148     */

149    public int historyDelay = 0;
150
151    /**
152     * used as the count of how many EJBs to retrieve at one time when getting ready to send data
153     * to clients as history. A negative, or zero count indicates get next EJB, send it, repeat...
154     */

155    public int historyCountInc = 100;
156
157    // if persist is true at time of channel closing, and these values are != null, sever will save
158
// file to DK using these values below to generate the file
159
/**
160     * indicates what type of file is generated by the data in this Channel if the
161     * data is to be archived to DocumentKonnect
162     *
163     */

164    public String JavaDoc mimeType; // the MIME type that the archived data will be save as
165

166    /**
167     * indicates the file extension for the file genererated by the data in this
168     * Channel if the data is to be archived to DocumentKonnect
169     *
170     */

171    public String JavaDoc fileExtension; // the extension that the file should have, should agree with the MIME type
172

173    /**
174     * Provides the DataShareServer with the the class used to handle data for
175     * this Channel (the class of the Rendezvous function) when archiving this Channel's
176     * data to DocumentKonnect. Note that the full package name is required.
177     *
178     */

179    public String JavaDoc archiveChannelClass; // class that server can use to archive data from this function
180

181    /**
182     * Provides the DataShareServer with the method in the archiveChannelClass
183     * to call so that the data that was archived to EJBs can be re-processed prior
184     * to calling the archiveChannelGetDataMethod to create the file for DocumentKonnect.
185     *
186     */

187    public String JavaDoc archiveChannelSetDataMethod; // method in archiveChannelClass that will be called with DataShareObjects
188

189    /**
190     * Provides the DataShareServer with the method to call in the archiveChannelClass
191     * to genereate the DocumentKonnect file (after all the EJB persisted data has
192     * been sent to the archiveChannelSetDataMethod).
193     *
194     */

195    public String JavaDoc archiveChannelGetDataMethod; // method in archiveChannelClass that will return byte[] from all the DataShareObjects
196

197    /**
198     * Constructor, should only be used when creating the command status connection.
199     * The only information needed by a client to create the commandStatus connection
200     * is the Server IP address and port number. All other information is set by this
201     * empty constructor.
202     */

203    public ChannelDescription()
204       {
205       this("commandStatus", /* channelName */
206            "", /* channelClass */
207            "communicates with Server", /* channelDescription */
208            ChannelDescription.TCP, /* type */
209            "", /* channelJarFileName, not used for commandStatus channel */
210            false, /* allowPersistSelection, not used for commandStatus channel */
211            false, /* persist, do not persist commandStatus data */
212            false, /* selectionPreset, not used for commandStatus channel */
213            0, /* historyDelay, not used for commandStatus channel */
214            0); /* historyCountInc, not used for commandStatus channel */
215       }
216
217    /**
218     * Constructor, should only be used when creating a single channel (per Session)
219     * data connection for a non-PpKClient client. There will be no history available.
220     * param channelType must be choosen from ChannelDescription.TCP, ChannelDescription.UDP,
221     * or ChannelDescription.MULTICAST
222     */

223    public ChannelDescription(String JavaDoc channelName, String JavaDoc channelDescription, int channelType)
224       {
225       this(channelName, /* channelName */
226            "", /* channelClass */
227            channelDescription, /* channelDescription */
228            channelType, /* type */
229            "", /* channelJarFileName, not used for commandStatus channel */
230            false, /* allowPersistSelection, not used for commandStatus channel */
231            false, /* persist, do not persist commandStatus data */
232            false, /* selectionPreset, not used for commandStatus channel */
233            0, /* historyDelay, not used for commandStatus channel */
234            0); /* historyCountInc, not used for commandStatus channel */
235       }
236
237    /**
238     * Constructor, describes a Channel that will not be archived
239     *
240     * @param channelName sets instance variable channelName
241     * @param channelClass sets instance variable channelClass
242     * @param channelDescription sets instance variable channelDescription
243     * @param type sets instance variable type
244     * @param channelJarFileName sets instance variable channelJarFileName
245     * @param allowPersistSelection set instance variable allowPersistSelection
246     * @param persist sets instance variable persist
247     * @param selectionPreSet sets instance variable selectionPreSet
248     * @param historyDelay sets the time to delay between sending packets from history, zero is no delay
249     * @param historyCountInc set the number of EJBs to retrieve from history per call to getData()
250     */

251    public ChannelDescription(String JavaDoc channelName,
252                              String JavaDoc channelClass,
253                              String JavaDoc channelDescription,
254                              int type,
255                              String JavaDoc channelJarFileName,
256                              boolean allowPersistSelection,
257                              boolean persist,
258                              boolean selectionPreSet,
259                              int historyDelay,
260                              int historyCountInc)
261       {
262       this.channelName = channelName;
263       this.channelClass = channelClass;
264       this.channelDescription = channelDescription;
265       this.type = type;
266       this.channelJarFileName = channelJarFileName;
267       this.allowPersistSelection = allowPersistSelection;
268       this.persist = persist;
269       this.selectionPreSet = selectionPreSet;
270       this.historyDelay = historyDelay;
271       this.historyCountInc = historyCountInc;
272       }
273
274    /**
275     * Constructor, describes a Channel that will not be archived, differs from the
276     * previous constructor by using a String for the type parameter
277     *
278     * @param channelName sets instance variable channelName
279     * @param channelClass sets instance variable channelClass
280     * @param channelDescription sets instance variable channelDescription
281     * @param type sets instance variable type
282     * @param channelJarFileName sets instance variable channelJarFileName
283     * @param allowPersistSelection set instance variable allowPersistSelection
284     * @param persist sets instance variable persist
285     * @param selectionPreSet sets instance variable selectionPreSet
286     * @param historyDelay sets the time to delay between sending packets from history, zero is no delay
287     * @param historyCountInc set the number of EJBs to retrieve from history per call to getData()
288     */

289    public ChannelDescription(String JavaDoc channelName,
290                              String JavaDoc channelClass,
291                              String JavaDoc channelDescription,
292                              String JavaDoc channelType, // this is the parameter that changed
293
String JavaDoc channelJarFileName,
294                              boolean allowPersistSelection,
295                              boolean persist,
296                              boolean selectionPreSet,
297                              int historyDelay,
298                              int historyCountInc)
299       {
300       this(channelName, channelClass, channelDescription, convertStringTypeToInt(channelType), channelJarFileName, allowPersistSelection, persist, selectionPreSet, historyDelay, historyCountInc );
301       }
302
303    /**
304     * Constructor, describes a Channel that may be archived
305     *
306     * @param channelName sets instance variable channelName
307     * @param channelClass sets instance variable channelClass
308     * @param channelDescription sets instance variable channelDescription
309     * @param type sets instance variable type
310     * @param channelJarFileName sets instance variable channelJarFileName
311     * @param allowPersistSelection set instance variable allowPersistSelection
312     * @param persist sets instance variable persist
313     * @param selectionPreSet sets instance variable selectionPreSet
314     * @param historyDelay sets the time to delay between sending packets from history, zero is no delay
315     * @param historyCountInc set the number of EJBs to retrieve from history per call to getData()
316     * @param mimeType sets instance variable mimeType
317     * @param fileExtension sets instance variable fileExtention
318     * @param archiveChannelClass sets instance variable archiveChannelClass
319     * @param archiveChannelSetDataMethod sets instance variable archiveChannelSetDataMethod
320     * @param archiveChannelGetDataMethod set instance variable archiveChannelGetDataMethod
321     */

322    public ChannelDescription(String JavaDoc channelName,
323                              String JavaDoc channelClass,
324                              String JavaDoc channelDescription,
325                              int type,
326                              String JavaDoc channelJarFileName,
327                              boolean allowPersistSelection,
328                              boolean persist,
329                              boolean selectionPreSet,
330                              int historyDelay,
331                              int historyCountInc,
332                              String JavaDoc mimeType, // the MIME type that the archived data will be save as
333
String JavaDoc fileExtension,
334                              String JavaDoc archiveChannelClass, // class that server can use to archive data from this function
335
String JavaDoc archiveChannelSetDataMethod, // method in archiveChannelClass that will be called with DataShareObjects
336
String JavaDoc archiveChannelGetDataMethod // method in archiveChannelClass that will return byte[] from all the DataShareObjects
337
)
338       {
339       this(channelName, channelClass, channelDescription, type, channelJarFileName, allowPersistSelection, persist, selectionPreSet, historyDelay, historyCountInc);
340       this.mimeType = mimeType;
341       this.fileExtension = fileExtension;
342       this.archiveChannelClass = archiveChannelClass;
343       this.archiveChannelSetDataMethod = archiveChannelSetDataMethod;
344       this.archiveChannelGetDataMethod = archiveChannelGetDataMethod;
345       }
346
347    /**
348     * Constructor, describes a Channel that may be archived, uses String for the type parameter
349     *
350     * @param channelName sets instance variable channelName
351     * @param channelClass sets instance variable channelClass
352     * @param channelDescription sets instance variable channelDescription
353     * @param type sets instance variable type
354     * @param channelJarFileName sets instance variable channelJarFileName
355     * @param allowPersistSelection set instance variable allowPersistSelection
356     * @param persist sets instance variable persist
357     * @param selectionPreSet sets instance variable selectionPreSet
358     * @param historyDelay sets the time to delay between sending packets from history, zero is no delay
359     * @param historyCountInc set the number of EJBs to retrieve from history per call to getData()
360     * @param mimeType sets instance variable mimeType
361     * @param fileExtension sets instance variable fileExtention
362     * @param archiveChannelClass sets instance variable archiveChannelClass
363     * @param archiveChannelSetDataMethod sets instance variable archiveChannelSetDataMethod
364     * @param archiveChannelGetDataMethod set instance variable archiveChannelGetDataMethod
365     */

366    public ChannelDescription(String JavaDoc channelName,
367                              String JavaDoc channelClass,
368                              String JavaDoc channelDescription,
369                              String JavaDoc channelType,
370                              String JavaDoc channelJarFileName,
371                              boolean allowPersistSelection,
372                              boolean persist,
373                              boolean selectionPreSet,
374                              int historyDelay,
375                              int historyCountInc,
376                              String JavaDoc mimeType, // the MIME type that the archived data will be save as
377
String JavaDoc fileExtension,
378                              String JavaDoc archiveChannelClass, // class that server can use to archive data from this function
379
String JavaDoc archiveChannelSetDataMethod, // method in archiveChannelClass that will be called with DataShareObjects
380
String JavaDoc archiveChannelGetDataMethod // method in archiveChannelClass that will return byte[] from all the DataShareObjects
381
)
382       {
383       this(channelName, channelClass, channelDescription, convertStringTypeToInt(channelType), channelJarFileName, allowPersistSelection, persist, selectionPreSet, historyDelay, historyCountInc,
384            mimeType, fileExtension, archiveChannelClass, archiveChannelSetDataMethod, archiveChannelGetDataMethod);
385       }
386
387    /**
388     * takes the string representation of ChannelType and converts it to the int value
389     *
390     * @param channelType can be "TCP","UDP", or "MULTICAST"; case is not important
391     */

392    private static int
393    convertStringTypeToInt(String JavaDoc channelType)
394       {
395       int type = TCP; // default value
396
for(int x=0; x<validTypes.length; x++)
397          {
398          if(channelType.toLowerCase().equals(validTypes[x].toLowerCase()))
399             {
400             type = x;
401             break;
402             }
403          }
404
405       return type;
406       }
407
408    }
409
Popular Tags