/**************************************************
   Root class for all the Graph Domain Exception

   Current Scheme is:
     use ID to indentify different kinds of exceptions

   Rename to JOWException, 121098 Yufei Qian

***************************************************/

package jow;

public class JOWException extends java.lang.Exception {
  int type;

  Object obj=null;

  public static final int BuildFail  = 001;

  public static final int RemoteException =010;

  public static final int GONotFound  = 100;
  public static final int FileNotFound =110;

  //public static final int RWException = 200;
  public static final int ReadException =210;
  public static final int WriteException =220;

  public static final int CREATE_GRAPH_FAIL =300;

  /* Ticket related */
  public static final int TICKET_INVALID = 400;

  /* ACL related */
  public static final int ACL_NO_CREATE = 500;
  public static final int NO_ACCESS =600;

  /** User/group related */

  public static final int USERNAME_CONFLICT = 1000;
  public static final int USERNAME_NOTEXIST = 1001;

  /*commented by Yufei Qian */
  //to support N-Server architecture
  //when login/password are not correct, USER_INVALID DomainException will be thrown
  //this makes it possible to support N-Server architecture across domains

  public static final int USER_INVALID=1002;
  public static final int USER_INGROUP = 1003;
  public static final int GROUPNAME_CONFLICT = 1010;
  public static final int GROUPNAME_NOTEXIST = 1011;

  public static final int ALLGROUP_NOTDELETE =1100;
  public static final int ALLUSER_NOTDELETE  =1101;
  /** Concurrency related */

  public static final int CONCURRENT_WRITE =1500;

  public static final int OIDERROR = 2000;

  public static final int IOException = 3001;
  public static final int ClassNotFound = 3002;

  private String m_strDomainName;


  public JOWException(int type) {
    super();
    this.type=type;
    m_strDomainName="no domain name";

  }

  public JOWException(int type, String strDomainName) {
    super();
    this.type=type;
    m_strDomainName=strDomainName;
  }

  public int getType() {
    return type;
  }

  public String getDomainName() {
    return m_strDomainName;
  }
  /** override super class's getMessage method, produce message on the fly*/
  public String getMessage() {
    String msg;
    switch (this.type) {
        case BuildFail: msg=new String("Domain Service build failure!"); break;
        case RemoteException:  msg=new String(" It is a Remote Exception "); break;
        case GONotFound: msg=new String("Object not found"); break;
        case FileNotFound: msg=new String("File not found"); break;
        case ReadException: msg=new String("Object read error!"); break;
        case WriteException: msg=new String("Object write error!"); break;
        case ACL_NO_CREATE: msg=new String("user has no access to create object in this partition"); break;
        case CREATE_GRAPH_FAIL: msg=new String("create object fail"); break;
        case NO_ACCESS: msg=new String("user has no access"); break;

        case CONCURRENT_WRITE: msg=new String("concurrent write exception"); break;
        case TICKET_INVALID: msg=new String("session Ticket invalid"); break;

        case USERNAME_CONFLICT: msg=new String("USERNAME_CONFLICT"); break;
        case USERNAME_NOTEXIST: msg=new String("USERNAME_NOTEXIST"); break;
        case USER_INGROUP: msg=new String("User is a memeber of some group"); break;

        case GROUPNAME_CONFLICT:  msg=new String(" GROUPNAME_CONFLICT"); break;
        case GROUPNAME_NOTEXIST : msg=new String("GROUPNAME_NOTEXIST "); break;
        case USER_INVALID : msg=new String("Invalid user"); break;

        case ALLUSER_NOTDELETE : msg=new String(" ALLUSER  not deletable"); break;
        case ALLGROUP_NOTDELETE : msg=new String("ALLGROUP not deletable"); break;

        default: msg=new String("Some error!"); break;
    }
    return new String(" Domain Exception: "+msg);
  }
}

