KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > repository > MockChildBeanFetcher


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.repository;
5
6 import org.apache.xmlbeans.XmlObject;
7
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10
11 /**
12  * A mock {@link ChildBeanFetcher}, for use in tests.
13  */

14 public class MockChildBeanFetcher implements ChildBeanFetcher {
15
16   private int numGetChilds;
17   private XmlObject[] returnedChildren;
18   private int returnedChildrenPos;
19   private List JavaDoc lastParents;
20
21   public MockChildBeanFetcher() {
22     this.returnedChildren = new XmlObject[] { null };
23     this.lastParents = new ArrayList JavaDoc();
24
25     reset();
26   }
27
28   public void reset() {
29     this.numGetChilds = 0;
30     this.returnedChildrenPos = 0;
31     this.lastParents.clear();
32   }
33
34   public XmlObject getChild(XmlObject parent) {
35     ++this.numGetChilds;
36     this.lastParents.add(parent);
37     XmlObject out = this.returnedChildren[this.returnedChildrenPos++];
38     if (this.returnedChildrenPos >= this.returnedChildren.length) this.returnedChildrenPos = 0;
39     return out;
40   }
41
42   public XmlObject getLastParent() {
43     return (XmlObject) this.lastParents.get(this.lastParents.size() - 1);
44   }
45   
46   public XmlObject[] getLastParents() {
47     return (XmlObject[]) this.lastParents.toArray(new XmlObject[this.lastParents.size()]);
48   }
49
50   public int getNumGetChilds() {
51     return numGetChilds;
52   }
53
54   public void setReturnedChild(XmlObject returnedChild) {
55     setReturnedChildren(new XmlObject[] { returnedChild });
56   }
57
58   public void setReturnedChildren(XmlObject[] returnedChildren) {
59     this.returnedChildren = returnedChildren;
60   }
61
62 }
63
Popular Tags