Home » Castor-1.3-src » org.exolab.castor » mapping » [javadoc | source]
org.exolab.castor.mapping
public final class: Mapping [javadoc | source]
java.lang.Object
   org.exolab.castor.mapping.Mapping
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 );
Constructor:
 public Mapping() 
 public Mapping(ClassLoader loader) 
    Constructs a new mapping.
    Parameters:
    loader - The class loader to use, null for the default
Method from org.exolab.castor.mapping.Mapping Summary:
getClassLoader,   getMappingSources,   getRoot,   loadMapping,   loadMapping,   loadMapping,   loadMapping,   loadMapping,   loadMapping,   markAsProcessed,   processed,   setBaseURL,   setEntityResolver
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.exolab.castor.mapping.Mapping Detail:
 public 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.
 public List getMappingSources() throws MappingException 
    Get list of mapping sources to resolve.
 public MappingRoot getRoot() 
    Get the loaded mapping.
 public  void loadMapping(String url) throws IOException, MappingException 
    Loads 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.
 public  void loadMapping(URL url) throws IOException, MappingException 
    Loads the mapping from the specified URL with type defaults to 'CastorXmlMapping'.
 public  void loadMapping(InputSource source) 
    Loads the mapping from the specified input source with type defaults to 'CastorXmlMapping'.
 public  void loadMapping(String url,
    String type) 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.
 public  void loadMapping(URL url,
    String type) throws IOException, MappingException 
    Loads the mapping from the specified URL.
 public  void loadMapping(InputSource source,
    String type) 
    Loads the mapping from the specified input source.
 public  void markAsProcessed(Object id) 
    Marks the given mapping as having been processed.
 public boolean processed(Object id) 
    Returns true if the given systemID or stream has been marked as processed.
 public  void 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.
 public  void 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.