org.simantics.databoard.accessor.impl
Class CompositeRecord

java.lang.Object
  extended by org.simantics.databoard.accessor.impl.CompositeRecord
All Implemented Interfaces:
Accessor, RecordAccessor
Direct Known Subclasses:
StepwiseDatasourceAccessor

public class CompositeRecord
extends java.lang.Object
implements RecordAccessor

Record is an accessor to a record where fields defined from a composition of other accessors. Fields should not be modified while CompositeRecord is in accessor usage.

Author:
Toni Kalajainen

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.Accessor
Accessor.Listener
 
Constructor Summary
CompositeRecord()
           
 
Method Summary
 void addField(java.lang.String name, Accessor field)
           
 void addListener(Accessor.Listener listener, InterestSet interestSet, AccessorReference path)
          Place a listener to an accessor node.
 void apply(java.util.List<Event> cs, java.util.LinkedList<Event> rollback)
          Apply a change set in a single transaction operation.
 int count()
          Get the number of fields in the record
<T extends Accessor>
T
getAccessor(AccessorReference reference)
          Get an accessor to a sub-container.
<T extends Accessor>
T
getFieldAccessor(int index)
          Get an accessor to a field.
<T extends Accessor>
T
getFieldAccessor(java.lang.String fieldName)
          Get an accessor to a field.
 java.lang.Object getFieldValue(int index, Binding fieldBinding)
          Get field value
 java.lang.Object getValue(Binding binding)
          Get a snapshot of the object model as a single data value.
 void removeField(java.lang.String name)
           
 void removeListener(Accessor.Listener listener)
          Remove a listener.
 void setFieldValue(int index, Binding fieldBinding, java.lang.Object value)
          Set field value.
 void setValue(Binding binding, java.lang.Object newValue)
          Set a complete new value to the data container.
 RecordType type()
          Get structural represtentation of the accessor presented in databoard's type system format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeRecord

public CompositeRecord()
Method Detail

addField

public void addField(java.lang.String name,
                     Accessor field)

removeField

public void removeField(java.lang.String name)

count

public int count()
Description copied from interface: RecordAccessor
Get the number of fields in the record

Specified by:
count in interface RecordAccessor
Returns:
field count

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 or posssibly its decendant nodes, depending on interest set.

The synchronization contract is implementation specific, so read the document. A common contract is that the listener object must not make modifications to the accessor within the handle event function. The correct strategy is to collect events and mutate the accessor afterwards.

Each event instance spawned by the listener, is annotated with a reference that describes the reference path of the node to which the event applies to. The path originates from the node where the listener was placed.

Listener is attached to the container 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
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
Throws:
AccessorException

getFieldAccessor

public <T extends Accessor> T getFieldAccessor(int index)
                                    throws AccessorConstructionException
Description copied from interface: RecordAccessor
Get an accessor to a field. The return value becomes invalid if a new value is assigned with RecordAccessor.setFieldValue(int, Binding, Object).

Specified by:
getFieldAccessor in interface RecordAccessor
Returns:
accessor to the field
Throws:
AccessorConstructionException

getFieldAccessor

public <T extends Accessor> T getFieldAccessor(java.lang.String fieldName)
                                    throws AccessorConstructionException
Description copied from interface: RecordAccessor
Get an accessor to a field. The return value becomes invalid if a new value is assigned with RecordAccessor.setFieldValue(int, Binding, Object).

Specified by:
getFieldAccessor in interface RecordAccessor
Returns:
accessor to the field
Throws:
AccessorConstructionException

getFieldValue

public java.lang.Object getFieldValue(int index,
                                      Binding fieldBinding)
                               throws AccessorException
Description copied from interface: RecordAccessor
Get field value

Specified by:
getFieldValue in interface RecordAccessor
Returns:
the value of the field
Throws:
AccessorException

setFieldValue

public void setFieldValue(int index,
                          Binding fieldBinding,
                          java.lang.Object value)
                   throws AccessorException
Description copied from interface: RecordAccessor
Set field value. Writing the current value again may not emit an event. This is implementation specific.

Specified by:
setFieldValue in interface RecordAccessor
Parameters:
index - field index
Throws:
AccessorException

type

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

Specified by:
type in interface Accessor
Specified by:
type in interface RecordAccessor
Returns:
type description

apply

public void apply(java.util.List<Event> cs,
                  java.util.LinkedList<Event> rollback)
           throws AccessorException
Description copied from interface: Accessor
Apply a change set in a single transaction operation. If rollback log is supplied, it is filled with reverse events. If the operation fails, rollback log can be applied to cancel changes.

Specified by:
apply in interface Accessor
rollback - log to be filled with rollback events or null
Throws:
AccessorException - failed to apply change set

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

getValue

public java.lang.Object getValue(Binding binding)
                          throws AccessorException
Description copied from interface: Accessor
Get a snapshot of the object model as a single data value.

Specified by:
getValue in interface Accessor
Returns:
the value
Throws:
AccessorException

setValue

public void setValue(Binding binding,
                     java.lang.Object newValue)
              throws AccessorException
Description copied from interface: Accessor
Set a complete new value to the data container. If the new value removes old map entries, array entries, optional value, or changes union or variant value type, it will disengage any existing sub-accessors and send InvalidatedEvent.

Writing the current value again may not emit an event. This is implementation specific.

Write is durable, once a the method returns successfully the value has been stored in the implmentation.

Specified by:
setValue in interface Accessor
Throws:
AccessorException