01: package org.geotools.xml.impl;
02:
03: import javax.xml.namespace.QName;
04:
05: import org.eclipse.xsd.XSDNamedComponent;
06: import org.geotools.xml.Binding;
07: import org.geotools.xml.ComplexBinding;
08:
09: /**
10: * Gets children from a parent object, visiting bindings in teh
11: * hierachy until one is found.
12: *
13: * @author Justin Deoliveira, The Open Planning Project
14: *
15: */
16: public class GetPropertyExecutor implements BindingWalker.Visitor {
17:
18: /** parent + child objects **/
19: Object parent;
20: Object child;
21:
22: /** declaration (element or attribute) + qualified name**/
23: QName name;
24:
25: public GetPropertyExecutor(Object parent, XSDNamedComponent content) {
26: this .parent = parent;
27:
28: name = new QName(content.getTargetNamespace(), content
29: .getName());
30: }
31:
32: public Object getChildObject() {
33: return child;
34: }
35:
36: public void visit(Binding binding) {
37: //TODO: visit should return a boolena to signify wether to continue
38: if (child != null)
39: return;
40:
41: if (binding instanceof ComplexBinding) {
42: ComplexBinding complex = (ComplexBinding) binding;
43:
44: try {
45: child = complex.getProperty(parent, name);
46: } catch (Exception e) {
47: throw new RuntimeException("Failed to get property: "
48: + name, e);
49: }
50: }
51: }
52:
53: }
|