[12188] | 1 | package org.greenstone.gsdl3.gs3build.schema;
|
---|
| 2 |
|
---|
| 3 | import org.w3c.dom.Element;
|
---|
| 4 | import org.w3c.dom.Node;
|
---|
| 5 | import org.w3c.dom.NodeList;
|
---|
| 6 |
|
---|
| 7 | import java.util.List;
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 |
|
---|
| 10 | public class SchemaComplexType implements SchemaType
|
---|
| 11 | {
|
---|
| 12 | public String name;
|
---|
| 13 | public List children;
|
---|
| 14 |
|
---|
| 15 | public SchemaComplexType(Element element) throws SchemaException
|
---|
| 16 | {
|
---|
| 17 | this.name = element.getAttribute("name");
|
---|
| 18 | if (name == null)
|
---|
| 19 | { throw new SchemaException("Type defined without name");
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | this.children = new ArrayList();
|
---|
| 23 |
|
---|
| 24 | NodeList childNodes = element.getChildNodes();
|
---|
| 25 | for (int i = 0; i < childNodes.getLength(); i ++) {
|
---|
| 26 | Node node = childNodes.item(i);
|
---|
| 27 |
|
---|
| 28 | if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
|
---|
| 29 | String nodeName = node.getNodeName();
|
---|
| 30 |
|
---|
| 31 | if (nodeName == null) {
|
---|
| 32 | continue;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | nodeName = SchemaNode.getElementName(nodeName);
|
---|
| 36 | // a simple-based type
|
---|
| 37 | if (node.getNodeName().equals("simpleContent")) {
|
---|
| 38 | // we're really just a simple type with attributes - nothing more to do
|
---|
| 39 | }
|
---|
| 40 | // a complex-based type
|
---|
| 41 | else if (node.getNodeName().equals("complexContent")) {
|
---|
| 42 | // we just contain elements, no text
|
---|
| 43 | }
|
---|
| 44 | // the following pretty much speak for themselves
|
---|
| 45 | else {
|
---|
| 46 | try {
|
---|
| 47 | Object child = SchemaNodeFactory.makeNode((Element) node);
|
---|
| 48 | if (child != null) {
|
---|
| 49 | this.children.add(child);
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 | catch (SchemaException ex)
|
---|
| 53 | {
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | SchemaTypeMap.theMap.addType(this);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public String getName()
|
---|
| 63 | { return this.name;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|