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 Accessor>
T
getAccessor(Binding binding, java.lang.Object value)
          Open an accessor to a Java Object.
static
<T extends Accessor>
T
getAccessor(Binding binding, java.lang.Object value, AccessorParams params)
          Open an accessor to a Java Object.
static
<T extends Accessor>
T
getAccessor(byte[] binary, Datatype type)
          Open an accessor to byte data.
static
<T extends Accessor>
T
getAccessor(java.lang.Object value)
          Open Accessor to a Java Object.
static
<T extends Accessor>
T
getAccessor(RandomAccessBinary binary, Datatype type)
          Open an accessor to byte data.
static
<T extends Accessor>
T
getAccessor(RandomAccessBinary binary, Datatype type, AccessorParams params)
          Open an accessor to byte data.
static java.util.concurrent.Executor getCurrentThread()
          Get an executor for current thread
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 Accessor> T getAccessor(RandomAccessBinary binary,
                                                 Datatype type,
                                                 AccessorParams params)
                                      throws AccessorConstructionException
Open an accessor to byte data.

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

getAccessor

public static <T extends 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 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 Accessor> T getAccessor(Binding binding,
                                                 java.lang.Object value,
                                                 AccessorParams params)
                                      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.

You must provide mutual exclusion locking mechanism to the whole Object Model in AccessorParams, if you intend to use the accessors in multi-thread environment.

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

getAccessor

public static <T extends 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. If you intend to use it in concurrent multi-thread environment, use the other method where you can pass lock objects in AccessorParams.

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

getAccessor

public static <T extends 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. If you intend to use it in concurrent multi-thread environment, use the other method where you can pass lock objects in AccessorParams.

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

getCurrentThread

public static java.util.concurrent.Executor getCurrentThread()
Get an executor for current thread

Returns:
executor