home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetError.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.2 KB  |  89 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.util.Vector;
  7. import symjava.sql.SQLException;
  8.  
  9. class NetError extends ServerObject {
  10.    int _severity;
  11.    int _errorID;
  12.    int _type;
  13.    Vector _errorStr;
  14.    String _leader;
  15.  
  16.    NetError(byte severity, int errorID, String s1, String s2, String s3, String leader) {
  17.       this._severity = severity;
  18.       this._errorID = errorID;
  19.       this._errorStr = new Vector();
  20.       this._errorStr.addElement(new NetString(s1));
  21.       this._errorStr.addElement(new NetString(s2));
  22.       this._errorStr.addElement(new NetString(s3));
  23.       this._leader = leader;
  24.    }
  25.  
  26.    int getSeverity() {
  27.       return this._severity;
  28.    }
  29.  
  30.    int getID() {
  31.       return this._errorID;
  32.    }
  33.  
  34.    String getErrorString(int errorLevel) {
  35.       if (errorLevel > this._errorStr.size()) {
  36.          return new String("");
  37.       } else {
  38.          NetString s = (NetString)this._errorStr.elementAt(errorLevel);
  39.          return new String(s.getString());
  40.       }
  41.    }
  42.  
  43.    SQLException toSQLException() {
  44.       return (SQLException)(this._type == 8 ? new SQLConnectionException(this.getErrorString(0), this.getErrorString(1), this.getID()) : new SQLException(this.getErrorString(0), this.getErrorString(1), this.getID()));
  45.    }
  46.  
  47.    NetError() {
  48.    }
  49.  
  50.    int getType() {
  51.       return 49;
  52.    }
  53.  
  54.    void read(DataInputStream in) throws SQLException, IOException, ErrorException {
  55.       in.readShort();
  56.       byte[] leader = new byte[4];
  57.       in.readFully(leader, 0, 4);
  58.       this._leader = new String(leader, 0);
  59.       this._severity = in.readByte();
  60.       this._errorID = in.readInt();
  61.       this._type = in.readInt();
  62.       this._errorStr = new Vector();
  63.  
  64.       for(int i = 0; i < 3; ++i) {
  65.          ServerObject obj = (ServerObject)NetClass.getNextObject(in);
  66.          if (obj.getType() == 52) {
  67.             this._errorStr.addElement(obj);
  68.          } else {
  69.             ((ServerObject)this).onObjectError(obj);
  70.          }
  71.       }
  72.  
  73.    }
  74.  
  75.    void write(DataOutputStream out) throws IOException {
  76.       out.writeByte(this.getType());
  77.       out.writeShort(9);
  78.       out.writeBytes(this._leader);
  79.       out.writeByte(this._severity);
  80.       out.writeInt(this._errorID);
  81.  
  82.       for(int i = 0; i < 3; ++i) {
  83.          NetString s = (NetString)this._errorStr.elementAt(i);
  84.          s.write(out);
  85.       }
  86.  
  87.    }
  88. }
  89.