01: package org.drools.repository;
02:
03: import java.util.Iterator;
04:
05: import javax.jcr.Node;
06: import javax.jcr.NodeIterator;
07:
08: /**
09: * This iterates over nodes and produces RuleItem's.
10: * Also allows "skipping" of results to jump to certain items,
11: * as per JCRs "skip".
12: *
13: * JCR iterators are/can be lazy, so this makes the most of it for large
14: * numbers of assets.
15: *
16: * @author Michael Neale
17: */
18: public class AssetItemIterator implements Iterator {
19:
20: private NodeIterator it;
21: private RulesRepository rulesRepository;
22:
23: public AssetItemIterator(NodeIterator nodes, RulesRepository repo) {
24: this .it = nodes;
25: this .rulesRepository = repo;
26: }
27:
28: public boolean hasNext() {
29: return it.hasNext();
30: }
31:
32: public Object next() {
33: return new AssetItem(rulesRepository, (Node) it.next());
34: }
35:
36: public void remove() {
37: throw new UnsupportedOperationException(
38: "You can't remove a rule this way.");
39: }
40:
41: /**
42: * @param i The number of rules to skip.
43: */
44: public void skip(int i) {
45: it.skip(i);
46: }
47:
48: }
|