org.simantics.databoard.accessor.java
Class JavaUnion

java.lang.Object
  extended by org.simantics.databoard.accessor.java.JavaObject
      extended by org.simantics.databoard.accessor.java.JavaUnion
All Implemented Interfaces:
Accessor, UnionAccessor

public class JavaUnion
extends JavaObject
implements UnionAccessor

Accessor to Java Object of Union Type

Author:
Toni Kalajainen

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.simantics.databoard.accessor.Accessor
Accessor.Listener
 
Constructor Summary
JavaUnion(JavaObject parent, UnionBinding binding, java.lang.Object object)
           
 
Method Summary
 void addListener(Accessor.Listener listener, InterestSet interestSet, AccessorReference path)
          Place a listener to an accessor node.
 int count()
          Get the number of tag types
<T extends Accessor>
T
getAccessor(AccessorReference reference)
          Get an accessor to a sub-container.
 UnionBinding getBinding()
           
<T extends Accessor>
T
getComponentAccessor()
          Get an accessor to the component value.
 java.lang.Object getComponentValue(Binding componentBinding)
          Get the value
 int getTag()
          Get the union tag index
 void removeListener(Accessor.Listener listener)
          Remove a listener.
 void setComponentValue(int tag, Binding componentBinding, java.lang.Object componentValue)
          Set a new component value.
 void setValue(Binding unionBinding, java.lang.Object newUnionValue)
          Set a new Union value.
 UnionType type()
          Get structural represtentation of the accessor presented in databoard's type system format.
 
Methods inherited from class org.simantics.databoard.accessor.java.JavaObject
apply, createAccessor, getObject, getValue, 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
 

Constructor Detail

JavaUnion

public JavaUnion(JavaObject parent,
                 UnionBinding binding,
                 java.lang.Object object)
Method Detail

type

public UnionType 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 UnionAccessor
Overrides:
type in class JavaObject
Returns:
type description

getBinding

public UnionBinding getBinding()
Overrides:
getBinding in class JavaObject

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

count

public int count()
          throws AccessorException
Description copied from interface: UnionAccessor
Get the number of tag types

Specified by:
count in interface UnionAccessor
Returns:
the number of tag types
Throws:
AccessorException

setValue

public void setValue(Binding unionBinding,
                     java.lang.Object newUnionValue)
              throws AccessorException
Description copied from interface: UnionAccessor
Set a new Union value. If the tag-type changes and there is an accessor to the previous value, it becomes invalid.

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

getComponentAccessor

public <T extends Accessor> T getComponentAccessor()
                                        throws AccessorConstructionException
Description copied from interface: UnionAccessor
Get an accessor to the component value. The accessor becomes invalid if a new value is assigned.

Specified by:
getComponentAccessor in interface UnionAccessor
Returns:
accessor to the value
Throws:
AccessorConstructionException

getComponentValue

public java.lang.Object getComponentValue(Binding componentBinding)
                                   throws AccessorException
Description copied from interface: UnionAccessor
Get the value

Specified by:
getComponentValue in interface UnionAccessor
Parameters:
componentBinding - component binding
Returns:
value
Throws:
AccessorException

getTag

public int getTag()
           throws AccessorException
Description copied from interface: UnionAccessor
Get the union tag index

Specified by:
getTag in interface UnionAccessor
Returns:
tag index
Throws:
AccessorException

setComponentValue

public void setComponentValue(int tag,
                              Binding componentBinding,
                              java.lang.Object componentValue)
                       throws AccessorException
Description copied from interface: UnionAccessor
Set a new component value. The argument newValue may be captured or copied.

Specified by:
setComponentValue in interface UnionAccessor
Throws:
AccessorException

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