home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / sys / msg.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  5.4 KB  |  187 lines

  1. /*
  2. * @(#)Msg.java    1.0 95/11/09 Ulrich Gall & Jan Kautz
  3. *
  4. * Copyright (c) 1996 Ulrich Gall & Jan Kautz 
  5. * uhgall@cip.informatik.uni-erlangen.de
  6. * Hofmannstr. 48, D-91052 Erlangen, Germany, Fax: +49-9131-201358
  7. *
  8. * Permission to use, copy, and distribute this software
  9. * and its documentation for NON-COMMERCIAL purposes and without
  10. * fee is hereby granted provided that this copyright notice
  11. * appears in all copies. Please contact us for  further copyright 
  12. * and licensing information.
  13. *
  14. * WE MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15. * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WE SHALL NOT BE LIABLE FOR
  18. * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19. * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20. */
  21.  
  22. package como.sys;
  23.  
  24. /**
  25.  * This is used for sending messages over the net. A Msg can include an object
  26.  * that implements Saveable.
  27.  * Some classes are inherently supported (String, Integer, Dictionary)
  28.  * 
  29.  * Just like an Event, a Msg has a type (integer). For your own messages
  30.  * you can pick any types > 10000. We strongly recommend increasing the
  31.  * numbers the further you go down the Object hierarchy.
  32.  * 
  33.  * For messages, type should be >0. Right now, answers are implemented as
  34.  * negative types. The answer is  the inverse of the question.
  35.  */
  36.  
  37. public class Msg extends Object {
  38.     public static final int NOT_ALLOWED = 0;
  39.     public static final int NO_CONNECTION = 1;
  40.     public static final int OK = 2;
  41.     public static final int WHO_AM_I = 3;
  42.     public static final int WHO_ELSE = 4;
  43.     public static final int COM_CLASS = 6;
  44.     public static final int CONNECT_TO_EXISTING_COM = 7;
  45.     public static final int INVITATION = 8;
  46.     public static final int MAKE_SOCKET = 9;
  47.     public static final int LOAD_CLASS = 10;
  48.     public static final int LINE_DROPPED = 11;
  49.     public static final int NO_DATA = 12;
  50.     public static final int PRIVATE_DATA = 13;
  51.     public static final int ARE_YOU_THERE = 14;
  52.     public static final int CLASS_CODE = 15;
  53.     public static final int PING = 16;
  54.     public static final int GET_USER_INFO = 17;
  55.     public static final int ASK_MASTER = 18;
  56.     public static final int UPCOMING_USER = 19;
  57.     public static final int NEW_TOPIC = 20;
  58.     public static final int NEW_USER_INFO = 21;
  59.     public static final int NEW_MASTER = 22;
  60.     public static final int KICK_USER = 23;
  61.  
  62.     // Comlet
  63.  
  64.     public static final int USER_LEFT = 101;
  65.     public static final int ADD_USER = 102;
  66.  
  67.     // WindowComlet
  68.  
  69.     public static final int WINDOW_MOVED = 103;
  70.  
  71.     // Chat
  72.     public static final int CHAT_DIALOG_STRING = 500;
  73.     public static final int CHAT_PERSONAL_STRING = 501;
  74.  
  75.     // x > 10000 can be used by Clients without registering them here.
  76.     // Just make sure you're not using a MSG ID from a parent class.
  77.  
  78.     public int from;
  79.     public int to;
  80.     public Object arg;  // can be everything!
  81.     public int type;
  82.  
  83.     /**
  84.     * Message Priority: 0 = highest Priority
  85.     */
  86.     public int priority;
  87.  
  88.     /**
  89.      * Contructor for a message.
  90.      * @param typ the type of the Message (e.g. NEW_USER_INFO)
  91.      * @param f the sender's ID
  92.      * @param t the ID you want to send the message to.
  93.      * @param o the Object you want to send (must implement Saveable or be support java.lang-Object)
  94.      */
  95.     public Msg( int typ, int f, int t, Object o ) {
  96.         type = typ;
  97.         from = f;
  98.         to = t;
  99.         arg = o;
  100.     }
  101.  
  102.     /**
  103.      * Contructor for a message.
  104.      * @param typ the type of the Message (e.g. NEW_USER_INFO)
  105.      * @param f the sender's ID
  106.      * @param t the ID you want to send the message to.
  107.      * @param p the message's priority (0 highest).
  108.      * @param o the Object you want to send (must implement Saveable or
  109.      *  must be supported by como.io.ObjectXXXStream).
  110.      */
  111.     public Msg( int typ, int f, int t, int p,Object c ) {
  112.         type = typ;
  113.         from = f;
  114.         to = t;
  115.         arg = c;
  116.         priority = p;
  117.     }
  118.  
  119.     /**
  120.      * Contructor for a message. The sender's ID is not set,
  121.      * but is usually set by the ComObj automatically.
  122.      * @param typ the type of the Message (e.g. NEW_USER_INFO)
  123.      * @param t the ID you want to send the message to.
  124.      * @param o the Object you want to send (must implement Saveable or
  125.      *  must be supported by como.io.ObjectXXXStream).
  126.      */
  127.       public Msg(int type, int to, Object arg) {
  128.         this.to = to;
  129.         this.type = type;
  130.         this.arg = arg;
  131.       }
  132.  
  133.     /**
  134.      * Contructor for a message.
  135.      * @param typ the type of the Message (e.g. NEW_USER_INFO)
  136.      * @param o the Object you want to send (must implement Saveable or
  137.      *  must be supported by como.io.ObjectXXXStream).
  138.      */
  139.     public Msg( int typ, Object c ) {
  140.         this( typ, 0, 0, c );
  141.     }
  142.  
  143.     /**
  144.      * Contructor for a message.
  145.      * @param typ the type of the Message (e.g. NEW_USER_INFO)
  146.      */
  147.     public Msg( int typ ) {
  148.         this( typ, 0, 0, null );
  149.     }
  150.  
  151.     /**
  152.      * Checks if the current msg is an answer-message.
  153.      * @return true if the message is an answer.
  154.      */
  155.     public boolean isAnswer() {
  156.         if( type < 0 )
  157.         return true;
  158.         else
  159.         return false;
  160.     }
  161.  
  162.     /**
  163.      * Make the msg to an answer or non-answer-message.
  164.      * @param isanswer set to true, if you want to make an answer.
  165.      */
  166.     public void setAnswer( boolean isanswer ) {
  167.         if( isanswer )
  168.         type = -Math.abs( type );
  169.         else
  170.         type = Math.abs( type );
  171.     }
  172.  
  173.     /**
  174.      * Returns a String object representing this message.
  175.      * @return the String.
  176.      */
  177.     public String toString()
  178.     {
  179.         if( arg != null )
  180.             return( "Msg(): type: " + type + " from: " + from +
  181.             " to: " + to + " cont: " + arg.toString() );
  182.         else
  183.             return( "Msg(): type: " + type + " from: " + from +
  184.             " to: " + to + " arg: empty " );
  185.     }
  186. }
  187.