01: /*
02: * Created on 14-Feb-2006
03: */
04: package uk.org.ponder.rsf.componentprocessor;
05:
06: import java.util.HashMap;
07: import java.util.Iterator;
08: import java.util.Map;
09:
10: import uk.org.ponder.beanutil.IterableBeanLocator;
11: import uk.org.ponder.rsf.components.UIComponent;
12: import uk.org.ponder.saxalizer.MethodAnalyser;
13: import uk.org.ponder.saxalizer.SAXAccessMethod;
14: import uk.org.ponder.saxalizer.SAXalizerMappingContext;
15:
16: /** Constructs an iteration over any children of an "composite component"
17: * that are also components, by means of reflection.
18: * @author Antranig Basman (antranig@caret.cam.ac.uk)
19: *
20: */
21:
22: public class ComponentChildIterator implements IterableBeanLocator {
23: private Map children = new HashMap();
24:
25: public ComponentChildIterator(UIComponent parent,
26: SAXalizerMappingContext mappingcontext) {
27: MethodAnalyser ma = mappingcontext.getAnalyser(parent
28: .getClass());
29: for (int i = 0; i < ma.allgetters.length; ++i) {
30: SAXAccessMethod sam = ma.allgetters[i];
31: if (sam.tagname.equals("parent"))
32: continue;
33: if (UIComponent.class.isAssignableFrom(sam
34: .getDeclaredType())) {
35: Object child = sam.getChildObject(parent);
36: if (child != null) {
37: children.put(sam.tagname, child);
38: }
39: } else if (sam.getDeclaredType() == Object.class) {
40: Object child = sam.getChildObject(parent);
41: if (child instanceof UIComponent) {
42: children.put(sam.tagname, child);
43: }
44: }
45: }
46: }
47:
48: public Iterator iterator() {
49: return children.keySet().iterator();
50: }
51:
52: public Object locateBean(String path) {
53: return children.get(path);
54: }
55: }
|