Classes | Public Member Functions | Static Public Attributes

org.exolab.castor.mapping.Mapping Class Reference

List of all members.

Classes

class  ClassMappingResolver
class  EngineMapping
class  IncludeListener
class  MappingState

Public Member Functions

 Mapping (ClassLoader loader)
 Mapping ()
MappingResolver getResolver (EngineMapping engine) throws MappingException
synchronized MappingResolver getResolver (EngineMapping engine, Object param) throws MappingException
MappingRoot getRoot ()
void setAllowRedefinitions (boolean allow)
void setLogWriter (PrintWriter logWriter)
void setEntityResolver (EntityResolver resolver)
void setBaseURL (String url)
ClassLoader getClassLoader ()
void loadMapping (String url) throws IOException, MappingException
void loadMapping (URL url) throws IOException, MappingException
void loadMapping (InputSource source) throws IOException, MappingException

Static Public Attributes

static final EngineMapping JDO
static final EngineMapping DAX
static final EngineMapping XML

Detailed Description

Utility class for loading mapping files and providing them to the XML marshaller, JDO engine etc. The mapping file can be loaded from a URL, input stream or SAX InputSource.

Multiple mapping files can be loaded with the same Mapping object. When loading master mapping files that include other mapping files it might be convenient to use setBaseURL or setEntityResolver.

If the desired class loader is different than the one used by Castor (e.g. if Castor is installed as a Java extension), the Mapping object can be constructed with the proper class loader.

The following example loads two mapping files:

 Mapping mapping;
 mapping = new Mapping( getClass().getClassLoader() );
 mapping.loadMapping( "mapping.xml" );
 mapping.loadMapping( url );
 
Author:
Assaf Arkin
Version:
Revision:
1.8
Date:
2004/12/17 21:56:04

Constructor & Destructor Documentation

org.exolab.castor.mapping.Mapping.Mapping ( ClassLoader  loader  ) 

Constructs a new mapping.

Parameters:
loader The class loader to use, null for the default
org.exolab.castor.mapping.Mapping.Mapping (  ) 

Constructs a new mapping.


Member Function Documentation

ClassLoader org.exolab.castor.mapping.Mapping.getClassLoader (  ) 

Returns the class loader used by this mapping object. The returned class loaded may be the one passed in the constructor, the one used to load Castor, or in some 1.1 JVMs null.

Returns:
The class loader used by this mapping object (may be null)
MappingResolver org.exolab.castor.mapping.Mapping.getResolver ( EngineMapping  engine  )  throws MappingException

Returns a mapping resolver for the suitable engine. The engine's specific mapping loader is created and used to create engine specific descriptors, returning a suitable mapping resolver. The mapping resolver is cached in memory and returned in subsequent method calls.

Parameters:
engine The mapping engine
Returns:
A mapping resolver
Exceptions:
MappingException A mapping error occured preventing descriptors from being generated from the loaded mapping
See also:
JDO
XML
DAX
synchronized MappingResolver org.exolab.castor.mapping.Mapping.getResolver ( EngineMapping  engine,
Object  param 
) throws MappingException

Returns a mapping resolver for the suitable engine. The engine's specific mapping loader is created and used to create engine specific descriptors, returning a suitable mapping resolver. The mapping resolver is cached in memory and returned in subsequent method calls.

Parameters:
engine The mapping engine
param Arbitrary parameter that is to be passed to resolver.loadMapping()
Returns:
A mapping resolver
Exceptions:
MappingException A mapping error occured preventing descriptors from being generated from the loaded mapping
See also:
JDO
XML
DAX

References org.exolab.castor.mapping.loader.MappingLoader.loadMapping(), and org.exolab.castor.mapping.loader.MappingLoader.setAllowRedefinitions().

MappingRoot org.exolab.castor.mapping.Mapping.getRoot (  ) 

Returns a MappingRoot which contains all loaded mapping classes and key generators definition.

void org.exolab.castor.mapping.Mapping.loadMapping ( InputSource  source  )  throws IOException, MappingException

Loads the mapping from the specified input source.

Parameters:
source The input source
Exceptions:
IOException An error occured when reading the mapping file
MappingException The mapping file is invalid
void org.exolab.castor.mapping.Mapping.loadMapping ( String  url  )  throws IOException, MappingException

Loads the mapping from the specified URL. If an entity resolver was specified, will use the entity resolver to resolve the URL. This method is also used to load mappings referenced from another mapping or configuration file.

Parameters:
url The URL of the mapping file
Exceptions:
IOException An error occured when reading the mapping file
MappingException The mapping file is invalid
void org.exolab.castor.mapping.Mapping.loadMapping ( URL  url  )  throws IOException, MappingException

Loads the mapping from the specified URL.

Parameters:
url The URL of the mapping file
Exceptions:
IOException An error occured when reading the mapping file
MappingException The mapping file is invalid
void org.exolab.castor.mapping.Mapping.setAllowRedefinitions ( boolean  allow  ) 

Enables or disables the ability to allow the redefinition of class mappings.

Parameters:
allow a boolean that when true enables redefinitions.
void org.exolab.castor.mapping.Mapping.setBaseURL ( String  url  ) 

Sets the base URL for the mapping and related files. If the base URL is known, files can be included using relative names. Any URL can be passed, if the URL can serve as a base URL it will be used. If url is an absolute path, it is converted to a file URL.

Parameters:
url The base URL
void org.exolab.castor.mapping.Mapping.setEntityResolver ( EntityResolver  resolver  ) 

Sets the entity resolver. The entity resolver can be used to resolve external entities and cached documents that are used from within mapping files.

Parameters:
resolver The entity resolver to use
void org.exolab.castor.mapping.Mapping.setLogWriter ( PrintWriter  logWriter  ) 

Sets the log writer. If not null, errors and other messages will be directed to that log writer.

Parameters:
logWriter The log writer to use

Member Data Documentation

final EngineMapping org.exolab.castor.mapping.Mapping.DAX [static]
Initial value:
        new EngineMapping( "dax", "org.exolab.castor.dax.engine.DAXMappingLoader" )

Use this object to obtain the mapping resolver for DAX from getResolver.

final EngineMapping org.exolab.castor.mapping.Mapping.JDO [static]
Initial value:
        new EngineMapping( "jdo", "org.exolab.castor.jdo.engine.JDOMappingLoader" )

Use this object to obtain the mapping resolver for JDO from getResolver.

final EngineMapping org.exolab.castor.mapping.Mapping.XML [static]
Initial value:
        new EngineMapping( "xml", "org.exolab.castor.xml.XMLMappingLoader" )

Use this object to obtain the mapping resolver for XML from getResolver.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties