Packagecom.ericfeminella.collections
Classpublic class LocalPersistenceMap
ImplementsIMap

Provides an IMap implementation into the data object of a SharedObject on a clients local file system.

LocalPersistenceMap allows the data object of a SharedObject to be accessed via an IMap implementation in order to provide a consistant API for working with the underlying data of the SharedObject.


Example
The following example demonstrates how a client implementation of LocalPersistenceMap can be utilized to provide a typical IMap implementation into a SharedObject.

     var map:IMap = new LocalPersistenceMap("test", "/");
     map.put("username", "efeminella");
     map.put("password", "43kj5k4nr43r934hcr34hr8h3");
     map.put("admin", true);

     

See also

com.ericfeminella.collections.IMap
flash.net.SharedObject;


Public Properties
 PropertyDefined by
  sharedObjectInstance : SharedObject
[read-only] Retrieves the underlying SharedObject instance used by the LocalPersistenceMap.
LocalPersistenceMap
Protected Properties
 PropertyDefined by
  minimumStorage : Number
Defines the minimum disc space which is required by the persistant SharedObject.
LocalPersistenceMap
  sharedObject : SharedObject
Defines the underlying SharedObject instance in which the persistant data is stored.
LocalPersistenceMap
Public Methods
 MethodDefined by
  
LocalPersistenceMap(identifier:String, localPath:String = null, secure:Boolean = false, minimumStorage:int = 500)
LocalPersistenceMap constructor creates a reference to the persisted SharedObject available from the clients local disk.
LocalPersistenceMap
  
clear():void
Resets all key / values in the data object of the underlying the SharedObject instance to null.
LocalPersistenceMap
  
clearAllExcept(key:*):void
Clears all key / values defined in the data object of the underlying the SharedObject instance with the exception of the specified key.
LocalPersistenceMap
  
containsKey(key:*):Boolean
Determines if a key exists in the data object of the underlying the SharedObject instance.
LocalPersistenceMap
  
containsValue(value:*):Boolean
Determines if a value exists in the HashMap instance
LocalPersistenceMap
  
getEntries():IList
Returns an IList of IHashMapEntry objects based on the underlying internal map.
LocalPersistenceMap
  
getKey(value:*):*
Returns a key value from the HashMap instance
LocalPersistenceMap
  
getKeys():Array
Returns each key added to the data object of the underlying the SharedObject instance.
LocalPersistenceMap
  
getValue(key:*):*
Returns each key added to the data object of the underlying the SharedObject instance.
LocalPersistenceMap
  
getValues():Array
Retrieves each value assigned to the data object of the underlying the SharedObject instance.
LocalPersistenceMap
  
isEmpty():Boolean
Determines if the current data object of the underlying the SharedObject instance is empty.
LocalPersistenceMap
  
put(key:*, value:*):void
Adds a key and value to the data object of the underlying the SharedObject instance.
LocalPersistenceMap
  
putAll(table:Dictionary):void
[new] putAll places all name / value pairs defined in an Object or Dictionary instance into the SharedObject instance.
LocalPersistenceMap
  
putEntry(entry:IHashMapEntry):void
[new] putEntry is intended as a pseudo-overloaded put implementation whereby clients may call putEntry to pass an IHashMapEntry implementation.
LocalPersistenceMap
  
remove(key:*):void
Removes a key and value from the data object of the underlying the SharedObject instance.
LocalPersistenceMap
  
reset():void
Resets all key / value assignment in the data object of the underlying the SharedObject instance is empty to null.
LocalPersistenceMap
  
resetAllExcept(key:*):void
Resets all key / values defined in the data object of the underlying the SharedObject instance is empty to null with the exception of the specified key.
LocalPersistenceMap
  
size():int
Determines the size of the data object of the underlying the SharedObject instance.e
LocalPersistenceMap
Protected Methods
 MethodDefined by
  
stripInvalidChars(identifier:String):String
[static] Removes invalid charachters from a SharedObject name and substitutes the invalid charachters with an underscore.
LocalPersistenceMap
Property detail
minimumStorageproperty
protected var minimumStorage:Number

Defines the minimum disc space which is required by the persistant SharedObject.

sharedObjectproperty 
protected var sharedObject:SharedObject

Defines the underlying SharedObject instance in which the persistant data is stored.

sharedObjectInstanceproperty 
sharedObjectInstance:SharedObject  [read-only]

Retrieves the underlying SharedObject instance used by the LocalPersistenceMap.

Implementation
    public function get sharedObjectInstance():SharedObject

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;
var map:LocalPersistenceMap = new LocalPersistenceMap("sharedObjectName");
trace( map.sharedObjectInstance );
                  

Constructor detail
LocalPersistenceMap()constructor
public function LocalPersistenceMap(identifier:String, localPath:String = null, secure:Boolean = false, minimumStorage:int = 500)

LocalPersistenceMap constructor creates a reference to the persisted SharedObject available from the clients local disk. If the SharedObject does not currently exist, Flash Player will attempt to created it.

If the identifier parameter contains any invalid charachters, they will be substituted with underscores

Parameters
identifier:String — name of the local SharedObject
 
localPath:String (default = null) — the local path to the SharedObject
 
secure:Boolean (default = false) — specifies if the shared object is from a secure domain
 
minimumStorage:int (default = 500) — minimum amount of disc space required by the shared object
Method detail
clear()method
public function clear():void

Resets all key / values in the data object of the underlying the SharedObject instance to null.


Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.size() ); //2

map.clear();
trace( map.size() ); //0
                  

clearAllExcept()method 
public function clearAllExcept(key:*):void

Clears all key / values defined in the data object of the underlying the SharedObject instance with the exception of the specified key.

Parameters
key:* — key which is not to be cleared from the map

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.size() ); //2

map.clearAllExcept( "editor", editorVO );
trace( map.getValues() ); //[object, editorVO]
trace( map.size() ); //1
                  

containsKey()method 
public function containsKey(key:*):Boolean

Determines if a key exists in the data object of the underlying the SharedObject instance.

Parameters
key:* — the key in which to determine existance in the map

Returns
Boolean — true if the key exisits, false if not

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
trace( map.containsKey( "admin" ) ); //true
                  

containsValue()method 
public function containsValue(value:*):Boolean

Determines if a value exists in the HashMap instance

Parameters
value:* — the value in which to determine existance in the map

Returns
Boolean — true if the value exisits, false if not

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
trace( map.containsValue( adminVO ) ); //true
                  

getEntries()method 
public function getEntries():IList

Returns an IList of IHashMapEntry objects based on the underlying internal map.

Returns
IList
getKey()method 
public function getKey(value:*):*

Returns a key value from the HashMap instance

Parameters
value:* — the key in which to retrieve the value of

Returns
String — the value of the specified key

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
trace( map.getKey( adminVO ) ); //admin
                  

getKeys()method 
public function getKeys():Array

Returns each key added to the data object of the underlying the SharedObject instance.

Returns
Array — Array of key identifiers

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getKeys() ); //admin, editor
                  

getValue()method 
public function getValue(key:*):*

Returns each key added to the data object of the underlying the SharedObject instance.

Parameters
key:*

Returns
* — Array of key identifiers

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getKeys() ); //admin, editor
                  

getValues()method 
public function getValues():Array

Retrieves each value assigned to the data object of the underlying the SharedObject instance.

Returns
Array — Array of values assigned for all keys in the map

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getValues() ); //[object, adminVO],[object, editorVO]
                  

isEmpty()method 
public function isEmpty():Boolean

Determines if the current data object of the underlying the SharedObject instance is empty.

Returns
Boolean — true if the current map is empty, false if not

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
trace( map.isEmpty() ); //true

map.put( "admin", adminVO );
trace( map.isEmpty() ); //false
                  

put()method 
public function put(key:*, value:*):void

Adds a key and value to the data object of the underlying the SharedObject instance.

Parameters
key:* — key to add to the map
 
value:* — value of the specified key

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "user", userVO );
                  

putAll()method 
public function putAll(table:Dictionary):void

Places all name / value pairs into the current IMap instance.

Parameters
table:DictionaryObject of name / value pairs

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var table:Object = {a: "foo", b: "bar"};

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.putAll( table );

trace( map.getKeys() ); // a, b
trace( map.getValues() ); // foo, bar

         

putEntry()method 
public function putEntry(entry:IHashMapEntry):void

putEntry is intended as a pseudo-overloaded put implementation whereby clients may call putEntry to pass an IHashMapEntry implementation.

Parameters
entry:IHashMapEntryIHashMapEntry implementation
remove()method 
public function remove(key:*):void

Removes a key and value from the data object of the underlying the SharedObject instance.

Parameters
key:* — key to remove from the map

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.remove( "admin" );
                  

reset()method 
public function reset():void

Resets all key / value assignment in the data object of the underlying the SharedObject instance is empty to null.


Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
map.reset();
trace( map.getValues() ); //null, null
                  

resetAllExcept()method 
public function resetAllExcept(key:*):void

Resets all key / values defined in the data object of the underlying the SharedObject instance is empty to null with the exception of the specified key.

Parameters
key:* — key which is not to be cleared from the map

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.getValues() ); //[object, adminVO],[object, editorVO]

map.resetAllExcept( "editor", editorVO );
trace( map.getValues() ); //null, [object, editorVO]
                  

size()method 
public function size():int

Determines the size of the data object of the underlying the SharedObject instance.e

Returns
int — the current size of the map instance

Example
import com.ericfeminella.collections.LocalPersistenceMap;
import com.ericfeminella.collections.IMap;

var map:IMap = new LocalPersistenceMap("sharedObjectName");
map.put( "admin", adminVO );
map.put( "editor", editorVO );
trace( map.size() ); //2

stripInvalidChars()method 
protected static function stripInvalidChars(identifier:String):String

Removes invalid charachters from a SharedObject name and substitutes the invalid charachters with an underscore.

Parameters
identifier:String

Returns
String — a valid SharedObject name