org.simantics.databoard.accessor.binary
Class BinaryOptional

java.lang.Object
  extended by org.simantics.databoard.accessor.binary.BinaryObject
      extended by org.simantics.databoard.accessor.binary.BinaryOptional
All Implemented Interfaces:
Accessor, CloseableAccessor, FileAccessor, FileOptionalAccessor, OptionalAccessor, ParametrisedAccessor

public class BinaryOptional
extends BinaryObject
implements OptionalAccessor, FileOptionalAccessor


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.Accessor
Accessor.Listener
 
Constructor Summary
BinaryOptional(BinaryObject parent, Blob blob, OptionalType type, AccessorParams params)
           
 
Method Summary
 void addListener(Accessor.Listener listener, InterestSet interestSet, AccessorReference path)
          Place a listener to an accessor node.
<T extends Accessor>
T
getAccessor(AccessorReference reference)
          Get an accessor to a sub-container.
<T extends Accessor>
T
getComponentAccessor()
          Get accessor to the component value or null if there is no component value
 java.lang.Object getComponentValue(Binding cb)
          Return component value if there is a component value.
 boolean hasValue()
          Return true if there is a value assigned
 void removeListener(Accessor.Listener listener)
          Remove a listener.
 void setComponentValue(Binding cb, java.lang.Object cv)
          Set a new component value.
 void setComponentValueNoflush(Binding cb, java.lang.Object cv)
           
 void setNoValue()
          Sets no value.
 void setNoValueNoflush()
           
 void setValueNoflush(Binding binding, java.lang.Object newValue)
          Write a new value and don't flush the buffer
 OptionalType type()
          Get structural represtentation of the accessor presented in databoard's type system.
 
Methods inherited from class org.simantics.databoard.accessor.binary.BinaryObject
apply, close, createAccessor, file, flush, getBinary, getEmitter, getParams, getReadLock, getSource, getValue, getWriteLock, setValue, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.simantics.databoard.accessor.OptionalAccessor
setValue
 
Methods inherited from interface org.simantics.databoard.accessor.file.FileAccessor
close, file, flush
 
Methods inherited from interface org.simantics.databoard.accessor.Accessor
apply, getValue
 

Constructor Detail

BinaryOptional

public BinaryOptional(BinaryObject parent,
                      Blob blob,
                      OptionalType type,
                      AccessorParams params)
               throws AccessorConstructionException
Throws:
AccessorConstructionException
Method Detail

type

public OptionalType 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 OptionalAccessor
Overrides:
type in class BinaryObject
Returns:
type description

setValueNoflush

public void setValueNoflush(Binding binding,
                            java.lang.Object newValue)
                     throws AccessorException
Description copied from class: BinaryObject
Write a new value and don't flush the buffer

Specified by:
setValueNoflush in interface FileAccessor
Specified by:
setValueNoflush in class BinaryObject
Throws:
AccessorException

setComponentValueNoflush

public void setComponentValueNoflush(Binding cb,
                                     java.lang.Object cv)
                              throws AccessorException
Specified by:
setComponentValueNoflush in interface FileOptionalAccessor
Throws:
AccessorException

setNoValueNoflush

public void setNoValueNoflush()
                       throws AccessorException
Specified by:
setNoValueNoflush in interface FileOptionalAccessor
Throws:
AccessorException

setNoValue

public void setNoValue()
                throws AccessorException
Description copied from interface: OptionalAccessor
Sets no value. Any existing component accessor is invalidated.

Specified by:
setNoValue in interface OptionalAccessor
Throws:
AccessorException

setComponentValue

public void setComponentValue(Binding cb,
                              java.lang.Object cv)
                       throws AccessorException
Description copied from interface: OptionalAccessor
Set a new component value. Any existing component accessor is invalidated.

Specified by:
setComponentValue in interface OptionalAccessor
Throws:
AccessorException

getComponentAccessor

public <T extends Accessor> T getComponentAccessor()
                                        throws AccessorConstructionException
Description copied from interface: OptionalAccessor
Get accessor to the component value or null if there is no component value

Specified by:
getComponentAccessor in interface OptionalAccessor
Returns:
accessor or null
Throws:
AccessorConstructionException

getComponentValue

public java.lang.Object getComponentValue(Binding cb)
                                   throws AccessorException
Description copied from interface: OptionalAccessor
Return component value if there is a component value. Exception is thrown if there is no component value.

Specified by:
getComponentValue in interface OptionalAccessor
Parameters:
cb - component binding
Returns:
component value
Throws:
AccessorException

hasValue

public boolean hasValue()
                 throws AccessorException
Description copied from interface: OptionalAccessor
Return true if there is a value assigned

Specified by:
hasValue in interface OptionalAccessor
Returns:
true if there is a value
Throws:
AccessorException

getAccessor

public <T extends Accessor> T getAccessor(AccessorReference reference)
                               throws AccessorConstructionException
Description copied from interface: Accessor
Get an accessor to a sub-container. If one already exists, the same is returned, otherwise a new is created.

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

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

addListener

public void addListener(Accessor.Listener listener,
                        InterestSet interestSet,
                        AccessorReference path)
                 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.

Specified by:
addListener in interface Accessor
Overrides:
addListener in class BinaryObject
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 BinaryObject
Throws:
AccessorException