ObjectFile Objects |
Active Web |
An ObjectFile object is a script object that can be saved to and loaded from a file. This provides object persistence as the same object can saved in one script and restored in another See Object Persistence for more details.
An ObjectFile can only save properties that are primitive objects and arrays of primitive objects. Non primitive properties held by the ObjectFile object will not be saved. The ObjectFile can save multiple level object models and there is no limit to the complexity and number of levels.
ObjectFile objects are shared objects and can be used by more than one script simultaneously. To prevent problems with two or more scripts changing the same properties the LockingPrototype is included in the object prototype chain. Calling the lock function will cause the script to wait if another script currently holds a lock on the ObjectFile object (its lock was obtained by calling the lock function). The lock is released either by calling the unlock function or by the script completing.
Property |
Description |
error |
An error message If an error has occurred. If no error has occurred then it will be null. The error messages are explained below: No file name supplied - The copyTo function was called with no name argument. While accessing the file the operating system can generate various other error messages. |
prototype |
A reference to the Locking Prototype. This property does not enumerate and can not be deleted but can be changed. |
Function |
Description |
copyTo(name) |
Copies the ObjectFile object to another file and returns a new ObjectFile object read from that file. Returns a null object if there was an error. The name is the name of the new file and uses the script file reference to identify the file. The ObjectFile will have done a write to the new file of the complete contents of the ObjectFile. |
merge(object) |
Merge the enumerable properties from the object argument, into the ObjectFile object. This will overwrite any existing properties with the same name. This does not affect the object used for the merge and it does not write the ObjectFile to its file. |
remove(name[, name[, . . .]]) |
Remove the named property from the ObjectFile object. The name is a string and can be in a dot separated format to define any property in the compound hierarchy. You can specify as many name arguments as you want. Returns a number indicating how many properties were removed. e.g. var myObjectFile = new ObjectFile(“myFile.xml”); myObjectFile.box.width = 99: myObjectFile.remove(“box.width”); |
write() |
Write the ObjectFile object to the file. Returns true if the write was successful or false on an error. |
The ObjectFile constructor is used to create new File objects.
var myObjectFile = new ObjectFile(name);
A new ObjectFile object for the file identified by the name is created. The name uses the script file reference to identify the file. The file can be anywhere on the host filing system. If the name argument is not present then a runtime error will be generated and the script page execution halted.
When a new ObjectFile object is created the file is opened and read and the complete object with all its properties is recreated. This object is held in a cache so that subsequent creations use the cached version unless the time stamp on the file is more recent than that on the cache. Properties can then be added to, modified or removed from the ObjectFile object.
Shown below is the ObjectFile object prototype chain.
When the constructor is run as a function without the new operator it has exactly the same behaviour as using the new operator.
Constructor properties are read only (they can not be changed or deleted) and it is not possible to add new properties to the Constructor.
Property |
Description |
prototype |
A reference to the Locking Prototype. This property does not enumerate and can not be changed or deleted. |
The ObjectFile constructor has no predefined functions.
Topic ID: 150076