|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.mapper.MapperFactory
public class MapperFactory
MapperFactory
is responsible for creating mappers based on
domain class names or any other String name. This allows a domain class to
be a value bean and delegate data storage responsibility to a specific
Mapper
subclass.
MapperFactory.getMapper()
method uses caching to prevent
creating mappers multiple times. This means that a Mapper returned from
getMapper()
will not be a new instance which could cause
problems in a multi-threaded environment (the servlet container environment
is multi-threaded). Mappers returned by the MapperFactory
should not use instance variables to maintain state, rather, they should
use local method variables so they are thread-safe.
Note that you do not need to subclass MapperFactory
to specify
the specific Mapper
implementation classes to return from
getMapper()
. Because Mapper
implementation
classes are defined in a Map
, you can have any combination of
Mapper
types in use at the same time. For example, you could
have EjbPersonMapper using an EJB to persist Person objects and a
JdbcOrderMapper using JDBC calls to persist Order objects. You can register
MapperFactoryListener
implementations with the factory to
initialize the various types of Mappers when they are created.
Mapper
,
MapperFactoryListener
Field Summary | |
---|---|
protected ObjectFactory |
factory
This factory actually creates the mappers. |
Constructor Summary | |
---|---|
MapperFactory(Map map)
Create a new MapperFactory with the mappings contained in the given Map. |
Method Summary | |
---|---|
void |
addMapperFactoryListener(MapperFactoryListener listener)
Register a listener with this MapperFactory to receive notifications of events. |
Mapper |
getMapper(Class mappedClass)
Factory method for getting the mapper associated with the given class. |
Mapper |
getMapper(String name)
Factory method for getting the mapper associated with the given class. |
void |
removeMapperFactoryListener(MapperFactoryListener listener)
Unregister a listener from this MapperFactory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ObjectFactory factory
Constructor Detail |
---|
public MapperFactory(Map map)
map
- Any map containing logical names (often domain class names)
as the keys and mapper class names as the values.
IllegalArgumentException
- if there is a problem finding the
mapped classes.Method Detail |
---|
public Mapper getMapper(Class mappedClass)
mappedClass
- The class whose mapper should be returned
IllegalArgumentException
- if the given Class was not found in
the map or there was an error creating an instance of the Mapper. This
is usually caused by a missing public no-arg constructor.public Mapper getMapper(String name)
name
- The name of the mapper to be returned.
IllegalArgumentException
- if the given name was not found in
the map or there was an error creating an instance of the Mapper. This
is usually caused by a missing public no-arg constructor.public void addMapperFactoryListener(MapperFactoryListener listener)
listener
- public void removeMapperFactoryListener(MapperFactoryListener listener)
listener
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |