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 ObjectProperty
    28  
    29  	@description :
    30  	Classe de propriétés persistantes.
    31  	Extends Property
    32  
    33  
    34  	@author Jens Halm copyright http://www.spicefactory.org/
    35  	@author erixtekila copyleft http://www.v-i-a.net  
    36  -------------------------------------------
    37  	version history :
    38  	1.2.0 : 17/01/05
    39  			- Portage en actionscript 2 pour le
    40  			compile time type checking
    41  -------------------------------------------
    42  */
    43  
    44  import org.omus.data.Property;
    45  import org.omus.data.DataParser;
    46  
    47  /**
    48   *	Classe de base des propriétés persistantes.
    49   *
    50   *	@author Jens Halm copyright http://www.spicefactory.org/
    51   *	@author erixtekila copyleft http://www.v-i-a.net 
    52   *	@version 1.2.0
    53   */
    54  class org.omus.data.ObjectProperty extends Property
    55  {
    56  	//--------------------
    57  	// PROPRIETES
    58  	//--------------------
    59  	
    60  	//--------------------
    61  	// CONSTRUCTEUR
    62  	//--------------------
    63  	/**
    64  	 *	TODO
    65  	 *
    66  	 *	@param nm			Nom de la propriété.
    67  	 *	@param tp			Type attaché à la propriété.
    68  	 *	@param cl			Classe.
    69  	 *	@param ch			Liste du cache.
    70  	 *	@param vl			Valeur de la propriété.	
    71  	 */
    72  	public function ObjectProperty (nm:String, tp:String, cl:Object, ch:Array, vl:Object)
    73  	{
    74  		super(nm, tp, cl, ch, vl.value);
    75  		
    76  		// Propriétés
    77  		backup = vl.backup;
    78  		
    79  		// trace(this+ " installé.");
    80  	}
    81  	
    82  	//--------------------
    83  	// METHODES PUBLIQUES
    84  	//--------------------
    85  	/**
    86  	 *	Utilisé dans un contexte littéral
    87  	 *	@return	Une chaine définissant l'objet
    88  	 */
    89  	public function toString ():String
    90  	{
    91  		return "[Object ObjectProperty]\n" + format(0);
    92  	}
    93  
    94  
    95  	/**
    96  	*	Mise à jour de la propriété après synchronisation.
    97  	 *
    98  	 *	@param newVal		Une nouvelle valeur.
    99  	 *	@param clientReq	true si la demande émane du client.
   100  	 */
   101  	public function update (newVal:Object, clientReq:Boolean):Void
   102  	{
   103  		// synced Date, Object, Array
   104  		this.value = newVal.value;
   105  		this.backup = newVal.backup;
   106  		if (! propSet.marsh.contains(name)) modified = false;
   107  	}
   108  	
   109  	/**
   110  	 *	Annule la modification d'un propriété.
   111  	 *	Utile lors d'un échec de synchronisation.
   112  	 */
   113  	public function reset ():Void
   114  	{ 
   115  		// synced Date, Object, Array
   116  		if (typeof(backup) == "number")
   117  		{
   118  			// date property
   119  			value = new Date();
   120  			value.setTime(backup);
   121  		} else 
   122  		{
   123  			// array, object
   124  			var dp = new DataParser(backup, 0);
   125  			value = dp.nextValue(false);
   126  			if (dp.error != null)
   127  			{
   128  				// Logs internes
   129  				_global.oregano.iLog.error("clj-018", "property name = " + this.name + " - error = " + dp.error);
   130  				value = null;
   131  			}
   132  		}
   133  		if (! propSet.marsh.contains(name)) modified = false;
   134  	}
   135  	//--------------------
   136  	// METHODES PRIVEES
   137  	//--------------------
   138  
   139  	
   140  	//--------------------
   141  	// METHODES STATIQUES
   142  	//--------------------
   143  	/**
   144  	*	Formate une chaîne de représenation de l'objet.
   145  	 *
   146  	 *	@param indent		Numbre d'espace d'indentation.
   147  	 *	@return				Une chaîne formatée.
   148  	 */
   149  	private function format (indent:Number):String
   150  	{
   151  		var s= "org.omus.data.ObjectProperty:";
   152  		var arr = ["name", "type", "modified"];
   153  		var long = arr.length;
   154  		for (var i = 0; i < long ; i++) 
   155  		{
   156  			s += "\n";
   157  			for (var idx = 0; idx < indent; idx++) s += "  ";
   158  			s += arr[i] + " = " + this[arr[i]];
   159  		}
   160  		s += "\n";
   161  		for (var idx = 0; idx < indent; idx++) s += "  ";
   162  		s += "value = ";
   163  		if (value == null)
   164  		{
   165  			s += "[not loaded]";
   166  		} else
   167  		{
   168  			s += org.omus.util.Log.format(value, indent + 1);
   169  		}
   170  		return s;
   171  	}
   172  
   173  /**
   174  *	Utilisé dans un contexte littéral
   175  	 *	@return	Une chaine définissant l'objet
   176  	 */
   177  	public static function toLog():String
   178  	{
   179  		return "[Object ObjectProperty]";
   180  	}
   181  }