* Sets the database options from a JDO database mapping file.
*
* @param databaseURL URL string for JDO database mapping file.
*/
public void setDatabase(final String databaseURL) throws DTXException {
Unmarshaller unm = new Unmarshaller(Database.class);
unm.setEntityResolver(new DTDResolver());
try {
_database = (Database) unm.unmarshal(
new InputSource(new URL(databaseURL).openStream()));
} catch (Exception except) {
throw new DTXException(except);
}
if (_database.getEngine() == null) {
_factory = PersistenceFactoryRegistry.getPersistenceFactory("generic");
} else {
_factory = PersistenceFactoryRegistry.getPersistenceFactory(_database.getEngine());
}
if (_factory == null) {
throw new DTXException("no engine");
}
// Class mappings
_classMappings = new HashMap();
// Load the specificed mapping source
Unmarshaller munm = new Unmarshaller(MappingRoot.class);
Mapping[] mappings = _database.getMapping();
for (int i = 0; i < mappings.length; ++i) {
try {
URL mappingURL = new URL(new URL(databaseURL), mappings[i].getHref());
MappingRoot mr = (MappingRoot) munm.unmarshal(new InputSource(mappingURL.openStream()));
ClassMapping[] classMaps = mr.getClassMapping();
for (int j = 0; j < classMaps.length; j++) {
_classMappings.put(classMaps[j].getName(), classMaps[j]);
}