01: /**
02: *
03: */package org.geotools.xml.handlers;
04:
05: import java.net.URI;
06:
07: import org.geotools.xml.schema.ComplexType;
08: import org.geotools.xml.schema.Element;
09: import org.geotools.xml.schema.ElementGrouping;
10: import org.geotools.xml.schema.Type;
11:
12: /**
13: * Utility class with methods to help implement Element and Type Handlers
14: * @author Jesse
15: */
16: public class XMLTypeHelper {
17:
18: public static Element findChildElement(Type type, String localName,
19: URI namespaceURI) {
20: if (type instanceof ComplexType) {
21: ComplexType complexType = (ComplexType) type;
22: ElementGrouping child = complexType.getChild();
23: if (child != null) {
24: Element found = child.findChildElement(localName,
25: namespaceURI);
26: if (found != null)
27: return found;
28: }
29: Element[] children = complexType.getChildElements();
30: if (children == null || children.length == 0)
31: return null;
32: for (int i = 0; i < children.length; i++) {
33: Element element = children[i];
34: if (localName.equals(element.getName())
35: && namespaceURI.equals(element.getNamespace()))
36: return element;
37: }
38: if (complexType.getParent() != null) {
39: Type parent = complexType.getParent();
40: return findChildElement((ComplexType) parent,
41: localName, namespaceURI);
42: }
43: } else {
44: return type.findChildElement(localName);
45: }
46: return null;
47: }
48:
49: }
|