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 TableProperty
    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.PropertySet;
    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.TableProperty extends Property
    55  {
    56  	//--------------------
    57  	// PROPRIETES
    58  	//--------------------
    59  	/**
    60  	 *	Nom.
    61  	 */
    62  	private var name:String;
    63  	
    64  	/**
    65  	 *	Type.
    66  	 */
    67  	private var type:String;
    68  	
    69  	/**
    70  	 *	Classe.
    71  	 */
    72  	private var clazz:Object;
    73  	
    74  	/**
    75  	 *	Cache.
    76  	 */
    77  	private var cache:Array;
    78  	
    79  	/**
    80  	 *	Un flag pour indiquer le changement.
    81  	 */
    82  	private var modified:Boolean;
    83  	
    84  	/**
    85  	 *	Valeur de la propriété.
    86  	 */
    87  	private var value:Object;
    88  	
    89  	/**
    90  	 *	Une référence au PropetSet. 
    91  	 */
    92  	private var propSet:PropertySet;
    93  	
    94  	/**
    95  	 *	TODO
    96  	 */
    97  	private var backup:Object;
    98  	
    99  	//--------------------
   100  	// CONSTRUCTEUR
   101  	//--------------------
   102  	/**
   103  	 *	TODO
   104  	 *
   105  	 *	@param nm			Nom de la propriété.
   106  	 *	@param tp			Type attaché à la propriété.
   107  	 *	@param cl			Classe.
   108  	 *	@param ch			Liste du cache.
   109  	 *	@param vl			Valeur de la propriété.	
   110  	 */
   111  	public function TableProperty (nm:String, tp:String, cl:Object, ch:Array, vl:Object)
   112  	{
   113  		super(nm, tp, cl, ch, vl.value);
   114  
   115  		// Propriétés
   116  		vl.value.setContainer(this);
   117  		backup = vl.backup;
   118  		
   119  		// trace(this+ " installé.");
   120  	}
   121  	
   122  	//--------------------
   123  	// METHODES PUBLIQUES
   124  	//--------------------
   125  	/**
   126  	 *	Utilisé dans un contexte littéral
   127  	 *	@return	Une chaine définissant l'objet
   128  	 */
   129  	public function toString ():String
   130  	{
   131  		return "[Object TableProperty]\n" + format(0);
   132  	}
   133  	
   134  	
   135  	/**
   136  	 *	Appelé par un objet Table non synchronisé.
   137  	 *	called by table objects that are not synchronized
   138  	 *
   139  	 *	@see org.omus.data.Table
   140  	 */
   141  	public function setModified ():Void
   142  	{
   143  		modified = true;
   144  		propSet.valueChanged(name, value.us);
   145  	}
   146  	
   147  	/**
   148  	 *	Met à jour la propriétés après synchronisation.
   149  	 *
   150  	 *	@param newVal		Nouvelle valeur.
   151  	 *	@param clientReq	true si la demande provient du poste client.
   152  	 */
   153  	public function update (newVal:Object, clientReq:Boolean):Void
   154  	{ 
   155  		// synced Table
   156  		// with marshalled backup:
   157  		newVal.value.execute(this.value, clientReq);
   158  		this.backup.update(this.value, newVal.backup);
   159  		if (! propSet.marsh.contains(name)) modified = false;
   160  	}
   161  	
   162  	/**
   163  	 *	Annule la modification d'un propriété.
   164  	 *	Utile lors d'un échec de synchronisation.
   165  	 */
   166  	public function reset ():Void
   167  	{
   168  		// synced Table
   169  		backup.restore(value);
   170  		if (! propSet.marsh.contains(name)) modified = false;
   171  	}
   172  	
   173  	/**
   174  	 *	Affecte une nouvelle valeur.
   175  	 *
   176  	 *	@param newVal		Valeur.
   177  	 */
   178  	public function setValue (newVal:Object)
   179  	{
   180  		// Logs internes
   181  		_global.oregano.iLog.warn("clj-017","property name = " + name);
   182  		return;
   183  	}
   184  	
   185  	
   186  	//--------------------
   187  	// METHODES STATIQUES
   188  	//--------------------
   189  	/**
   190  		*	Formate une chaîne de représenation de l'objet.
   191  	 *
   192  	 *	@param indent		Numbre d'espace d'indentation.
   193  	 *	@return				Une chaîne formatée.
   194  	 */
   195  	private function format (indent:Number):String
   196  	{
   197  		var s= "org.omus.data.TableProperty:";
   198  		var arr = ["name", "type", "modified"];
   199  		var long = arr.length;
   200  		for (var i = 0; i < long ; i++) 
   201  		{
   202  			s += "\n";
   203  			for (var idx = 0; idx < indent; idx++) s += "  ";
   204  			s += arr[i] + " = " + this[arr[i]];
   205  		}
   206  		s += "\n";
   207  		for (var idx = 0; idx < indent; idx++) s += "  ";
   208  		s += "value = ";
   209  		if (value == null)
   210  		{
   211  			s += "[not loaded]";
   212  		} else
   213  		{
   214  			s += org.omus.util.Log.format(value, indent + 1);
   215  		}
   216  		return s;
   217  	}
   218  	
   219  	/**
   220  		*	Utilisé dans un contexte littéral
   221  	 *	@return	Une chaine définissant l'objet
   222  	 */
   223  	public static function toLog():String
   224  	{
   225  		return "[Object TableProperty]";
   226  	}
   227  }