01: package com.xoetrope.data.pojo;
02:
03: import java.util.Collection;
04: import java.util.Iterator;
05:
06: /**
07: * Collection iterator model
08: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
09: * the GNU Public License (GPL), please see license.txt for more details. If
10: * you make commercial use of this software you must purchase a commercial
11: * license from Xoetrope.</p>
12: */
13: public class XPojoIteratorEx extends XPojoModelEx {
14: protected Collection collection;
15: protected Iterator iterator;
16:
17: /**
18: * Creates a new instance of <code>XPojoIteratorEx</code>
19: * @param ds data source
20: * @param c Collection which iterator is wrapped by this node
21: */
22: public XPojoIteratorEx(XPojoDataSourceEx ds, Collection c,
23: XPojoModelEx finder) {
24: super (finder, null, ds);
25: collection = c;
26: iterator = collection.iterator();
27: setPojo(null);
28: first();
29: }
30:
31: /**
32: * Incdicates whether the iterator has more elements
33: * @return true if the iterator has more elements,
34: * false otherwise.
35: */
36: public boolean hasNext() {
37: return iterator.hasNext();
38: }
39:
40: public Class getPojoClass() {
41: return null;
42: }
43:
44: /**
45: * Returns the first object from the underlying collection and
46: * resets the iteration index to 0.
47: * @return first element of the collection
48: */
49: public Object first() {
50: if (collection != null) {
51: iterator = collection.iterator();
52: setPojo(iterator.hasNext() ? iterator.next() : null);
53: adapter = (pojo != null ? dataSource.getAdapter(pojo
54: .getClass()) : null);
55: }
56: return pojo;
57: }
58:
59: /**
60: * Gets this node's visualiser tree caption.
61: * @return the caption
62: */
63: public String getCaption() {
64: String caption = "iterator: ";
65: setCaption(caption);
66: return caption;
67: }
68:
69: /**
70: * Gets the current element adapter of
71: * this iteration
72: * @return the adapter
73: */
74: public XPojoAdapterEx getAdapter() {
75: return (XPojoAdapterEx) adapter;
76: }
77:
78: /**
79: * Gets the runtime binding path of this node
80: * @return binding path
81: */
82: public String getBindingPath() {
83: String path = ((XPojoModelVis) getParent()).getBindingPath();
84: return (path + "/iterator");
85: }
86:
87: }
|