org.simantics.databoard
Class Methods

java.lang.Object
  extended by org.simantics.databoard.Methods

public class Methods
extends java.lang.Object

This is a facade class for method services.

Author:
Toni Kalajainen

Field Summary
static MethodReflectionBinding methodReflectionBinding
           
static Interface NULL_INTERFACE
           
 
Constructor Summary
Methods()
           
 
Method Summary
static MethodInterface adaptMethods(MethodInterface mi, MethodTypeDefinition[] rangeMethods)
           
static
<T> MethodInterface
bindInterface(java.lang.Class<T> interfaze, T obj)
          Creates a InterfaceBinding implementation out of an object that implements an interface.
static MethodInterface bindInterface(Interface interfaceType, java.lang.Object obj)
          Bind an interface type to an instance.
static MethodInterface composeMethods(MethodInterface... interfaces)
           
static
<T> T
createProxy(java.lang.Class<T> interfaze, MethodInterface ib)
          Creates a proxy implementation that implements all methods of the interface.
static Interface getInterfaceType(java.lang.Class<?> interfaze)
           
static Interface getInterfaceTypeUnchecked(java.lang.Class<?> interfaze)
           
static MethodTypeDefinition getMethodDescription(java.lang.reflect.Method m)
          Get method description
static MethodType getMethodType(java.lang.reflect.Method m)
          Get method description
static MethodTypeBinding getMethodTypeBinding(java.lang.reflect.Method m)
          Get method binding of a method.
static MethodTypeBinding[] getMethodTypeBindings(java.lang.Class<?> interfaze)
          Get method bindings for all methods of an interface
static MethodTypeBinding[] getMethodTypeBindingsUnchecked(java.lang.Class<?> interfaze)
          Get method type bindings of all methods of an interface
static MethodInterface noMethods()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_INTERFACE

public static Interface NULL_INTERFACE

methodReflectionBinding

public static MethodReflectionBinding methodReflectionBinding
Constructor Detail

Methods

public Methods()
Method Detail

adaptMethods

public static MethodInterface adaptMethods(MethodInterface mi,
                                           MethodTypeDefinition[] rangeMethods)

bindInterface

public static MethodInterface bindInterface(Interface interfaceType,
                                            java.lang.Object obj)
                                     throws BindingConstructionException
Bind an interface type to an instance. The obj must have all the methods described in the interface type.

Parameters:
interfaceType - interface type
obj - instance
Returns:
interface binding
Throws:
BindingConstructionException

bindInterface

public static <T> MethodInterface bindInterface(java.lang.Class<T> interfaze,
                                                T obj)
                                     throws BindingConstructionException
Creates a InterfaceBinding implementation out of an object that implements an interface. All the methods of the interface are represented in the resulting InterfaceBinding. MethodTypeDefinitions are generated automatically.

There are restrictions to interface methods. Methods cannot have as argument, return type or as an exception anything Datatypes.getDatatype(Class) cannot create data type out of. In other perspective, all classes must be composed of simple array, record, union, and primitive types.

Parameters:
interfaze - interface to inspect methods from
obj - implementing object
Returns:
method interface implementation
Throws:
BindingConstructionException

createProxy

public static <T> T createProxy(java.lang.Class<T> interfaze,
                                MethodInterface ib)
                     throws BindingConstructionException
Creates a proxy implementation that implements all methods of the interface. The interface binding ib must implement all the methods.

Parameters:
interfaze - interface
ib - interface binding
Returns:
an implementation to interfaze
Throws:
BindingConstructionException - on construction error

getMethodDescription

public static MethodTypeDefinition getMethodDescription(java.lang.reflect.Method m)
                                                 throws DatatypeConstructionException
Get method description

Parameters:
m -
Returns:
method description
Throws:
DatatypeConstructionException

getMethodType

public static MethodType getMethodType(java.lang.reflect.Method m)
                                throws DatatypeConstructionException
Get method description

Parameters:
m -
Returns:
method type
Throws:
DatatypeConstructionException

getMethodTypeBinding

public static MethodTypeBinding getMethodTypeBinding(java.lang.reflect.Method m)
                                              throws BindingConstructionException
Get method binding of a method. Method arguments are wrapped into an Object[]. Throwables in an UnionType.

Parameters:
m -
Returns:
method bindings
Throws:
BindingConstructionException

getMethodTypeBindingsUnchecked

public static MethodTypeBinding[] getMethodTypeBindingsUnchecked(java.lang.Class<?> interfaze)
Get method type bindings of all methods of an interface

Parameters:
interfaze -
Returns:
and array of method type bindings

getMethodTypeBindings

public static MethodTypeBinding[] getMethodTypeBindings(java.lang.Class<?> interfaze)
                                                 throws BindingConstructionException
Get method bindings for all methods of an interface

Parameters:
interfaze -
Returns:
an array of methods type bindings
Throws:
BindingConstructionException

getInterfaceType

public static Interface getInterfaceType(java.lang.Class<?> interfaze)
                                  throws BindingConstructionException
Throws:
BindingConstructionException

getInterfaceTypeUnchecked

public static Interface getInterfaceTypeUnchecked(java.lang.Class<?> interfaze)

composeMethods

public static MethodInterface composeMethods(MethodInterface... interfaces)
                                      throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

noMethods

public static MethodInterface noMethods()