* @throws MappingException The mapping file is invalid
*/
private void loadMappingInternal( InputSource source )
throws IOException, MappingException
{
MappingRoot loaded;
Unmarshaller unm;
Enumeration enumeration;
// Clear all the cached resolvers, so they can be reconstructed a
// second time based on the new mappings loaded
_resolvers.clear();
//check that the mapping has already been processed
if ((source.getSystemId()!=null) && _state.processed(source.getSystemId()) ) {
//-- already processed...just return
return;
}
try {
if ( _mapping == null ) {
_mapping = new MappingRoot();
_idResolver.setMapping(_mapping);
}
//mark the mapping as being processed
if (source.getSystemId() != null)
_state.markAsProcessed(source.getSystemId(), _mapping);
// Load the specificed mapping source
unm = new Unmarshaller( MappingRoot.class );
unm.setEntityResolver( _resolver );
if ( _logWriter != null )
unm.setLogWriter( _logWriter );
unm.setClassLoader( Mapping.class.getClassLoader() );
unm.setIDResolver(_idResolver);
unm.setUnmarshalListener(new IncludeListener());
loaded = (MappingRoot) unm.unmarshal( source );
// Load all the included mapping by reference
//-- note: this is just for processing any
//-- includes which may have previously failed
//-- using the IncludeListener...and to
//-- report any potential errors.
Enumeration includes = loaded.enumerateInclude();
while ( includes.hasMoreElements() ) {
Include include = (Include) includes.nextElement();
if (!_state.processed( include.getHref() )) {
try {
loadMappingInternal( include.getHref() );
}
catch ( Exception except ) {
throw new MappingException( except );
}
}
}
// gather "class" tags
enumeration = loaded.enumerateClassMapping();
while ( enumeration.hasMoreElements() )
_mapping.addClassMapping( (ClassMapping) enumeration.nextElement() );
// gather "key-generator" tags
enumeration = loaded.enumerateKeyGeneratorDef();
while ( enumeration.hasMoreElements() ) {
_mapping.addKeyGeneratorDef( (KeyGeneratorDef) enumeration.nextElement() );
}
} catch ( Exception except ) {
throw new MappingException( except );