org.simantics.databoard.binding.reflection
Class ClassBindingFactory

java.lang.Object
  extended by org.simantics.databoard.binding.reflection.ClassBindingFactory

public class ClassBindingFactory
extends java.lang.Object

Type Factory constructs data types from reflection requests. Successfully constructed types are placed in the repository that was given at construction time.

Author:
Toni Kalajainen

Constructor Summary
ClassBindingFactory()
          Construct a new reflection binding factory
ClassBindingFactory(BindingRepository repository)
          Construct a new reflection binding factory that places constructed bindings into user given repository.
 
Method Summary
 void addFactory(BindingSubFactory factory)
           
 Binding construct(BindingRequest request)
           
 Binding getBinding(BindingRequest request)
           
<T extends Binding>
T
getBinding(java.lang.Class<?> clazz)
          Get a binding to a Java Class.
<T extends Binding>
T
getBinding(java.lang.Class<?> clazz, java.lang.Class<?>... parameters)
          Get a binding to a Java Class.
 Binding getBindingUnchecked(BindingRequest request)
           
static java.lang.annotation.Annotation[] getFieldAnnotations(java.lang.reflect.Field field)
           
 BindingRepository getRepository()
           
 void removeFactory(BindingSubFactory factory)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassBindingFactory

public ClassBindingFactory()
Construct a new reflection binding factory


ClassBindingFactory

public ClassBindingFactory(BindingRepository repository)
Construct a new reflection binding factory that places constructed bindings into user given repository.

Parameters:
repository -
Method Detail

addFactory

public void addFactory(BindingSubFactory factory)

removeFactory

public void removeFactory(BindingSubFactory factory)

getRepository

public BindingRepository getRepository()

construct

public Binding construct(BindingRequest request)
                  throws BindingConstructionException
Throws:
BindingConstructionException

getBinding

public <T extends Binding> T getBinding(java.lang.Class<?> clazz)
                             throws BindingConstructionException
Get a binding to a Java Class. Type details can be modified with annotations. Please see the package org.simantics.databoard.annotations.

The whether the result binding is a completely mutable or not depends on the provided classes. For instance, fields such as Boolean, Integer, Long are not mutable, instead MutableBoolean, MutableInteger and MutableLong are. The length of Object[] is not mutable, but length of List is.

Note, results are stored with strong reference into the repository assigned to this factory.

Parameters:
clazz -
Returns:
binding
Throws:
BindingConstructionException
See Also:
ClassBindingFactory

getBinding

public <T extends Binding> T getBinding(java.lang.Class<?> clazz,
                                        java.lang.Class<?>... parameters)
                             throws BindingConstructionException
Get a binding to a Java Class. Use this method to acquire class parameters for a generics class.

Example 1: Binding binding = getBinding(Map.class, String.class, Integer.class); Map map = (Map) binding.createDefault(); Example 2: Binding d = getBinding(List.class, Integer.class); List list = (List) d.createRandom(5); Example 3: Binding d = getBinding(List.class, List.class, Integer.class); List> list = (List>) d.createRandom(5);

Parameters:
clazz -
Returns:
binding
Throws:
BindingConstructionException
See Also:
ClassBindingFactory

getBinding

public Binding getBinding(BindingRequest request)
                   throws BindingConstructionException
Throws:
BindingConstructionException

getBindingUnchecked

public Binding getBindingUnchecked(BindingRequest request)
                            throws RuntimeBindingConstructionException
Throws:
RuntimeBindingConstructionException

getFieldAnnotations

public static java.lang.annotation.Annotation[] getFieldAnnotations(java.lang.reflect.Field field)