*/
private Collection<ItemState> getTransientStates()
throws InvalidItemStateException, RepositoryException {
// list of transient states that should be persisted
ArrayList<ItemState> dirty = new ArrayList<ItemState>();
ItemState transientState;
if (isNode()) {
// build list of 'new' or 'modified' descendants
Iterator<ItemState> iter = stateMgr.getDescendantTransientItemStates((NodeId) id);
while (iter.hasNext()) {
transientState = iter.next();
// fail-fast test: check status of transient state
switch (transientState.getStatus()) {
case ItemState.STATUS_NEW:
case ItemState.STATUS_EXISTING_MODIFIED:
// add modified state to the list
dirty.add(transientState);
break;
case ItemState.STATUS_STALE_MODIFIED:
throw new InvalidItemStateException(
"Item cannot be saved because it has been "
+ "modified externally: " + this);
case ItemState.STATUS_STALE_DESTROYED:
throw new InvalidItemStateException(
"Item cannot be saved because it has been "
+ "deleted externally: " + this);
case ItemState.STATUS_UNDEFINED:
throw new InvalidItemStateException(
"Item cannot be saved; it seems to have been "
+ "removed externally: " + this);
default:
log.warn("Unexpected item state status: "
+ transientState.getStatus() + " of " + this);
// ignore
break;
}
}
}
// fail-fast test: check status of this item's state
if (isTransient()) {
final ItemState state = getItemState();
switch (state.getStatus()) {
case ItemState.STATUS_EXISTING_MODIFIED:
// add this item's state to the list
dirty.add(state);
break;
case ItemState.STATUS_NEW:
throw new RepositoryException(
"Cannot save a new item: " + this);
case ItemState.STATUS_STALE_MODIFIED:
throw new InvalidItemStateException(
"Item cannot be saved because it has been"
+ " modified externally: " + this);
case ItemState.STATUS_STALE_DESTROYED:
throw new InvalidItemStateException(
"Item cannot be saved because it has been"
+ " deleted externally:" + this);
case ItemState.STATUS_UNDEFINED:
throw new InvalidItemStateException(
"Item cannot be saved; it seems to have been"
+ " removed externally: " + this);
default:
log.warn("Unexpected item state status:"
+ state.getStatus() + " of " + this);
// ignore
break;
}
}