org.simantics.databoard.binding.reflection
Class ReflectionBindingFactory

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

public class ReflectionBindingFactory
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
ReflectionBindingFactory()
          Construct a new reflection binding factory
ReflectionBindingFactory(java.util.Map<BindingRequest,Binding> repository)
          Construct a new reflection binding factory that places constructed bindings into user given repository.
 
Method Summary
static void _getAllFields(java.lang.Class<?> clazz, java.util.Collection<java.lang.reflect.Field> result)
           
 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)
           
 java.util.Map<BindingRequest,Binding> getRepository()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionBindingFactory

public ReflectionBindingFactory()
Construct a new reflection binding factory


ReflectionBindingFactory

public ReflectionBindingFactory(java.util.Map<BindingRequest,Binding> repository)
Construct a new reflection binding factory that places constructed bindings into user given repository.

Parameters:
repository -
Method Detail

getRepository

public java.util.Map<BindingRequest,Binding> 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:
ReflectionBindingFactory

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

getBinding

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

getBindingUnchecked

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

_getAllFields

public static void _getAllFields(java.lang.Class<?> clazz,
                                 java.util.Collection<java.lang.reflect.Field> result)