org.simantics.databoard
Class Accessors

java.lang.Object
  extended by org.simantics.databoard.Accessors

public class Accessors
extends java.lang.Object

This is a facade class for accessor services.

Author:
Toni Kalajainen

Constructor Summary
Accessors()
           
 
Method Summary
static FileVariantAccessor createFile(java.io.File file)
          Create a new binary file with an empty value and open an accessor.
static
<T extends FileAccessor>
T
createFile(java.io.File file, DataType type)
          Create a binary file (.dbb) and open an accessor.
static
<T extends JavaObject & Accessor>
T
getAccessor(Binding binding, java.lang.Object value)
          Open an accessor to a Java Object.
static
<T extends BinaryObject & Accessor>
T
getAccessor(byte[] binary, DataType type)
          Open an accessor to byte data.
static
<T extends JavaObject & Accessor>
T
getAccessor(java.lang.Object value)
          Open Accessor to a Java Object.
static
<T extends BinaryObject & Accessor>
T
getAccessor(RandomAccessBinary binary, DataType type)
          Open an accessor to byte data.
static FileVariantAccessor openAccessor(java.io.File file)
          Open an accessor to a binary file (.dbb).
static DirectoryMap openDirectory(java.io.File directory)
          Open a Map(Variant, Variant) accessor to a directory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Accessors

public Accessors()
Method Detail

getAccessor

public static <T extends BinaryObject & Accessor> T getAccessor(RandomAccessBinary binary,
                                                               DataType type)
                                                    throws AccessorConstructionException
Open an accessor to byte data.

Parameters:
binary -
type -
Returns:
an accessor
Throws:
AccessorConstructionException

getAccessor

public static <T extends BinaryObject & Accessor> T getAccessor(byte[] binary,
                                                               DataType type)
                                                    throws AccessorConstructionException
Open an accessor to byte data.

Parameters:
binary -
type -
Returns:
an accessor
Throws:
AccessorConstructionException

getAccessor

public static <T extends JavaObject & Accessor> T getAccessor(Binding binding,
                                                             java.lang.Object value)
                                                  throws AccessorConstructionException
Open an accessor to a Java Object.

Accessor is disposed by leaving it to garbage collector.

Do not modify the object outside the accessor as long as you use the accessor. Exterioir modifications will mix up listening the mechanism. Also, do not create more than one accessor to one Object.

The accessor is not multi-thread accessible. You must provide mutual exclusion locking mechanism to the whole Object Model, if you intend to use it in multi-thread environment.

Parameters:
binding -
value -
Returns:
accessor
Throws:
AccessorConstructionException
Since:
0.5

getAccessor

public static <T extends JavaObject & Accessor> T getAccessor(java.lang.Object value)
                                                  throws AccessorConstructionException
Open Accessor to a Java Object. This version reads the type using reflection.

Accessor is disposed by leaving it to garbage collector.

Do not modify the object outside the accessor as long as you use the accessor. Exterioir modifications will mix up listening the mechanism. Also, do not create more than one accessor to one Object.

The accessor is not multi-thread accessible. You must provide mutual exclusion locking mechanism to the whole Object Model, if you intend to use it in multi-thread environment.

Parameters:
value -
Returns:
accessor
Throws:
AccessorConstructionException
Since:
0.5

openAccessor

public static FileVariantAccessor openAccessor(java.io.File file)
                                        throws AccessorConstructionException
Open an accessor to a binary file (.dbb). The file is always a variant. The accessor must be closed by invoking FileAccessor.close() at root or any sub-accessor.

To share accessors of the same file use FileLibrary utility.

Parameters:
file -
Returns:
file accessor
Throws:
AccessorConstructionException
Since:
0.5

createFile

public static FileVariantAccessor createFile(java.io.File file)
                                      throws AccessorConstructionException
Create a new binary file with an empty value and open an accessor. If file already exists, it is overwritten. It is recommended that the file extension is .dbb (Databoard Binary)

The caller must close the file with FileAccessor.close().

Parameters:
file -
Returns:
an accessor to the root variant node
Throws:
AccessorConstructionException
Since:
0.5

createFile

public static <T extends FileAccessor> T createFile(java.io.File file,
                                                    DataType type)
                                         throws AccessorConstructionException
Create a binary file (.dbb) and open an accessor. The file is always a variant.

File is closed with FileAccessor.close() at root or any sub-accessor.

To share accessors of the same file use FileLibrary utility.

Type Parameters:
T -
Parameters:
file -
type -
Returns:
an accessor to the value node
Throws:
AccessorConstructionException

openDirectory

public static DirectoryMap openDirectory(java.io.File directory)
Open a Map(Variant, Variant) accessor to a directory. Map entries are binary files (.dbb), and the file name is the key with the following encoding: Filenames have the following encoding: S.dbb String types Control characters " : < > | ? * \ / % [0..31] [128..] are escaped as % " "-space is _ I.dbb Integer types L.dbb Long types H.dbb All other cases the value as binary The caller must close (FolderMap#close()) the accessor after usage. This releases file handles and a directory polling thread. FolderMap is not concurrent-use-safe. Its files are not either. The user must ensure that the files are not used concurrently from different threads.

Parameters:
directory -
Returns:
MapAccessor