public class Loader extends Object
The Loader
wraps Java reflection API exceptions in XatkitException
s, easing client code to handle
loading and construction errors.
Constructor and Description |
---|
Loader() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
construct(Class<T> clazz)
Constructs a new instance of the provided
clazz using its default constructor. |
static <T> T |
construct(Class<T> clazz,
Class<?> parameterType1,
Class<?> parameterType2,
Object parameter1,
Object parameter2)
Constructs a new instance of the provided
clazz with the given parameter1 and parameter2 . |
static <T> T |
construct(Class<T> clazz,
Class<?> parameterType,
Object parameter)
Constructs a new instance of the provided
clazz with the given parameter . |
static <T> T |
construct(Class<T> clazz,
List<Class<?>> parameterTypes,
List<Object> parameters)
Constructs a new instance of the provided
clazz with the given parameters . |
static <T> T |
construct(Class<T> clazz,
Object[] parameters)
Constructs a new instance of
clazz with the given parameters . |
static RuntimeEventProvider |
constructRuntimeEventProvider(Class<? extends RuntimeEventProvider> eventProviderClass,
RuntimePlatform runtimePlatform,
Configuration configuration)
Constructs a new instance of the provided
eventProviderClass with the given xatkitCore and
configuration . |
static RuntimePlatform |
constructRuntimePlatform(Class<? extends RuntimePlatform> runtimePlatformClass,
XatkitCore xatkitCore,
Configuration configuration)
Constructs a new instance of the provided
runtimePlatformClass with the given xatkitCore and
configuration . |
static <T> Class<? extends T> |
loadClass(String qualifiedName,
Class<T> superClass)
Loads the Class with the provided
qualifiedName , and casts it to the provided superClass . |
public static <T> Class<? extends T> loadClass(String qualifiedName, Class<T> superClass) throws XatkitException
qualifiedName
, and casts it to the provided superClass
.T
- the super type of the Class
to loadqualifiedName
- the name of the Class
to loadsuperClass
- the super-class of the Class
to loadClass
casted to the provided superClass
XatkitException
- if the provided qualifiedName
is not a valid Class
name, or if the
loaded Class
is not a sub-class of the provided superClass
public static <T> T construct(Class<T> clazz, Object[] parameters) throws NoSuchMethodException, InvocationTargetException
clazz
with the given parameters
.
This method iterates through the clazz
Constructor
s and attempt to find one that accepts the
provided parameters
. Note that this method tries to call all the Constructor
s that define as
many parameters as the ones provided. If the parameters
types are known use
construct(Class, List, List)
that directly calls the appropriate Constructor
.
T
- the type of the Class
to construct an instance ofclazz
- the Class
to construct a new instance ofparameters
- the concrete parameters of the constructor to callNoSuchMethodException
- if the provided clazz
does not define a constructor matching the
provided
parameters
InvocationTargetException
- if the called constructor throws an exceptionconstruct(Class, List, List)
public static <T> T construct(Class<T> clazz) throws XatkitException
clazz
using its default constructor.
Use construct(Class, Class, Object)
, construct(Class, Class, Class, Object, Object)
,
construct(Class, List, List)
, or construct(Class, Object[])
to construct an instance of
clazz
with parameters.
T
- the type of the Class
to construct an instance ofclazz
- the Class
to construct a new instance ofXatkitException
- if an error occurred when calling the clazz
's constructorconstruct(Class, Class, Object)
,
construct(Class, List, List)
,
construct(Class, Object[])
public static <T> T construct(Class<T> clazz, Class<?> parameterType, Object parameter) throws NoSuchMethodException, XatkitException
clazz
with the given parameter
.
This method is equivalent to construct(clazz, Arrays.asList(parameterType), Arrays.asList(parameters)
.
T
- the type of the Class
to construct an instance ofclazz
- the Class
to construct a new instance ofparameterType
- the parameter type in the constructor signatureparameter
- the concrete parameter of the constructor to callNoSuchMethodException
- if the provided clazz
does not define a constructor matching the
provided parameterType
XatkitException
- if an error occurred when calling the clazz
's constructorconstruct(Class, List, List)
public static <T> T construct(Class<T> clazz, Class<?> parameterType1, Class<?> parameterType2, Object parameter1, Object parameter2) throws NoSuchMethodException, XatkitException
clazz
with the given parameter1
and parameter2
.
This method is equivalent to construct(clazz, Arrays.asList(parameterType1, parameterType2), Arrays
.asList(parameter1, parameter2)
.
T
- the type of the Class
to construct an instance ofclazz
- the Class
to construct a new instance ofparameterType1
- the first parameter type in the constructor signatureparameterType2
- the second parameter type in the constructor signatureparameter1
- the first concrete parameter of the constructor to callparameter2
- the second concrete parameter of the constructor to callNoSuchMethodException
- if the provided clazz
does not define a constructor matching the
provided parameterType1
and parameterType2
XatkitException
- if an error occurred when calling the clazz
's constructorconstruct(Class, List, List)
public static <T> T construct(Class<T> clazz, List<Class<?>> parameterTypes, List<Object> parameters) throws NoSuchMethodException, XatkitException
clazz
with the given parameters
.
This method uses the Java reflection API to find the constructor accepting the provided parameterTypes
, and attempts to instantiate the provided clazz
using the given parameters
.
T
- the type of the Class
to construct an instance ofclazz
- the Class
to construct a new instance ofparameterTypes
- the List
of parameter types in the constructor signatureparameters
- the concrete parameters of the constructor to callNoSuchMethodException
- if the provided clazz
does not define a constructor matching the
provided parameterTypes
XatkitException
- if an error occurred when calling the clazz
's constructorpublic static RuntimePlatform constructRuntimePlatform(Class<? extends RuntimePlatform> runtimePlatformClass, XatkitCore xatkitCore, Configuration configuration)
runtimePlatformClass
with the given xatkitCore
and
configuration
.
This method first tries to construct an instance of the provided runtimePlatformClass
with the provided
xatkitCore
and configuration
. If the RuntimePlatform
does not define such constructor,
the method logs a warning and tries to construct an instance with only the xatkitCore
parameter.
The runtimePlatformClass
parameter can be loaded by using this class' loadClass(String, Class)
utility method.
runtimePlatformClass
- the RuntimePlatform
Class
to construct a new instance ofxatkitCore
- the XatkitCore
instance used to construct the RuntimePlatform
configuration
- the Configuration
instance used to construct the RuntimePlatform
RuntimePlatform
XatkitException
- if the RuntimePlatform
does not define a constructor matching the provided
parameters.construct(Class, Class, Class, Object, Object)
,
loadClass(String, Class)
public static RuntimeEventProvider constructRuntimeEventProvider(Class<? extends RuntimeEventProvider> eventProviderClass, RuntimePlatform runtimePlatform, Configuration configuration)
eventProviderClass
with the given xatkitCore
and
configuration
.
This method first tries to construct an instance of the provided eventProviderClass
with the provided
xatkitCore
and configuration
. If the RuntimeEventProvider
does not define such
constructor,
the method logs a warning and tries to construct an instance with only the xatkitCore
parameter.
The eventProviderClass
parameter can be loaded by using this class" loadClass(String, Class)
utility method.
eventProviderClass
- the RuntimeEventProvider
Class
to construct a new instance ofruntimePlatform
- the RuntimePlatform
instance used to construct the RuntimeEventProvider
configuration
- the Configuration
instance used to construct the RuntimeEventProvider
RuntimeEventProvider
XatkitException
- if the RuntimeEventProvider
does not define a constructor matching the provided
parameters.construct(Class, Class, Class, Object, Object)
,
loadClass(String, Class)
Copyright © 2020 SOM Research Lab. All rights reserved.