use of org.apache.commons.collections.iterators.IteratorChain in project jackrabbit by apache.
the class CommandLine method getAllParameters.
/**
* @return all the parameters. i.e. args, options and flags.
*/
public Iterator getAllParameters() {
IteratorChain chain = new IteratorChain();
chain.addIterator(getArguments().values().iterator());
chain.addIterator(getOptions().values().iterator());
chain.addIterator(getFlags().values().iterator());
return chain;
}
use of org.apache.commons.collections.iterators.IteratorChain in project jackrabbit by apache.
the class TransientItemStateManager method getChangeLog.
/**
* Create the change log for the tree starting at <code>target</code>. This
* includes a check if the ChangeLog to be created is totally 'self-contained'
* and independent; items within the scope of this update operation (i.e.
* below the target) must not have dependencies outside of this tree (e.g.
* moving a node requires that the target node including both old and new
* parents are saved).
*
* @param target
* @param throwOnStale Throws InvalidItemStateException if either the given
* <code>ItemState</code> or any of its descendants is stale and the flag is true.
* @return
* @throws InvalidItemStateException if a stale <code>ItemState</code> is
* encountered while traversing the state hierarchy. The <code>changeLog</code>
* might have been populated with some transient item states. A client should
* therefore not reuse the <code>changeLog</code> if such an exception is thrown.
* @throws RepositoryException if <code>state</code> is a new item state.
*/
ChangeLog getChangeLog(ItemState target, boolean throwOnStale) throws InvalidItemStateException, ConstraintViolationException, RepositoryException {
// fail-fast test: check status of this item's state
if (target.getStatus() == Status.NEW) {
String msg = "Cannot save/revert an item with status NEW (" + target + ").";
log.debug(msg);
throw new RepositoryException(msg);
}
if (throwOnStale && Status.isStale(target.getStatus())) {
String msg = "Attempt to save/revert an item, that has been externally modified (" + target + ").";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
Set<Operation> ops = new LinkedHashSet<Operation>();
Set<ItemState> affectedStates = new LinkedHashSet<ItemState>();
HierarchyEntry he = target.getHierarchyEntry();
if (he.getParent() == null) {
// simplicity. collecting ops, states can be omitted.
if (throwOnStale && !staleStates.isEmpty()) {
String msg = "Cannot save changes: States has been modified externally.";
log.debug(msg);
throw new InvalidItemStateException(msg);
} else {
affectedStates.addAll(staleStates);
}
ops.addAll(operations);
affectedStates.addAll(addedStates);
affectedStates.addAll(modifiedStates);
affectedStates.addAll(removedStates);
} else {
// - check if there is a stale state in the scope (save only)
if (throwOnStale) {
for (ItemState state : staleStates) {
if (containedInTree(target, state)) {
String msg = "Cannot save changes: States has been modified externally.";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
}
}
// - collect all affected states within the scope of save/undo
Iterator[] its = new Iterator[] { addedStates.iterator(), removedStates.iterator(), modifiedStates.iterator() };
IteratorChain chain = new IteratorChain(its);
if (!throwOnStale) {
chain.addIterator(staleStates.iterator());
}
while (chain.hasNext()) {
ItemState state = (ItemState) chain.next();
if (containedInTree(target, state)) {
affectedStates.add(state);
}
}
// changelog.
for (Operation op : operations) {
Collection<ItemState> opStates = op.getAffectedItemStates();
for (ItemState state : opStates) {
if (affectedStates.contains(state)) {
// operation needs to be included
if (!affectedStates.containsAll(opStates)) {
// incomplete changelog: need to save a parent as well
String msg = "ChangeLog is not self contained.";
throw new ConstraintViolationException(msg);
}
// no violation: add operation an stop iteration over
// all affected states present in the operation.
ops.add(op);
break;
}
}
}
}
ChangeLog cl = new ChangeLog(target, ops, affectedStates);
return cl;
}
use of org.apache.commons.collections.iterators.IteratorChain in project jackrabbit by apache.
the class CommandLine method getRequiredParameters.
/**
* @return the required parameters. i.e. args, options and flags.
*/
public Iterator getRequiredParameters() {
IteratorChain chain = new IteratorChain();
chain.addIterator(getRequiredArguments().iterator());
chain.addIterator(getRequiredOptions().iterator());
return chain;
}
use of org.apache.commons.collections.iterators.IteratorChain in project jackrabbit by apache.
the class NodeEntryImpl method getAllChildEntries.
/**
* Returns an Iterator over all children entries, that currently are loaded
* with this NodeEntry. NOTE, that if the childNodeEntries have not been
* loaded yet, no attempt is made to do so.
*
* @param includeAttic
* @return iterator over all children entries, that currently are loaded
* with this NodeEntry
*/
private Iterator<HierarchyEntry> getAllChildEntries(boolean includeAttic) {
IteratorChain chain = new IteratorChain();
// attic
if (includeAttic) {
Collection<PropertyEntry> attic = propertiesInAttic.values();
chain.addIterator(new ArrayList<PropertyEntry>(attic).iterator());
}
// add props
synchronized (properties) {
Collection<PropertyEntry> props = properties.getPropertyEntries();
chain.addIterator(props.iterator());
}
// add childNodeEntries
synchronized (childNodeEntries) {
chain.addIterator(childNodeEntries.iterator());
}
return chain;
}
Aggregations