public class BaseContainerInstantiator extends Object implements IContainerInstantiator
IContainerInstantiator
. ECF provider implementers
may subclass as desired.Modifier and Type | Field and Description |
---|---|
protected static Class[][] |
EMPTY_CLASS_ARRAY |
protected static String[] |
EMPTY_STRING_ARRAY |
protected static String[] |
NO_ADAPTERS_ARRAY |
Constructor and Description |
---|
BaseContainerInstantiator() |
Modifier and Type | Method and Description |
---|---|
IContainer |
createInstance(ContainerTypeDescription description,
Object[] parameters)
Create instance of IContainer.
|
protected Set |
getAdaptersForClass(Class clazz) |
protected ID |
getIDParameterValue(Namespace ns,
Map<String,?> parameters,
String key) |
protected <T> ID |
getIDParameterValue(Namespace ns,
Map<String,?> parameters,
String key,
Class<T> type,
T def) |
protected ID |
getIDParameterValue(Namespace ns,
Map<String,?> parameters,
String key,
String def) |
protected Integer |
getIntegerFromArg(Object arg) |
protected String[] |
getInterfacesAndAdaptersForClass(Class clazz) |
protected Set |
getInterfacesForClass(Class clazz) |
protected Set |
getInterfacesForClass(Set s,
Class clazz) |
protected Map<String,?> |
getMap(Object[] parameters) |
protected String |
getMapParameterString(Object[] parameters,
String key) |
protected String |
getMapParameterString(Object[] parameters,
String key,
String def) |
protected String |
getParameterValue(Map<String,?> parameters,
String key) |
protected <T> T |
getParameterValue(Map<String,?> parameters,
String key,
Class<T> clazz,
T def) |
protected String |
getParameterValue(Map<String,?> parameters,
String key,
String def) |
protected <T> T |
getParameterValue(Object[] parameters,
String key,
Class<T> clazz) |
protected <T> T |
getParameterValue(Object[] parameters,
String key,
Class<T> clazz,
T def) |
protected String |
getStringFromArg(Object arg) |
String[] |
getSupportedAdapterTypes(ContainerTypeDescription description)
Get array of supported adapters for the given container type description.
|
String[] |
getSupportedIntents(ContainerTypeDescription description) |
Class[][] |
getSupportedParameterTypes(ContainerTypeDescription description)
Get array of parameter types for given container type description.
|
protected static String[] NO_ADAPTERS_ARRAY
protected static String[] EMPTY_STRING_ARRAY
protected static Class[][] EMPTY_CLASS_ARRAY
protected Integer getIntegerFromArg(Object arg)
arg
- object to get Integer fromprotected String getStringFromArg(Object arg)
arg
- object to get String fromprotected Map<String,?> getMap(Object[] parameters)
parameters
- parameters to get Map fromprotected <T> T getParameterValue(Map<String,?> parameters, String key, Class<T> clazz, T def)
T
- the expected value typeparameters
- Map parameters to get value fromkey
- the key to use to get value from parametersclazz
- the expected type of the value accessed by keydef
- the default of the value accessed by key. May be null
protected String getParameterValue(Map<String,?> parameters, String key, String def)
parameters
- Map parameters to get value fromkey
- the key to use to get value from parametersdef
- the default of the value accessed by key. May be null
protected String getParameterValue(Map<String,?> parameters, String key)
parameters
- Map parameters to get value fromkey
- the key to use to get value from parametersprotected <T> ID getIDParameterValue(Namespace ns, Map<String,?> parameters, String key, Class<T> type, T def)
T
- the expected value typens
- namespace to use for ID creation. Must not be null
parameters
- Map parameters to get value fromkey
- the key to use to get value from parameterstype
- the expected type of the value from parametersdef
- a default value to use if value from parameters is nullprotected ID getIDParameterValue(Namespace ns, Map<String,?> parameters, String key, String def)
ns
- namespace to use for ID creation. Must not be null
parameters
- Map parameters to get value fromkey
- the key to use to get value from parametersdef
- a default String value to use if value from parameters is nullprotected ID getIDParameterValue(Namespace ns, Map<String,?> parameters, String key)
ns
- namespace to use for ID creation. Must not be null
parameters
- Map parameters to get value fromkey
- the key to use to get value from parametersprotected <T> T getParameterValue(Object[] parameters, String key, Class<T> clazz, T def)
T
- the expected value typeparameters
- parameters assumed to contain a Mapkey
- key to use to get parameter value from Mapclazz
- the expected type of the value from Mapdef
- a default value to use if value from Map is null
protected <T> T getParameterValue(Object[] parameters, String key, Class<T> clazz)
T
- the expected value typeparameters
- parameters assumed to contain a Mapkey
- key to use to get parameter value from Mapclazz
- the expected type of the value from Mapprotected String getMapParameterString(Object[] parameters, String key, String def)
parameters
- parameters assumed to contain a Mapkey
- key to use to get parameter value from Mapdef
- a default String value to use if value from Map is null
protected String getMapParameterString(Object[] parameters, String key)
parameters
- parameters assumed to contain a Mapkey
- key to use to get parameter value from Mappublic IContainer createInstance(ContainerTypeDescription description, Object[] parameters) throws ContainerCreateException
IContainerInstantiator
ContainerFactory.getDefault().createContainer("foocontainer",new Object { "hello" });
createInstance
in interface IContainerInstantiator
description
- the ContainerTypeDescription associated with the registered
container provider implementationparameters
- parameters specified by the caller. May be null if no
parameters are passed in by caller to
ContainerFactory.getDefault().createContainer(...)ContainerCreateException
- thrown if instance cannot be createdpublic String[] getSupportedAdapterTypes(ContainerTypeDescription description)
IContainerInstantiator
IContainer.getAdapter(Class)
with the same type name as a
returned value will return a non-null
result. In other
words, even if the class name is in the returned array, subsequent calls
to IContainer.getAdapter(Class)
may still return
null
.getSupportedAdapterTypes
in interface IContainerInstantiator
description
- the ContainerTypeDescription to report adapters for. Must not
be null
.null
may be returned by
the provider if no adapters are supported for this description.public Class[][] getSupportedParameterTypes(ContainerTypeDescription description)
IContainerInstantiator
IContainerInstantiator.createInstance(ContainerTypeDescription, Object[])
.
Each of the rows of the returned array specifies a Class[] of parameter
types. These parameter types correspond to the types of Object[] that can
be passed into the second parameter of
IContainerInstantiator.createInstance(ContainerTypeDescription, Object[])
.
Consider the following example:
public Class[][] getSupportedParameterTypes() { return new Class[][] { { String.class }, { String.class, String.class } }; }The above means that there are two acceptable values for the Object [] passed into
IContainerInstantiator.createInstance(ContainerTypeDescription, Object[])
:
1) a single String, and 2) two Strings. These would therefore be
acceptable as input to createInstance:
IContainer container = ContainerFactory.getDefault().createContainer( description, new Object[] { "Hello" }); IContainer container2 = ContainerFactory.getDefault().createContainer( description, new Object[] { "Hello" });
getSupportedParameterTypes
in interface IContainerInstantiator
description
- the ContainerTypeDescription to return parameter types forIContainerInstantiator.createInstance(ContainerTypeDescription, Object[])
.
null
returned if no parameter types supported for
given description.public String[] getSupportedIntents(ContainerTypeDescription description)
getSupportedIntents
in interface IContainerInstantiator
Copyright © 2004–2020 Eclipse Foundation. All rights reserved.