if (conf != null) {
return conf;
}
//XXX: locking required
DocumentAtExist document = null;
try {
document = collection.getDocument(broker, fileURL);
} catch (final PermissionDeniedException pde) {
throw new ConfigurationException(pde.getMessage(), pde);
}
if (document == null) {
if (broker.isReadOnly()) {
//database in read-only mode & there no configuration file,
//create in memory document & configuration
try {
final StringWriter writer = new StringWriter();
final SAXSerializer serializer = new SAXSerializer(writer, null);
serializer.startDocument();
serialize(instance, serializer);
serializer.endDocument();
final String data = writer.toString();
if (data == null || data.length() == 0) {
return null;
}
return parse(new ByteArrayInputStream(data.getBytes(UTF_8)));
} catch (final SAXException saxe) {
throw new ConfigurationException(saxe.getMessage(), saxe);
}
}
try {
document = save(instance, broker, collection, fileURL);
} catch (final IOException e) {
LOG.error(e.getMessage(), e);
//TODO : throw exception ? -pb
return null;
}
}
if (document == null) {
return null; //possibly on corrupted database, find better solution (recovery flag?)
}
final ElementAtExist confElement = (ElementAtExist) document.getDocumentElement();
if (confElement == null) {
return null; //possibly on corrupted database, find better solution (recovery flag?)
}
conf = new ConfigurationImpl(confElement);