Package org.exolab.castor.mapping
Class Mapping
- java.lang.Object
-
- org.exolab.castor.mapping.Mapping
-
public final class Mapping extends java.lang.ObjectUtility 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(java.lang.String)orsetEntityResolver(org.xml.sax.EntityResolver).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 );
- Version:
- $Revision: 7951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
- Author:
- Assaf Arkin, Ralf Joachim
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoadergetClassLoader()Returns the class loader used by this mapping object.java.util.ListgetMappingSources()Get list of mapping sources to resolve.MappingRootgetRoot()Get the loaded mapping.voidloadMapping(java.lang.String url)Loads the mapping from the specified URL with type defaults to 'CastorXmlMapping'.voidloadMapping(java.lang.String url, java.lang.String type)Loads the mapping from the specified URL.voidloadMapping(java.net.URL url)Loads the mapping from the specified URL with type defaults to 'CastorXmlMapping'.voidloadMapping(java.net.URL url, java.lang.String type)Loads the mapping from the specified URL.voidloadMapping(org.xml.sax.InputSource source)Loads the mapping from the specified input source with type defaults to 'CastorXmlMapping'.voidloadMapping(org.xml.sax.InputSource source, java.lang.String type)Loads the mapping from the specified input source.voidmarkAsProcessed(java.lang.Object id)Marks the given mapping as having been processed.booleanprocessed(java.lang.Object id)Returns true if the given systemID or stream has been marked as processed.voidsetBaseURL(java.lang.String url)Sets the base URL for the mapping and related files.voidsetEntityResolver(org.xml.sax.EntityResolver resolver)Sets the entity resolver.
-
-
-
Method Detail
-
getMappingSources
public java.util.List getMappingSources() throws MappingExceptionGet list of mapping sources to resolve.- Returns:
- List of mapping sources to resolve.
- Throws:
MappingException- If no mapping source has been loaded previously.
-
markAsProcessed
public void markAsProcessed(java.lang.Object id)
Marks the given mapping as having been processed.- Parameters:
id- systemID or stream to identify the mapping to mark.
-
processed
public boolean processed(java.lang.Object id)
Returns true if the given systemID or stream has been marked as processed.- Parameters:
id- systemID or stream to check for being marked as processed.- Returns:
- true if the given systemID or stream has been marked as processed.
-
getRoot
public MappingRoot getRoot()
Get the loaded mapping.- Returns:
- The loaded mapping.
-
getClassLoader
public java.lang.ClassLoader 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)
-
setEntityResolver
public void setEntityResolver(org.xml.sax.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
-
setBaseURL
public void setBaseURL(java.lang.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
-
loadMapping
public void loadMapping(java.lang.String url) throws java.io.IOException, MappingExceptionLoads the mapping from the specified URL with type defaults to 'CastorXmlMapping'. 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.- Throws:
java.io.IOException- An error occured when reading the mapping file.MappingException- The mapping file is invalid.
-
loadMapping
public void loadMapping(java.lang.String url, java.lang.String type) throws java.io.IOException, MappingExceptionLoads 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.type- The source type.- Throws:
java.io.IOException- An error occured when reading the mapping file.MappingException- The mapping file is invalid.
-
loadMapping
public void loadMapping(java.net.URL url) throws java.io.IOException, MappingExceptionLoads the mapping from the specified URL with type defaults to 'CastorXmlMapping'.- Parameters:
url- The URL of the mapping file.- Throws:
java.io.IOException- An error occured when reading the mapping file.MappingException- The mapping file is invalid.
-
loadMapping
public void loadMapping(java.net.URL url, java.lang.String type) throws java.io.IOException, MappingExceptionLoads the mapping from the specified URL.- Parameters:
url- The URL of the mapping file.type- The source type.- Throws:
java.io.IOException- An error occured when reading the mapping file.MappingException- The mapping file is invalid.
-
loadMapping
public void loadMapping(org.xml.sax.InputSource source)
Loads the mapping from the specified input source with type defaults to 'CastorXmlMapping'.- Parameters:
source- The input source.
-
loadMapping
public void loadMapping(org.xml.sax.InputSource source, java.lang.String type)Loads the mapping from the specified input source.- Parameters:
source- The input source.type- The source type.
-
-