* method has been called on the <code>Collection</code><br />
*/
public void storeResource(Resource res) throws XMLDBException {
if (!(res instanceof XMLResource)) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"Only XML resources supported");
}
if (res.getContent() == null) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"no resource data");
}
checkOpen();
try {
String name = "";
Node content = ((XMLResourceImpl) res).getContentAsDOM();
if (content != null && content instanceof Document) {
if (res.getId() != null) {
col.insertDocument(res.getId(),
(Document) content);
}
else {
name = col.insertDocument((Document) content).toString();
((XMLResourceImpl) res).setId(name);
}
}
else {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
"A resource must be a document in order to be stored.");
}
} catch (Exception e) {
throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
}
}