org.objectweb.jorm.lib
Class Mapper

java.lang.Object
  extended byorg.objectweb.jorm.lib.Mapper
All Implemented Interfaces:
Loggable, PMapper, PMappingCallback, PMappingStructuresManager
Direct Known Subclasses:
MapperJCA, MapperJDBC

public abstract class Mapper
extends java.lang.Object
implements PMapper, Loggable, PMappingCallback

Author:
P. Dechamboux

Field Summary
protected  Logger logger
          The logger associated with this mapper.
protected  LoggerFactory loggerFactory
          The logger factory associated with this mapper.
 
Fields inherited from interface org.objectweb.jorm.api.PMapper
JORMPROPFILE, PBINDINGAPPENDER, PCLASSMAPPINGAPPENDER
 
Constructor Summary
Mapper()
          It builds a JormConfigurator with the default JormCompilerParameter and JormCompilerParameter.
Mapper(JormConfigurator c)
           
 
Method Summary
 void addDependency(java.lang.String jcname1, java.lang.String jcname2)
          Adds a dependency between a defined class and another class.
 void addMapperEventListener(PMapperListener listener)
          Adds the given mapper listener to this mapper.
 void classDefined(java.lang.String jcname)
          Indicates that a jorm class is defined.
 void clean()
          Clean the mapper: forget all classes previously mapped.
 void clear()
          Clean the mapping structure manager: forget all classes.
 java.lang.String cn2mn(java.lang.String cn)
          Constructs a "mapped name" starting from a JORM class name.
 PClassMapping createGenClassMapping()
          Creates a new PClassMapping for a gen class.
 void declareClass(java.lang.String jcname)
          Declares a persistent class.
 boolean equals(java.lang.Object o)
           
 JormConfigurator getJormConfigurator()
           
 Logger getLogger()
          Returns a logger to an component that wants to log things.
 LoggerFactory getLoggerFactory()
          Returns a logger factory that allows the creation of new loggers.
 java.lang.String[] getMappedClasses()
           
 java.lang.String getMapperName()
          The name yielded by this method defines what kind of PMapper is used on a particular DS.
 Manager getMetaInfoManager()
          It retrieves a meta-information Manager that may used by a parser in order to load the meta-information associated to JORM classes mapped within this PMapper.
 PMapCluster getPMapCluster(java.lang.String jcname)
          Asks for the map cluster associated with a JORM class.
 java.util.Collection getPMapClusters()
          Asks for all the map clusters defined within this mapper.
 PMappingStructuresManager getPMappingStructuresManager()
          Retrieves the PMappingStructuresManager associated with this mapper.
 PrefetchCache getPrefetchCache()
          Returns the prefetch cache associated to this mapper.
 PTypeSpace getPTypeSpace()
          It returns a PTypeSpace that may be used to create PType associated to JORM classes mapped within this PMapper.
 int hashCode()
           
 PClassMapping lookup(java.lang.String classname)
          It looks for the PClassMapping object associated to a JORM class within this PMapper.
 void map(java.lang.Object conn, PClassMapping pcm)
          It registers a PClassMapping associated to a particular JORM class within this PMapper.
 void map(java.lang.Object conn, PClassMapping pcm, boolean loadmeta)
          It registers a PClassMapping associated to a particular JORM class within this PMapper.
 void map(PClassMapping pcm)
          It registers a PClassMapping associated to a particular JORM class within this PMapper.
 void removeMapperEventListener(PMapperListener listener)
          Removes the given mapper listener from this mapper.
 void scheduleEvent(java.util.EventObject e)
          Schedules an mapper-related event.
 void setDTDLocations(java.util.ArrayList dtdlocs)
          It assigns a set of locations where DTD files may be found in order to allow the mapper to parse ".pd" files for loading meta-information.
 void setJormConfigurator(JormConfigurator jormConfigurator)
           
 void setLogger(Logger logger)
          It assigns a logger to an component that wants to log things.
 void setLoggerFactory(LoggerFactory loggerfactory)
          It assigns a logger factory that allows the creation of new loggers.
 void setMapperName(java.lang.String mappername)
          It assigns the name of the mapper that is instanciated.
 void setPathsToPdFiles(PathExplorer paths)
          It assigns a set of paths to locations where jorm descriptor files may be found.
 void setPMapper(PMapper pm)
          Assigns a mapper to this schema manager.
 void setPrefetchCache(PrefetchCache pc)
          Assigns a prefetch cache to this mapper.
 void start()
          Starts this mapper.
 void stop()
          Stops this mapper.
 void unmap(java.lang.String classname)
          It unmaps a particular JORM class within this PMapper.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.jorm.api.PMapper
closeConnection, getConnection, getConnection, getConnection, getConnectionFactory, setConnectionFactory
 

Field Detail

logger

protected Logger logger
The logger associated with this mapper.


loggerFactory

protected LoggerFactory loggerFactory
The logger factory associated with this mapper.

Constructor Detail

Mapper

public Mapper()
       throws PException
It builds a JormConfigurator with the default JormCompilerParameter and JormCompilerParameter.


Mapper

public Mapper(JormConfigurator c)
Method Detail

setJormConfigurator

public void setJormConfigurator(JormConfigurator jormConfigurator)

getJormConfigurator

public JormConfigurator getJormConfigurator()

scheduleEvent

public void scheduleEvent(java.util.EventObject e)
                   throws PException
Schedules an mapper-related event.

Specified by:
scheduleEvent in interface PMappingCallback
Parameters:
e - The event to be scheduled.
Throws:
PException - Cannot schedule this event.

getMapperName

public java.lang.String getMapperName()
The name yielded by this method defines what kind of PMapper is used on a particular DS.

Specified by:
getMapperName in interface PMapper
Returns:
The name defining the PMapper kind.

getPMappingStructuresManager

public PMappingStructuresManager getPMappingStructuresManager()
Retrieves the PMappingStructuresManager associated with this mapper.

Specified by:
getPMappingStructuresManager in interface PMapper
Returns:
The associated PMappingStructuresManager.

lookup

public PClassMapping lookup(java.lang.String classname)
It looks for the PClassMapping object associated to a JORM class within this PMapper.

Specified by:
lookup in interface PMapper
Returns:
The PClassMapping that maps the corresponding class, or null if none exists

map

public void map(PClassMapping pcm)
         throws PException
It registers a PClassMapping associated to a particular JORM class within this PMapper. It initializes the storage structures if necessary. It previously removes them if the "dsrem" flag is set. If the mapper is ready to manage the meta-information, it is loaded for this JORM class.

Specified by:
map in interface PMapper
Parameters:
pcm - The class mapping to add to this mapper.
Throws:
PExceptionIO - It is raised when an I/O problem occurs within the underlying DS.
PExceptionProtocol - It is raised when a problem occurs during initialisation of the class mapping.
PExceptionTyping - It is raised when a typing problem occurs during initialisation of the class mapping.
PException

map

public void map(java.lang.Object conn,
                PClassMapping pcm)
         throws PException
It registers a PClassMapping associated to a particular JORM class within this PMapper. It initializes the storage structures if necessary. It previously removes them if the "dsrem" flag is set. If the mapper is ready to manage the meta-information, it is loaded for this JORM class.

Specified by:
map in interface PMapper
Parameters:
conn - The connection to access to the underlying DS.
pcm - The class mapping to add to this mapper.
Throws:
PExceptionIO - It is raised when an I/O problem occurs within the underlying DS.
PExceptionProtocol - It is raised when a problem occurs during initialisation of the class mapping.
PExceptionTyping - It is raised when a typing problem occurs during initialisation of the class mapping.
PException

map

public void map(java.lang.Object conn,
                PClassMapping pcm,
                boolean loadmeta)
         throws PException
It registers a PClassMapping associated to a particular JORM class within this PMapper. It initializes the storage structures if necessary. It previously removes them if the "dsrem" flag is set. It also loads the meta-information related to this class if the "loadmeta" flag is set.

Specified by:
map in interface PMapper
Parameters:
conn - The connection to access to the underlying DS.
pcm - The class mapping to add to this mapper.
loadmeta - It specifies that meta-information should be loaded for this class to map.
Throws:
PExceptionIO - It is raised when an I/O problem occurs within the underlying DS.
PExceptionProtocol - It is raised when a problem occurs during initialisation of the class mapping.
PExceptionTyping - It is raised when a typing problem occurs during initialisation of the class mapping.
PException

setMapperName

public void setMapperName(java.lang.String mappername)
It assigns the name of the mapper that is instanciated. It is mandatory to assign it at mapper initialization as the load of meta-information depends on it.

Specified by:
setMapperName in interface PMapper
Parameters:
mappername - The name of the maping as defined within the XML JORM definition files.

setDTDLocations

public void setDTDLocations(java.util.ArrayList dtdlocs)
It assigns a set of locations where DTD files may be found in order to allow the mapper to parse ".pd" files for loading meta-information.

Specified by:
setDTDLocations in interface PMapper

setPathsToPdFiles

public void setPathsToPdFiles(PathExplorer paths)
It assigns a set of paths to locations where jorm descriptor files may be found.

Specified by:
setPathsToPdFiles in interface PMapper
Parameters:
paths - The potential location where to find ".pd" files in order to allow the mapper to load meta-information if needed.

createGenClassMapping

public PClassMapping createGenClassMapping()
                                    throws PException
Description copied from interface: PMapper
Creates a new PClassMapping for a gen class. It instanciates the relevant class wrt the type of mapper.

Specified by:
createGenClassMapping in interface PMapper
Returns:
Throws:
PException

getMetaInfoManager

public Manager getMetaInfoManager()
Description copied from interface: PMapper
It retrieves a meta-information Manager that may used by a parser in order to load the meta-information associated to JORM classes mapped within this PMapper.

Specified by:
getMetaInfoManager in interface PMapper
Returns:
The meta-information Manager assigned.

getPTypeSpace

public PTypeSpace getPTypeSpace()
It returns a PTypeSpace that may be used to create PType associated to JORM classes mapped within this PMapper.

Specified by:
getPTypeSpace in interface PMapper

start

public void start()
           throws PException
Starts this mapper.

Specified by:
start in interface PMapper
Throws:
PException

stop

public void stop()
          throws PException
Stops this mapper.

Specified by:
stop in interface PMapper
Throws:
PException

unmap

public void unmap(java.lang.String classname)
           throws PException
It unmaps a particular JORM class within this PMapper.

Specified by:
unmap in interface PMapper
Parameters:
classname - The name of the JORM class to be unmapped.
Throws:
PException

setPrefetchCache

public void setPrefetchCache(PrefetchCache pc)
                      throws PException
Assigns a prefetch cache to this mapper. It is optional.

Specified by:
setPrefetchCache in interface PMapper
Throws:
PExceptionProtocol - It is raised if a prefetch cache has already been assigned.
PException

getPrefetchCache

public PrefetchCache getPrefetchCache()
Returns the prefetch cache associated to this mapper. It can be null.

Specified by:
getPrefetchCache in interface PMapper

clean

public void clean()
           throws PException
Description copied from interface: PMapper
Clean the mapper: forget all classes previously mapped.

Specified by:
clean in interface PMapper
Throws:
PException

getPMapCluster

public PMapCluster getPMapCluster(java.lang.String jcname)
                           throws PException
Asks for the map cluster associated with a JORM class.

Specified by:
getPMapCluster in interface PMappingStructuresManager
Parameters:
jcname - The JORM class name.
Returns:
The relevant map cluster.
Throws:
PException - This class has not been mapped.

getPMapClusters

public java.util.Collection getPMapClusters()
Asks for all the map clusters defined within this mapper.

Specified by:
getPMapClusters in interface PMappingStructuresManager
Returns:
The Iterator over the collection of map clusters.

addDependency

public void addDependency(java.lang.String jcname1,
                          java.lang.String jcname2)
                   throws PException
Description copied from interface: PMappingStructuresManager
Adds a dependency between a defined class and another class.

Specified by:
addDependency in interface PMappingStructuresManager
Parameters:
jcname1 - is the class name of a defined class
jcname2 - is the name of the class which the first depends on it.
Throws:
PException

declareClass

public void declareClass(java.lang.String jcname)
Description copied from interface: PMappingStructuresManager
Declares a persistent class. This call crerates the PMapCluster.

Specified by:
declareClass in interface PMappingStructuresManager
Parameters:
jcname -

classDefined

public void classDefined(java.lang.String jcname)
                  throws PException
Description copied from interface: PMappingStructuresManager
Indicates that a jorm class is defined.

Specified by:
classDefined in interface PMappingStructuresManager
Parameters:
jcname - which is defined.
Throws:
PException

addMapperEventListener

public void addMapperEventListener(PMapperListener listener)
Adds the given mapper listener to this mapper. If it already exists, does nothing.

Specified by:
addMapperEventListener in interface PMapper
Parameters:
listener - The corresponding listener.

removeMapperEventListener

public void removeMapperEventListener(PMapperListener listener)
Removes the given mapper listener from this mapper. If it is not present among this list, does nothing.

Specified by:
removeMapperEventListener in interface PMapper
Parameters:
listener - The corresponding listener.

getMappedClasses

public java.lang.String[] getMappedClasses()
Specified by:
getMappedClasses in interface PMapper
Returns:
the array of the current mapped class. If the mapper is not started, an empty array is returned.

setPMapper

public void setPMapper(PMapper pm)
Assigns a mapper to this schema manager.

Specified by:
setPMapper in interface PMappingStructuresManager
Parameters:
pm - The concerned mapper.

clear

public void clear()
           throws PException
Description copied from interface: PMappingStructuresManager
Clean the mapping structure manager: forget all classes.

Specified by:
clear in interface PMappingStructuresManager
Throws:
PException

setLogger

public void setLogger(Logger logger)
It assigns a logger to an component that wants to log things.

Specified by:
setLogger in interface PMappingStructuresManager
Parameters:
logger - The logger object.

setLoggerFactory

public void setLoggerFactory(LoggerFactory loggerfactory)
It assigns a logger factory that allows the creation of new loggers.

Specified by:
setLoggerFactory in interface Loggable
Parameters:
loggerfactory - The LoggerFactory object to obtain new loggers.

getLogger

public Logger getLogger()
Description copied from interface: Loggable
Returns a logger to an component that wants to log things.

Specified by:
getLogger in interface Loggable

getLoggerFactory

public LoggerFactory getLoggerFactory()
Description copied from interface: Loggable
Returns a logger factory that allows the creation of new loggers.

Specified by:
getLoggerFactory in interface Loggable

cn2mn

public java.lang.String cn2mn(java.lang.String cn)
Description copied from interface: PMapper
Constructs a "mapped name" starting from a JORM class name. For example, "foo" class name produces ".foo", while "p1.p2.foo" produces "p1.p2..foo".

Specified by:
cn2mn in interface PMapper
Parameters:
cn - The JORM class name.

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()