1  //!-- UTF8
     2  /*
     3  Oregano Multiuser Server - Version 1.2.0 - January 4th, 2005
     4   
     5  	Web:  www.oregano-server.org
     6  	Mail: info@oregano-server.org
     7   
     8  	Copyright 2003 - 2004 - 2004 Jens Halm / Cologne, Germany
     9   
    10   This library is free software; you can redistribute it and/or
    11   modify it under the terms of the GNU Lesser General Public
    12   License as published by the Free Software Foundation; either
    13   version 2.1 of the License, or (at your option) any later version.
    14   
    15   This library is distributed in the hope that it will be useful,
    16   but WITHOUT ANY WARRANTY; without even the implied warranty of
    17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    18   Lesser General Public License for more details.
    19   
    20   You should have received a copy of the GNU Lesser General Public
    21   License along with this library; if not, write to the Free Software
    22   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23   */
    24  
    25  /*
    26  -------------------------------------------
    27  	Classe _Error
    28  
    29  	@description :
    30  	Code des erreurs.
    31  
    32  
    33  	@author Jens Halm copyright http://www.spicefactory.org/
    34  	@author erixtekila copyleft http://www.v-i-a.net  
    35  -------------------------------------------
    36  	version history :
    37  	1.2.0 : 18/01/05
    38  			- Portage en actionscript 2 pour le
    39  			compile time type checking
    40  	1.2.1 : 18/12/05
    41  	 		- Changement de nom pour éviter les conflits
    42  	 		avec la classe Error associée au exceptions du player.
    43  			Merci à Cosmin Cimpoi cosmin.cimpoi@monogroup.com
    44  -------------------------------------------
    45  */
    46  
    47  
    48  
    49  /**
    50   *	Gestion des erreurs.
    51   *
    52   *	@author Jens Halm copyright http://www.spicefactory.org/
    53   *	@author erixtekila copyleft http://www.v-i-a.net 
    54   *	@version 1.2.0
    55   */
    56  class org.omus.util._Error
    57  {
    58  	//--------------------
    59  	// PROPRIETES
    60  	//--------------------
    61  	/**
    62  	 *	Chaîne représentant l'erreur.
    63  	 */
    64  	private var code:String;
    65  	
    66  	/**
    67  	 *	Le nom de la méthode d'où provient l'erreur.
    68  	 */
    69  	private var method:String;
    70  	
    71  	/**
    72  	 *	Une liste de détails à traiter.
    73  	 */
    74  	private var args:Array;
    75  	
    76  	/**
    77  	 *	Tableau associatif des codes d'erreur
    78  	 */
    79  	public static var desc:Object;
    80  	
    81  	/**
    82  	 *	TODO
    83  	 */
    84  	public static var dbe:Object;
    85  	
    86  	
    87  	//--------------------
    88  	// CONSTRUCTEUR
    89  	//--------------------
    90  	/**
    91  	 *	Informations liées à une erreur du framework Oregano.
    92  	 *
    93  	 *	@param errCode		Le code de l'erreur.
    94  	 *	@param methodName		Fonction d'où l'erreur provient.
    95  	 *	@param aArgs			Une liste de détails liés à l'erreur.
    96  	 */
    97  	public function _Error (errCode:String, methodName:String, aArgs:Array) 
    98  	{
    99  		if (method == "execute")
   100  		{
   101  			code = errCode;
   102  		} else 
   103  		{
   104  			// simplify database error codes
   105  			code = _Error.dbe[errCode];
   106  			if (code == undefined) code = errCode;
   107  		}
   108  		method = methodName;
   109  		args = aArgs;
   110  		
   111  		// trace(this+ " installé.");
   112  	}
   113  	
   114  	//--------------------
   115  	// METHODES PUBLIQUES
   116  	//--------------------
   117  	/**
   118  	 *	Utilisé dans un contexte littéral
   119  	 *
   120  	 *	@return	Une chaine définissant l'objet
   121  	 */
   122  	public function toString():String
   123  	{
   124  		return format(0);
   125  	}
   126  	
   127  
   128  	
   129  	/**
   130  	 *	Renvoie le code d'une erreur.
   131  	 *
   132  	 *	@return		Le code sous forme chaîne.
   133  	 */
   134  	public function getCode ():String
   135  	{
   136  		return code;
   137  	}
   138  	
   139  	/**
   140  	 *	Renvoie le nom de la méthode d'où provient l'erreur.
   141  	 *
   142  	 *	@return		Un nom de fonction.
   143  	 */
   144  	public function getMethodName ():String
   145  	{
   146  		return method;
   147  	}
   148  	
   149  	/**
   150  	 *	Renvoie la liste des détails concernant l'erreur.
   151  	 *
   152  	 *	@return		Les paramètres détaillées de l'erreur.
   153  	 */
   154  	public function getArguments ():Array
   155  	{
   156  		return args;
   157  	}
   158  	
   159  	/**
   160  	 *	Renvoie la description associée au code de l'erreur.
   161  	 *
   162  	 *	@return		Une description de l'erreur.
   163  	 */
   164  	public function getDescription ():String
   165  	{
   166  		return _Error.desc[code];
   167  	}
   168  	
   169  	//--------------------
   170  	// METHODES PRIVEES
   171  	//--------------------
   172  	/**
   173  	 *	Renvoie une chaine formattée représentant l'erreur.
   174  	 *
   175  	 *	@param indent		Un nombre d'espace d'indentation pour le formattage.
   176  	 *	@return		Une chaîne.
   177  	 */
   178  	private function format (indent:Number):String
   179  	{
   180  		var s = "org.omus.util._Error:";
   181  		var names = ["error code", "description", "method name", "arguments"];
   182  		
   183  		var values = [code, _Error.desc[code], method, org.omus.util.Log.formatArray(args, indent + 1)];
   184  		for (var i = 0; i < 4; i++)
   185  		{
   186  			s += "\n";
   187  			for (var idx = 0; idx < indent; idx++) s += "  ";
   188  			s += names[i] + " = " + values[i];
   189  		}
   190  		return s;
   191  	}
   192  	
   193  	//--------------------
   194  	// METHODES STATIQUES
   195  	//--------------------
   196  	/**
   197  	 *	Utilisé dans un contexte littéral
   198  	 *	@return	Une chaine définissant l'objet
   199  	 */
   200  	public static function toLog():String
   201  	{
   202  		return "[Object _Error]";
   203  	}
   204  	
   205  	/**
   206  	 *	Initialisation des codes d'erreurs.
   207  	 */
   208  	public static function initDescriptions ():Void
   209  	{
   210  		var desc = new Object;
   211  		
   212  		// server side error codes
   213  		desc["clj-001"] = "property not found in object";
   214  		desc["clj-002"] = "method called with illegal arguments";
   215  		desc["clj-003"] = "org.omus.clazz: class name PropertySet is reserved";
   216  		desc["clj-004"] = "org.omus.group: target group has same name as current group";
   217  		desc["clj-005"] = "org.omus.group: changing groups already in progress";
   218  		desc["clj-006"] = "org.omus.session: cannot initialize while connected";
   219  		desc["clj-007"] = "org.omus.session: connection has already been established";
   220  		desc["clj-008"] = "org.omus.session: normal connection shutdown";
   221  		desc["clj-009"] = "org.omus.session: sending keep alive message";
   222  		desc["clj-010"] = "org.omus.session: incoming message";
   223  		desc["clj-011"] = "org.omus.session: cannot handle request while offline or changing groups";
   224  		desc["clj-012"] = "org.omus.session: outgoing message";
   225  		desc["clj-013"] = "org.omus.session: password encoder required";
   226  		desc["clj-065"] = "org.omus.session: session was not initialized";
   227  		desc["clj-066"] = "org.omus.session: reconnect port was not set";
   228  		desc["clj-014"] = "org.omus.DataParser: error converting array to row";
   229  		desc["clj-015"] = "org.omus.DataParser: class not registered in client";
   230  		desc["clj-016"] = "org.omus.Property: data type does not match configuration";
   231  		desc["clj-017"] = "org.omus.Property: no need to call setValue on synchronized tables";
   232  		desc["clj-018"] = "org.omus.Property: error parsing backup value";
   233  		desc["clj-019"] = "org.omus.PropertySet: property does not exist";
   234  		desc["clj-020"] = "org.omus.PropertySet: set no longer valid";
   235  		desc["clj-021"] = "org.omus.PropertySet: synchronize: no property was modified";
   236  		desc["clj-022"] = "org.omus.PropertySet: set no longer valid";
   237  		desc["clj-023"] = "org.omus.PropertySet: property does not exist";
   238  		desc["clj-024"] = "org.omus.PropertySet: property is already loaded";
   239  		desc["clj-064"] = "org.omus.PropertySet: all requested properties are already loaded";
   240  		desc["clj-025"] = "org.omus.PropertySet: set no longer valid";
   241  		desc["clj-026"] = "org.omus.PropertySet: property does not exist";
   242  		desc["clj-027"] = "org.omus.PropertySet: property does not exist";
   243  		desc["clj-067"] = "org.omus.PropertySet: property does not exist";
   244  		desc["clj-062"] = "org.omus.PropertyLoader: array of property names is empty";
   245  		desc["clj-063"] = "org.omus.PropertyLoader: array of property names can contain only strings";
   246  		desc["clj-028"] = "org.omus.Table: row does not match table definition";
   247  		desc["clj-029"] = "org.omus.Table: row does not match table definition";
   248  		desc["clj-030"] = "org.omus.Table: row does not match table definition";
   249  		desc["clj-031"] = "org.omus.Table: table does not contain row with given id";
   250  		desc["clj-032"] = "org.omus.TableBackup: error resetting table";
   251  		desc["clj-033"] = "org.omus.TableDefinition: attempt to add an column to an unmodifiable definition";
   252  		desc["clj-034"] = "org.omus.TableDefinition: illegal column name";
   253  		desc["clj-035"] = "org.omus.TableDefinition: duplicate column name";
   254  		desc["clj-036"] = "org.omus.TableDefinition: illegal field type";
   255  		desc["clj-037"] = "org.omus.UpdateSequence: duplicate call to remove for the same row";
   256  		desc["clj-038"] = "org.omus.UpdateSequence: attempt to update a removed row";
   257  		desc["clj-039"] = "org.omus.DbTransaction: illegal parameter value";
   258  		desc["clj-040"] = "org.omus.DbTransaction: constructor of transaction part was called with illegal arguments";
   259  		desc["clj-041"] = "org.omus.DbTransaction: duplicate resultID";
   260  		desc["clj-042"] = "org.omus.DbTransactionPart: illegal parameter value";
   261  		desc["clj-043"] = "org.omus.Mail: no need to load an attachment of a new mail";
   262  		desc["clj-044"] = "org.omus.Mail: cannot remove a mail that has not been sent yet";
   263  		desc["clj-045"] = "org.omus.Mail: cannot mark a mail that has not been sent yet";
   264  		desc["clj-068"] = "org.omus.Message: error parsing attachment";
   265  		desc["clj-046"] = "org.omus.MessageHandler: no handler for incoming message";
   266  		desc["clj-047"] = "org.omus.MessageRouter: missing cache value";
   267  		desc["clj-048"] = "org.omus.MessageRouter: missing cache value";
   268  		desc["clj-049"] = "org.omus.MessageRouter: no handler for incoming message";
   269  		desc["clj-061"] = "org.omus.MessageRouter: request timeout";
   270  		desc["clj-050"] = "org.omus.Messenger: no handler for incoming message";
   271  		desc["clj-051"] = "org.omus.Messenger: filtering incoming message";
   272  		desc["clj-069"] = "org.omus.Mailbox: some newMail message must have been lost";
   273  		desc["clj-052"] = "org.omus.EnvelopeFactory: illegal identifier";
   274  		desc["clj-053"] = "org.omus.EnvelopeFactory: illegal msgID";
   275  		desc["clj-054"] = "org.omus.EnvelopeFactory: illegal value for sender length";
   276  		desc["clj-055"] = "org.omus.EnvelopeFactory: illegal value for subject length";
   277  		desc["clj-056"] = "org.omus.EnvelopeFactory: illegal value for attachment length";
   278  		desc["clj-057"] = "org.omus.EnvelopeFactory: sender incomplete";
   279  		desc["clj-058"] = "org.omus.EnvelopeFactory: subject incomplete";
   280  		desc["clj-059"] = "org.omus.EnvelopeFactory: attachment incomplete";
   281  		desc["clj-060"] = "org.omus.EventDispatcher: firing event";
   282  		
   283  		// client side error codes
   284  		desc["ses-001"] = "internal server error";
   285  		desc["ses-002"] = "maximum number of connections exceeded";
   286  		desc["ses-003"] = "login denied by LoginExtension";
   287  		desc["ses-004"] = "wrong client versionID";
   288  		desc["ses-005"] = "server in debug mode or preparing for shutdown";
   289  		desc["ses-006"] = "user already logged in";
   290  		desc["ses-007"] = "user with given nick name already exists";
   291  		desc["ses-008"] = "user is banned";
   292  		desc["ses-009"] = "user with given email address already exists";
   293  		desc["ses-010"] = "user with given email address is banned";
   294  		desc["ses-011"] = "incorrect login";
   295  		desc["ses-012"] = "no connection to server";
   296  		desc["ses-013"] = "connection has already been established";
   297  		desc["ses-014"] = "cannot initialize while connected";
   298  		desc["msg-001"] = "unknown message type";
   299  		desc["msg-002"] = "error parsing message";
   300  		desc["msg-003"] = "missing GroupExtension for handling message";
   301  		desc["dbe-001"] = "unable to connect to database";
   302  		desc["dbe-002"] = "database error";
   303  		desc["dbe-003"] = "SQL error";
   304  		desc["dbe-004"] = "less than required minimum number of rows in ResultSet";
   305  		desc["dbe-005"] = "less than required minimum number of affected rows";
   306  		desc["dbe-006"] = "user is banned";
   307  		desc["dbe-007"] = "user does not exist";
   308  		desc["dbe-008"] = "group does not exist";
   309  		desc["dbe-009"] = "missing in-parameter";
   310  		desc["dbe-010"] = "missing out-parameter";
   311  		desc["dbe-011"] = "type of transaction part does not match configuration";
   312  		desc["dbe-012"] = "cannot handle fields set to SQL NULL";
   313  		desc["dbe-013"] = "DbTransaction was empty";
   314  		desc["dbe-014"] = "execution of one or more statements denied";
   315  		desc["cgr-001"] = "group does not exist";
   316  		desc["cgr-002"] = "group cannot be created";
   317  		desc["cgr-003"] = "group is closed";
   318  		desc["cgr-004"] = "user limit of group reached";
   319  		desc["cgr-005"] = "joining this group not permitted";
   320  		desc["grp-001"] = "login group cannot be opened or closed";
   321  		desc["grp-003"] = "client not owner of this lock";
   322  		desc["usr-001"] = "changing email address not permitted";
   323  		desc["usr-002"] = "changing password not permitted";
   324  		desc["usr-003"] = "changing permissions not permitted";
   325  		desc["usr-004"] = "illegal value for setting user permissions";
   326  		desc["mbx-001"] = "mailbox limit exceeded";
   327  		desc["mbx-002"] = "mail in outBox cannot be marked as read";
   328  		desc["bud-001"] = "buddy list already contains this user";
   329  		desc["bud-002"] = "buddy list did not contain this user";
   330  		desc["bud-003"] = "limit of buddy list exceeded";
   331  		desc["prp-001"] = "one or more properties do not exist";
   332  		desc["prp-002"] = "data type of one or more properties does not match configuration";
   333  		desc["prp-003"] = "synchronization rejected by server extension";
   334  		desc["prp-004"] = "PropertySet no longer valid";
   335  		desc["prp-005"] = "changing groups failed - properties reset";
   336  		desc["lgt-001"] = "logout requested by client";
   337  		desc["lgt-002"] = "logout requested by server extension";
   338  		desc["lgt-003"] = "logout forced by administrator";
   339  		desc["lgt-004"] = "user was banned";
   340  		desc["lgt-005"] = "server switched to debug mode";
   341  		desc["lgt-006"] = "server shutdown";
   342  		desc["lgt-007"] = "connection broken";
   343  		
   344  		_Error.desc = desc;
   345  		
   346  		// Erreurs de la base de données
   347  		var dberror = new Object();
   348  		dbe["dbe-003"] = "dbe-002";
   349  		dbe["dbe-004"] = "dbe-002";
   350  		dbe["dbe-005"] = "dbe-002";
   351  		dbe["dbe-006"] = "dbe-002";
   352  		dbe["dbe-010"] = "dbe-002";
   353  		dbe["dbe-011"] = "dbe-002";
   354  		dbe["dbe-012"] = "dbe-002";
   355  		dbe["dbe-013"] = "dbe-002";
   356  		dbe["dbe-014"] = "dbe-002";
   357  		
   358  		_Error.dbe = dberror;
   359  	}
   360  }
   361