org.simantics.databoard.binding.impl
Class ObjectVariantBinding

java.lang.Object
  extended by org.simantics.databoard.binding.Binding
      extended by org.simantics.databoard.binding.VariantBinding
          extended by org.simantics.databoard.binding.impl.ObjectVariantBinding
All Implemented Interfaces:
java.util.Comparator<java.lang.Object>

public class ObjectVariantBinding
extends VariantBinding

ObjectVariantBinding binds VarianType and Object.class. The implementation is immutable as Object.class is not a container, it is a value.

ObjectVariantBinding understands many classes Collections: ArrayList, List, LinkedList, int[], .., other arrays [], Map, TreeMap, HashMap, Set, HashSet, TreeSet, Strings: String immutable primitives: Integer, Boolean, ... mutable primitives: MutableInteger, MutableBoolean, ... classes: Record-classes, Bean-Classes, Immutable-Classes null is bound to a void.

Author:
Toni Kalajainen

Nested Class Summary
 
Nested classes/interfaces inherited from class org.simantics.databoard.binding.Binding
Binding.Visitor<T>, Binding.Visitor1
 
Constructor Summary
ObjectVariantBinding(java.util.Map<BindingRequest,Binding> repository)
           
 
Method Summary
 void assertInstaceIsValid(java.lang.Object obj, java.util.Set<java.lang.Object> validInstances)
          Assert the obj is valid data type
 java.lang.Object create(Binding srcBinding, java.lang.Object value)
          Create a new variant object.
 java.lang.Object getContent(java.lang.Object variant)
          Get the value of the variant.
 java.lang.Object getContent(java.lang.Object variant, Binding binding)
          Get the value in the variant.
 Binding getContentBinding(java.lang.Object variant)
          Return a suggestion for the binding of the content of this variant.
 Datatype getContentType(java.lang.Object variant)
          Get the data type of the content.
 java.util.Map<BindingRequest,Binding> getRepository()
           
 Binding introduceBinding(Binding binding, java.lang.Class<?> clazz)
          ObjectVariantBinding can bind basic classes without problems.
 boolean isImmutable()
          Return true if the value is immutable.
 boolean isInstance(java.lang.Object obj)
           
 void setContent(java.lang.Object variant, Binding binding, java.lang.Object value)
          Set the content of an variant.
 
Methods inherited from class org.simantics.databoard.binding.VariantBinding
accept, accept, createUnchecked, deepCompare, deepHashValue, getComponentBinding, getComponentBinding, getComponentCount, readFrom
 
Methods inherited from class org.simantics.databoard.binding.Binding
assertInstaceIsValid, clone, cloneUnchecked, compare, createDefault, createDefaultUnchecked, createRandom, createRandomUnchecked, equals, hashValue, parseValue, parseValue, parseValueDefinition, printValue, printValueDefinition, serializer, toString, type
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

ObjectVariantBinding

public ObjectVariantBinding(java.util.Map<BindingRequest,Binding> repository)
Method Detail

getRepository

public java.util.Map<BindingRequest,Binding> getRepository()

introduceBinding

public Binding introduceBinding(Binding binding,
                                java.lang.Class<?> clazz)
ObjectVariantBinding can bind basic classes without problems. To be able to bind exact classes, the user must introduce class and binding

Parameters:
binding -
clazz -
Returns:
old binding or null

create

public java.lang.Object create(Binding srcBinding,
                               java.lang.Object value)
                        throws BindingException
Description copied from class: VariantBinding
Create a new variant object. The value argument may be included in the result.

Specified by:
create in class VariantBinding
Parameters:
srcBinding - the binding of the content
value - content
Returns:
new variant
Throws:
BindingException

getContentBinding

public Binding getContentBinding(java.lang.Object variant)
                          throws BindingException
Description copied from class: VariantBinding
Return a suggestion for the binding of the content of this variant.

Specified by:
getContentBinding in class VariantBinding
Parameters:
variant - variant object
Returns:
binding a binding
Throws:
BindingException

getContentType

public Datatype getContentType(java.lang.Object variant)
                        throws BindingException
Description copied from class: VariantBinding
Get the data type of the content.

Specified by:
getContentType in class VariantBinding
Parameters:
variant - the variant object
Returns:
the data type
Throws:
BindingException

getContent

public java.lang.Object getContent(java.lang.Object variant,
                                   Binding binding)
                            throws BindingException
Description copied from class: VariantBinding
Get the value in the variant. The returned value may represent internal value of variant.

Specified by:
getContent in class VariantBinding
Parameters:
variant - the variant object to read the content from
binding - the format of return value
Returns:
value variant's content
Throws:
BindingException

getContent

public java.lang.Object getContent(java.lang.Object variant)
                            throws BindingException
Description copied from class: VariantBinding
Get the value of the variant. The value is bound with the suggested binding, see VariantBinding.getContentBinding(Object).

Specified by:
getContent in class VariantBinding
Parameters:
variant - the variant object
Returns:
value variant's content
Throws:
BindingException

setContent

public void setContent(java.lang.Object variant,
                       Binding binding,
                       java.lang.Object value)
                throws BindingException
Description copied from class: VariantBinding
Set the content of an variant.

Specified by:
setContent in class VariantBinding
Parameters:
variant - variant object
binding - content's binding
value - new content
Throws:
BindingException

assertInstaceIsValid

public void assertInstaceIsValid(java.lang.Object obj,
                                 java.util.Set<java.lang.Object> validInstances)
                          throws BindingException
Description copied from class: Binding
Assert the obj is valid data type

Specified by:
assertInstaceIsValid in class Binding
Parameters:
obj - the instance
validInstances - optional set of already validated instances
Throws:
BindingException - on invalid instance

isInstance

public boolean isInstance(java.lang.Object obj)
Specified by:
isInstance in class Binding

isImmutable

public boolean isImmutable()
Description copied from class: Binding
Return true if the value is immutable. This question excludes the immutability of the component types.

Overrides:
isImmutable in class Binding
Returns:
true value if immutable