01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.core.impl;
10:
11: import com.completex.objective.components.persistency.Link;
12:
13: import java.util.Iterator;
14: import java.util.Map;
15:
16: /**
17: * Link Iterator. Useage example:
18: * <PRE>
19: * for (LinkIterator it = parent.linkIterator(); it.hasNext();) {
20: * Link link = it.nextLink();
21: * String linkPath = path + Link.SEP + link.getName();
22: * Object result = link.getResult();
23: * ....
24: * }
25: *
26: * </PRE>
27: *
28: *
29: * @author Gennady Krizhevsky
30: */
31: public class LinkIterator {
32:
33: public static final LinkIterator NULL_LINK_ITERATOR = new LinkIterator(
34: null);
35:
36: private Iterator iterator;
37: private Link link;
38: private Map children;
39:
40: public LinkIterator(Map children) {
41: if (children != null) {
42: this .children = children;
43: iterator = children.entrySet().iterator();
44: }
45: }
46:
47: public boolean hasNext() {
48: return iterator != null && iterator.hasNext();
49: }
50:
51: public Link nextLink() {
52: Map.Entry entry = (Map.Entry) iterator.next();
53: link = (Link) entry.getValue();
54: return link;
55: }
56:
57: // public String getName() {
58: // LinkComp linkComp = new LinkComp(name, link);
59: // if (!linkComp.namesEqual()) {
60: // throw new Error("!linkComp.namesEqual(): " + linkComp);
61: // }
62: // return name;
63: // }
64:
65: public Link getLink() {
66: return link;
67: }
68:
69: public String toString() {
70: return super .toString() + children;
71: }
72:
73: // private class LinkComp {
74: // String name;
75: // String linkName;
76: //
77: // public LinkComp(String name, Link link) {
78: // this.name = name;
79: // this.linkName = link == null ? null : link.getName();
80: // }
81: //
82: // public boolean namesEqual() {
83: //
84: // if (linkName != null ? !linkName.equals(name) : name != null) return false;
85: // if (name != null ? !name.equals(linkName) : linkName != null) return false;
86: //
87: // return true;
88: // }
89: //
90: // public String toString() {
91: // return "name = " + name
92: // + "; linkName = " + linkName;
93: // }
94: // }
95:
96: }
|