|
ProgramixGenericLib v4.0.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.programix.da2.DAFactory
public class DAFactory
Used to construct and initialize instances of data access implementations using reflection.
Common usage is (where CustomerDA is an interface
that extends the GenericDA interface):
orValueMapconfig = //... CustomerDA cda = (CustomerDA) DAFactory.create(config, CustomerDA.class);
String filename = //...
CustomerDA cda = (CustomerDA) DAFactory.create(filename, CustomerDA.class);
The configuration ValueMap passed in must contain the
class name of the class to be instantiated stored under the key
DA_IMPLEMENTATION_CLASSNAME. Other key/value pairs in the map
are populated with whatever the specific data access
implementation needs for initialization.
| Field Summary | |
|---|---|
static String |
DA_IMPLEMENTATION_CLASSNAME
The reserved key that retrieves the fully-qualified name (as a String) of the data access implementation class that will be instantiated via reflection. |
static String |
DA_SOURCE_PREFIX
Used by this factory to facilitate the creation and initialization of a chain of data access' if the outer 'wrappers' implement DecoratorDA. |
| Method Summary | |
|---|---|
static GenericDA |
create(File file,
Class targetType)
Create a data access instance using an File whose data is in the format described by ValueMap
(nearly identical to the format for a Properties file). |
static GenericDA |
create(InputStream rawIn,
Class targetType)
Create a data access instance using an InputStream whose data is in the format described by ValueMap
(nearly identical to the format for a Properties file). |
static GenericDA |
create(Reader rawIn,
Class targetType)
Create a data access instance using a Reader whose data is in the format described by ValueMap
(nearly identical to the format for a Properties file). |
static GenericDA |
create(URL propertiesURL,
Class targetType)
Create a data access instance using the specified URL whose data is in the format described by ValueMap(nearly identical to the format for a
Properties file). |
static GenericDA |
create(ValueMap config,
Class daInterfaceType)
Constructs an instance of the data access implementation specified in the configuration. |
static GenericDA |
createFromFile(String filename,
Class targetType)
Create a data access instance using the specified filename whose data is in the format described by ValueMap(nearly identical to the format for a
Properties file). |
static GenericDA |
createFromResource(String resourceLocation,
Class targetType)
Create a data access instance using the specified resourceLocation whose data is in the format described by ValueMap(nearly identical to the format for a
Properties file). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String DA_IMPLEMENTATION_CLASSNAME
The value of this key is always:
da.impl.classname
create(ValueMap, Class),
Constant Field Valuespublic static final String DA_SOURCE_PREFIX
DecoratorDA.
The reserved key prefix that when present in the configuration
ValueMap is used to extract a sub-map via the
getNestedValueMap(prefix)
on ValueMap. This sub-map is then passed off to the source
of the DecoratorDA.
The value of this key is always (note the trailing dot):
da.source.
create(ValueMap, Class),
Constant Field Values| Method Detail |
|---|
public static GenericDA create(ValueMap config,
Class daInterfaceType)
throws DAException
DA_IMPLEMENTATION_CLASSNAME
with a String value which is the full class name of the
implementation of the data access interface.
Immediately after the zero-argument constructor is invoked,
the init(ValueMap conf) of
GenericDA is invoked to initialize the configuration.
If the targetType is not null, then an additional check is done to ensure that the constructed object can be type cast into that type (failures throw a DAException instead of a ClassCastException).
If the implementation happens to be not only a GenericDA
but also a DecoratorDA and there are config map
keys starting with the DA_SOURCE_PREFIX, then this
create method will attempt to create the chain of decorated data access
implementations. This create method will attempt to extract a
sub-map using this reserved key prefix via the
getNestedValueMap(prefix)
on ValueMap. This sub-map is then used to create the source
of the DecoratorDA.
config - key/value mapping with everything that is needed to
initialize this data access implementation.daInterfaceType - the class type that this instance is expected
to be cast into. Use null to skip this check. If not
null and the type does not match what is constructed,
then a DAException is thrown.
DAException - if instance can not be constructed
and initialized.create(Reader, Class),
create(InputStream, Class),
createFromFile(String, Class),
create(File, Class),
create(URL, Class)
public static GenericDA create(Reader rawIn,
Class targetType)
throws DAException
ValueMap
(nearly identical to the format for a Properties file).
Internally, the stream will be buffered and the stream
will be closed.
rawIn - a stream whose contents can be loaded into
a ValueMap with everything that is needed to
initialize the instance of data access.targetType - the class type that this instance is expected
to be cast into. Use null to skip this check. If not
null and the type does not match what is constructed,
then a DataAccessException is thrown.
DAException - if instance can not be constructed
and initialized.create(ValueMap, Class),
create(InputStream, Class),
createFromFile(String, Class),
create(File, Class),
create(URL, Class)
public static GenericDA create(InputStream rawIn,
Class targetType)
throws DAException
ValueMap
(nearly identical to the format for a Properties file).
Internally, the stream will be buffered and the stream
will be closed.
rawIn - a stream whose contents can be loaded into
a ValueMap with everything that is needed to
initialize the instance of data access.targetType - the class type that this instance is expected
to be cast into. Use null to skip this check. If not
null and the type does not match what is constructed,
then a DataAccessException is thrown.
DAException - if instance can not be constructed
and initialized.create(ValueMap, Class),
create(Reader, Class),
createFromFile(String, Class),
create(File, Class),
create(URL, Class)
public static GenericDA create(File file,
Class targetType)
throws DAException
ValueMap
(nearly identical to the format for a Properties file).
file - file with key/value mapping with everything that
is needed to initialize the instance of data access.targetType - the class type that this instance is expected to be
cast into. Use null to skip this check. If not
null and the type does not match what is
constructed, then a DataAccessException is thrown.
DAException - if instance can not be constructed and
initialized.create(ValueMap, Class),
create(Reader, Class),
create(InputStream, Class),
createFromFile(String, Class),
create(URL, Class)
public static GenericDA createFromFile(String filename,
Class targetType)
throws DAException
ValueMap(nearly identical to the format for a
Properties file).
filename - file with key/value mapping with everything that is
needed to initialize the instance of data access.targetType - the class type that this instance is expected to be
cast into. Use null to skip this check. If not
null and the type does not match what is
constructed, then a DataAccessException is thrown.
DAException - if instance can not be constructed and
initialized.create(ValueMap, Class),
create(Reader, Class),
create(InputStream, Class),
create(File, Class),
create(URL, Class)
public static GenericDA create(URL propertiesURL,
Class targetType)
throws DAException
ValueMap(nearly identical to the format for a
Properties file).
propertiesURL - a URL whose contents can be loaded into
a ValueMap with everything that is needed to
initialize the instance of data access.targetType - the class type that this instance is expected
to be cast into. Use null to skip this check. If not
null and the type does not match what is constructed,
then a DataAccessException is thrown.
DAException - if instance can not be constructed
and initialized.create(ValueMap, Class),
create(Reader, Class),
create(InputStream, Class),
createFromFile(String, Class),
create(File, Class)
public static GenericDA createFromResource(String resourceLocation,
Class targetType)
throws DAException
ValueMap(nearly identical to the format for a
Properties file).
resourceLocation - resource with key/value mapping with
everything that is
needed to initialize the instance of data access.targetType - the class type that this instance is expected to be
cast into. Use null to skip this check. If not
null and the type does not match what is
constructed, then a DataAccessException is thrown.
DAException - if instance can not be constructed and
initialized.create(ValueMap, Class),
create(Reader, Class),
create(InputStream, Class),
create(File, Class),
create(URL, Class)
|
ProgramixGenericLib v4.0.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||