FileDocCategorySizeDatePackage
Message.javaAPI DocExample3040Sun Mar 23 19:41:28 GMT 1997dcj.util.Collaborative

Message

public class Message extends Object

Fields Summary
protected String
id
protected Vector
argList
protected String
endToken
Constructors Summary
public Message()


    
    id = "message";
    argList = new Vector();
  
public Message(String mid)

    id = mid;
    argList = new Vector();
  
Methods Summary
public booleanDo()

    return false;
  
public voidaddArg(java.lang.Object arg)

    argList.addElement(arg);
  
public java.util.VectorargList()

    Vector listCopy = (Vector)argList.clone();
    return listCopy;
  
public java.lang.ObjectgetArg(int idx)

    Object arg = null;
    if (idx < argList.size()) {
      arg = argList.elementAt(idx);
    }

    return arg;
  
public booleanhandles(java.lang.String msgId)

 return false; 
public java.lang.StringmessageID()

    return id;
  
public MessagenewCopy()

 return new Message(id); 
public booleanreadArgs(java.io.InputStream ins)

    boolean success = true;
    
    // Read tokens until the "end-of-message" token is seen.
    try {
      DataInputStream din = new DataInputStream(ins);
      String token = din.readUTF();
      while (token.compareTo(endToken) != 0) {
        // If an object argument is coming, read with an ObjectInputStream
        if (token.compareTo("#OBJ") == 0) {
          // Next argument is a non-string Object
          ObjectInputStream oin = new ObjectInputStream(ins);
          Object oarg = oin.readObject();
          addArg(oarg);
        }
        else {
          // The string itself is the argument, so save it
          addArg(token);
        }
        token = din.readUTF();
      }
    }
    catch (Exception e) {
      // Failed to read complete argument list.
      success = false;
    }
    return success;
  
public voidsetId(java.lang.String mid)

    id = mid;
  
public booleanwriteArgs(java.io.OutputStream outs)

    int len = argList.size();
    boolean success = true;
    
    // Write each argument in order
    try {
      DataOutputStream dout = new DataOutputStream(outs);

      for (int i = 0; i < len; i++) {
        Object arg = argList.elementAt(i);
        try {
          String sarg = (String)arg;
          System.out.println("m: sending token \"" + sarg + "\"");
          dout.writeUTF(sarg);
        }
        catch (ClassCastException ce) {
          // Argument wasn't a string, so send it as an object
          System.out.println("m: sending object");
          dout.writeUTF("#OBJ");
          ObjectOutputStream oout = new ObjectOutputStream(outs);
          oout.writeObject(arg);
        }
        catch (Exception e) {
          // Something else went wrong, indicate failure
          success = false;
          System.out.println("m: Got exception writing args");
        }
      }

      // Finish with the end-of-message token
      dout.writeUTF(endToken);
    }
    catch (Exception e) {
      success = false;
    }
    return success;