org.simantics.databoard.accessor.java
Class JavaArray

java.lang.Object
  extended by org.simantics.databoard.accessor.java.JavaObject
      extended by org.simantics.databoard.accessor.java.JavaArray
All Implemented Interfaces:
Accessor, ArrayAccessor, ArrayAccessor.CloseableArrayAccessor, CloseableAccessor, FileAccessor, FileArrayAccessor, ParametrisedAccessor, StreamAccessor

public class JavaArray
extends JavaObject
implements ArrayAccessor, StreamAccessor


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.ArrayAccessor
ArrayAccessor.CloseableArrayAccessor
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.Accessor
Accessor.Listener
 
Constructor Summary
JavaArray(Accessor parent, ArrayBinding binding, java.lang.Object object, AccessorParams params)
           
 
Method Summary
 void add(Binding binding, java.lang.Object value)
          Add a new value.
 void add(int index, Binding binding, java.lang.Object value)
          Insert a new value.
 void addAll(Binding binding, java.lang.Object[] values)
          Add an array of elements.
 void addAll(int index, Binding binding, java.lang.Object[] values)
          Add an array of elements.
 void addAllNoflush(Binding binding, java.lang.Object[] values)
          Add an array of elements.
 void addAllNoflush(int index, Binding binding, java.lang.Object[] values)
          Add an array of elements.
 void addListener(Accessor.Listener listener, InterestSet interestSet, ChildReference path, java.util.concurrent.Executor executor)
          Place a listener to an accessor node.
 void addNoflush(Binding binding, java.lang.Object value)
          Add a new value.
 void addNoflush(int index, Binding binding, java.lang.Object value)
          Insert a new value.
 void close()
          Close the accessor.
 java.io.File file()
          Get the file
 void flush()
          Flush the internal write buffer to the disc.
 java.lang.Object get(int index, Binding valueBinding)
          Get a copy of the element
 void get(int index, Binding valueBinding, java.lang.Object dst)
          Read the element to an object
<T extends Accessor>
T
getAccessor(int index)
          Get an accessor to an element.
 void getAll(Binding valueBinding, java.util.Collection<java.lang.Object> values)
          Get all elements
 void getAll(Binding valueBinding, java.lang.Object[] array)
          Get all elements and place them to an array.
 ArrayBinding getBinding()
           
<T extends Accessor>
T
getComponent(ChildReference reference)
          Open an accessor to a child.
 void remove(int index, int count)
          Remove an element at an index.
 void removeListener(Accessor.Listener listener)
          Remove a listener.
 void removeNoflush(int index, int count)
          Remove an element at an index.
 void reset()
          Reset internal buffer.
 void set(int index, Binding binding, java.lang.Object value)
          Replace a value container with a new value.
 void setNoflush(int index, Binding binding, java.lang.Object value)
          Replace a value container with a new value.
 void setSize(int newSize)
           
 void setSizeNoflush(int newSize)
          Set new array size
 void setValue(Binding arrayBinding, java.lang.Object newArray)
          Set all elements from an Array Value.
 void setValueNoflush(Binding binding, java.lang.Object newValue)
          Set all elements from an Array Value.
 int size()
          Return the number of elements in the array.
 ArrayType type()
          Get structural represtentation of the accessor presented in databoard's type system.
 
Methods inherited from class org.simantics.databoard.accessor.java.JavaObject
apply, createAccessor, createSubAccessor, getObject, getParams, getReadLock, getValue, getValue, getWriteLock, notifyValueChanged, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.simantics.databoard.accessor.Accessor
apply, getValue, getValue
 

Constructor Detail

JavaArray

public JavaArray(Accessor parent,
                 ArrayBinding binding,
                 java.lang.Object object,
                 AccessorParams params)
Method Detail

getBinding

public ArrayBinding getBinding()
Overrides:
getBinding in class JavaObject

type

public ArrayType type()
Description copied from interface: Accessor
Get structural represtentation of the accessor presented in databoard's type system.

Specified by:
type in interface Accessor
Specified by:
type in interface ArrayAccessor
Overrides:
type in class JavaObject
Returns:
type description

add

public void add(Binding binding,
                java.lang.Object value)
         throws AccessorException
Description copied from interface: ArrayAccessor
Add a new value.

Specified by:
add in interface ArrayAccessor
value - value
Throws:
AccessorException

addAll

public void addAll(Binding binding,
                   java.lang.Object[] values)
            throws AccessorException
Description copied from interface: ArrayAccessor
Add an array of elements.

Specified by:
addAll in interface ArrayAccessor
values - value
Throws:
AccessorException

add

public void add(int index,
                Binding binding,
                java.lang.Object value)
         throws AccessorException
Description copied from interface: ArrayAccessor
Insert a new value. If elements are inserted in the middle of the array, existing interest sets are updated to reflect the new positions.

Specified by:
add in interface ArrayAccessor
Parameters:
index - position to insert new value to
value - value
Throws:
AccessorException

addAll

public void addAll(int index,
                   Binding binding,
                   java.lang.Object[] values)
            throws AccessorException
Description copied from interface: ArrayAccessor
Add an array of elements. If elements are inserted in the middle of the array, existing interest sets are updated to reflect the new positions.

Specified by:
addAll in interface ArrayAccessor
Parameters:
index - position to insert new value to
Throws:
AccessorException

getComponent

public <T extends Accessor> T getComponent(ChildReference reference)
                                throws AccessorConstructionException
Description copied from interface: Accessor
Open an accessor to a child. If one already exists, the existing is returned, otherwise a new is created. Child accessors are often remembered with weak reference.

InvalidatedEvent is thrown from the accessor if it is unlinked from the parent hierarchy.

Specified by:
getComponent in interface Accessor
Parameters:
reference - component reference path or null to return _this_ accessor
Returns:
accessor
Throws:
AccessorConstructionException

getAccessor

public <T extends Accessor> T getAccessor(int index)
                               throws AccessorConstructionException
Description copied from interface: ArrayAccessor
Get an accessor to an element. The accessor is invalidated if the element is removed from the array.

The accessor is not to the index, it is to the element. For instance, you get accessor X of [2] then a new value is inserted before 2. The accessor now points to the element at [3].

Specified by:
getAccessor in interface ArrayAccessor
Returns:
the accessor
Throws:
AccessorConstructionException

getAll

public void getAll(Binding valueBinding,
                   java.util.Collection<java.lang.Object> values)
            throws AccessorException
Description copied from interface: ArrayAccessor
Get all elements

Specified by:
getAll in interface ArrayAccessor
Throws:
AccessorException

getAll

public void getAll(Binding valueBinding,
                   java.lang.Object[] array)
            throws AccessorException
Description copied from interface: ArrayAccessor
Get all elements and place them to an array. Exception is thrown if Array length is too short.

Specified by:
getAll in interface ArrayAccessor
Throws:
AccessorException

get

public java.lang.Object get(int index,
                            Binding valueBinding)
                     throws AccessorException
Description copied from interface: ArrayAccessor
Get a copy of the element

Specified by:
get in interface ArrayAccessor
Returns:
the element
Throws:
AccessorException

get

public void get(int index,
                Binding valueBinding,
                java.lang.Object dst)
         throws AccessorException
Description copied from interface: ArrayAccessor
Read the element to an object

Specified by:
get in interface ArrayAccessor
Throws:
AccessorException

remove

public void remove(int index,
                   int count)
            throws AccessorException
Description copied from interface: ArrayAccessor
Remove an element at an index. If there are listeners to elements after the index, the interest sets and accessor paths are updated and decreased. If there was an accessor, it becomes invalid.

Specified by:
remove in interface ArrayAccessor
Throws:
AccessorException

set

public void set(int index,
                Binding binding,
                java.lang.Object value)
         throws AccessorException
Description copied from interface: ArrayAccessor
Replace a value container with a new value.

Specified by:
set in interface ArrayAccessor
Throws:
AccessorException

setValue

public void setValue(Binding arrayBinding,
                     java.lang.Object newArray)
              throws AccessorException
Description copied from interface: ArrayAccessor
Set all elements from an Array Value. If array becomes shorter and there are accessors to the removed elements, the accessors are invalidated.

Specified by:
setValue in interface Accessor
Specified by:
setValue in interface ArrayAccessor
Throws:
AccessorException

setSize

public void setSize(int newSize)
             throws AccessorException
Specified by:
setSize in interface ArrayAccessor
Throws:
AccessorException

size

public int size()
         throws AccessorException
Description copied from interface: ArrayAccessor
Return the number of elements in the array.

Specified by:
size in interface ArrayAccessor
Returns:
the number of elements
Throws:
AccessorException

addListener

public void addListener(Accessor.Listener listener,
                        InterestSet interestSet,
                        ChildReference path,
                        java.util.concurrent.Executor executor)
                 throws AccessorException
Description copied from interface: Accessor
Place a listener to an accessor node. The listener will be notified for changes in the node/node tree, depending on interest set.

When events are emited and in which thread processed is implementation specific. It is also implementation specific, whether the object can be mutated in the listener or whether it has to be done afterwards.

In many implementations there is a pluggable event handling strategy EventEmitter. The default behaviour is to emit events as they are spawned in the current thread.

There is a reference in each event instance that describes the path from the accessor where listener was placed to the node to which the event applies to.

Listener is attached to the object that holds the value at the time at the of the adding. For example, If a listener is attached to an array of element at index 3, and a new value is inserted at position 2, the listener still monitors the same container, which is now at index 4. The references of incoming the events are modified to have the new index.

Also, if a new value is assigned to the parent of an object that is listened, the listener keeps on monitoring the new value at the same reference. This doesn't apply when a new value is set to a union of different tag, to a variant with a new type, or value is removed from Optional type. In these two cases the listener is invalidated.

See ChangeSet is an implementation that collects events. Executor argument determines the thread where the onEvents method is handled. null argument denotes current thread.

Specified by:
addListener in interface Accessor
Overrides:
addListener in class JavaObject
path - path to the accessor or null. This is used in the events the accessor produces
Throws:
AccessorException
See Also:
collects events

removeListener

public void removeListener(Accessor.Listener listener)
                    throws AccessorException
Description copied from interface: Accessor
Remove a listener. If the listener is added multiple times, the last one added is removed.

Specified by:
removeListener in interface Accessor
Overrides:
removeListener in class JavaObject
Throws:
AccessorException

flush

public void flush()
           throws AccessorException
Description copied from interface: FileAccessor
Flush the internal write buffer to the disc. This is needed if setXXNoFlush() methods are used.

Note, all the write methods of Accessor and its sub-interfaces guarantee Durability. They flush the value immediately and do not require separate FileAccessor.flush().

Specified by:
flush in interface FileAccessor
Specified by:
flush in interface StreamAccessor
Throws:
AccessorException

close

public void close()
           throws AccessorException
Description copied from interface: StreamAccessor
Close the accessor.

Specified by:
close in interface CloseableAccessor
Specified by:
close in interface FileAccessor
Specified by:
close in interface StreamAccessor
Throws:
AccessorException

reset

public void reset()
           throws AccessorException
Description copied from interface: StreamAccessor
Reset internal buffer. If there unwritten changes, they are flushed.

Specified by:
reset in interface FileAccessor
Specified by:
reset in interface StreamAccessor
Throws:
AccessorException

addNoflush

public void addNoflush(Binding binding,
                       java.lang.Object value)
                throws AccessorException
Description copied from interface: FileArrayAccessor
Add a new value.

Specified by:
addNoflush in interface FileArrayAccessor
value - value
Throws:
AccessorException

addAllNoflush

public void addAllNoflush(Binding binding,
                          java.lang.Object[] values)
                   throws AccessorException
Description copied from interface: FileArrayAccessor
Add an array of elements.

Specified by:
addAllNoflush in interface FileArrayAccessor
values - value
Throws:
AccessorException

addAllNoflush

public void addAllNoflush(int index,
                          Binding binding,
                          java.lang.Object[] values)
                   throws AccessorException
Description copied from interface: FileArrayAccessor
Add an array of elements. If elements are inserted in the middle of the array, existing interest sets are updated to reflect the new positions.

Specified by:
addAllNoflush in interface FileArrayAccessor
Parameters:
index - position to insert new value to
Throws:
AccessorException

addNoflush

public void addNoflush(int index,
                       Binding binding,
                       java.lang.Object value)
                throws AccessorException
Description copied from interface: FileArrayAccessor
Insert a new value. If elements are inserted in the middle of the array, existing interest sets are updated to reflect the new positions.

Specified by:
addNoflush in interface FileArrayAccessor
Parameters:
index - position to insert new value to
value - value
Throws:
AccessorException

setValueNoflush

public void setValueNoflush(Binding binding,
                            java.lang.Object newValue)
                     throws AccessorException
Description copied from interface: FileArrayAccessor
Set all elements from an Array Value. If array becomes shorter and there are accessors to the removed elements, the accessors are invalidated.

Specified by:
setValueNoflush in interface FileAccessor
Specified by:
setValueNoflush in interface FileArrayAccessor
Throws:
AccessorException

setNoflush

public void setNoflush(int index,
                       Binding binding,
                       java.lang.Object value)
                throws AccessorException
Description copied from interface: FileArrayAccessor
Replace a value container with a new value.

Specified by:
setNoflush in interface FileArrayAccessor
Throws:
AccessorException

removeNoflush

public void removeNoflush(int index,
                          int count)
                   throws AccessorException
Description copied from interface: FileArrayAccessor
Remove an element at an index. If there are listeners to elements after the null, the interest sets and accessor paths are updated and decreased. If there was an accessor, it becomes invalid.

Specified by:
removeNoflush in interface FileArrayAccessor
Throws:
AccessorException

setSizeNoflush

public void setSizeNoflush(int newSize)
                    throws AccessorException
Description copied from interface: FileArrayAccessor
Set new array size

Specified by:
setSizeNoflush in interface FileArrayAccessor
Throws:
AccessorException

file

public java.io.File file()
Description copied from interface: FileAccessor
Get the file

Specified by:
file in interface FileAccessor
Returns:
file