org.simantics.databoard.accessor.binary
Class BinaryVariant

java.lang.Object
  extended by org.simantics.databoard.accessor.binary.BinaryObject
      extended by org.simantics.databoard.accessor.binary.BinaryVariant
All Implemented Interfaces:
Accessor, CloseableAccessor, FileAccessor, FileVariantAccessor, ParametrisedAccessor, VariantAccessor

public class BinaryVariant
extends BinaryObject
implements VariantAccessor, FileVariantAccessor


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.Accessor
Accessor.Listener
 
Constructor Summary
BinaryVariant(BinaryObject parent, Blob blob, Datatype type, AccessorParams params)
           
 
Method Summary
 void addListener(Accessor.Listener listener, InterestSet interestSet, ChildReference path, java.util.concurrent.Executor executor)
          Place a listener to an accessor node.
<T extends Accessor>
T
getComponent(ChildReference reference)
          Open an accessor to a child.
<T extends Accessor>
T
getContentAccessor()
          Get an accessor to the variant's content.
 Datatype getContentType()
          Get the type of the content
 java.lang.Object getContentValue(Binding contentBinding)
          Get the content of this variant
 void removeListener(Accessor.Listener listener)
          Remove a listener.
 void setContentValue(Binding valueBinding, java.lang.Object value)
          Set the content of this variant.
 void setContentValueNoflush(Binding valueBinding, java.lang.Object value)
           
 void setValueNoflush(Binding variantBinding, java.lang.Object variantValue)
          Write a new value and don't flush the buffer
 VariantType 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, getParams, getReadLock, getSource, getValue, getValue, getWriteLock, isOpen, reset, 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.file.FileAccessor
close, file, flush, reset
 
Methods inherited from interface org.simantics.databoard.accessor.Accessor
apply, getValue, getValue, setValue
 

Constructor Detail

BinaryVariant

public BinaryVariant(BinaryObject parent,
                     Blob blob,
                     Datatype type,
                     AccessorParams params)
Method Detail

type

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

getContentAccessor

public <T extends Accessor> T getContentAccessor()
                                      throws AccessorConstructionException
Description copied from interface: VariantAccessor
Get an accessor to the variant's content.

Specified by:
getContentAccessor in interface VariantAccessor
Returns:
value
Throws:
AccessorConstructionException

setContentValueNoflush

public void setContentValueNoflush(Binding valueBinding,
                                   java.lang.Object value)
                            throws AccessorException
Specified by:
setContentValueNoflush in interface FileVariantAccessor
Throws:
AccessorException

setContentValue

public void setContentValue(Binding valueBinding,
                            java.lang.Object value)
                     throws AccessorException
Description copied from interface: VariantAccessor
Set the content of this variant. (Note! this methods sets the _content_ value, in contrast to Accessor.setValue(org.simantics.databoard.binding.Binding, Object) which sets the _variant_ value.

Specified by:
setContentValue in interface VariantAccessor
Throws:
AccessorException

getContentType

public Datatype getContentType()
                        throws AccessorException
Description copied from interface: VariantAccessor
Get the type of the content

Specified by:
getContentType in interface VariantAccessor
Returns:
type
Throws:
AccessorException

getContentValue

public java.lang.Object getContentValue(Binding contentBinding)
                                 throws AccessorException
Description copied from interface: VariantAccessor
Get the content of this variant

Specified by:
getContentValue in interface VariantAccessor
Returns:
content
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

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 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

setValueNoflush

public void setValueNoflush(Binding variantBinding,
                            java.lang.Object variantValue)
                     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