1 package org.simantics.xml.sax;
\r
3 import org.w3._2001.xmlschema.AttributeGroup;
\r
4 import org.w3._2001.xmlschema.AttributeGroupRef;
\r
5 import org.w3._2001.xmlschema.ComplexType;
\r
6 import org.w3._2001.xmlschema.Element;
\r
7 import org.w3._2001.xmlschema.NamedAttributeGroup;
\r
8 import org.w3._2001.xmlschema.OpenAttrs;
\r
9 import org.w3._2001.xmlschema.SimpleType;
\r
11 public class SchemaObject {
\r
12 enum ObjectType{ELEMENT,COMPLEX_TYPE,SIMPLE_TYPE,ATTRIBUTE_GROUP};
\r
14 private SchemaObject parent;
\r
15 private ObjectType type;
\r
16 private OpenAttrs obj;
\r
18 public SchemaObject(Element element) {
\r
22 public SchemaObject(ComplexType complexType) {
\r
23 this(null, complexType);
\r
26 public SchemaObject(SimpleType simpleType) {
\r
27 this(null, simpleType);
\r
30 public SchemaObject(SchemaObject parent, Element element) {
\r
31 this.parent = parent;
\r
33 this.type = ObjectType.ELEMENT;
\r
36 public SchemaObject(SchemaObject parent, ComplexType complexType) {
\r
37 this.parent = parent;
\r
38 this.obj = complexType;
\r
39 this.type = ObjectType.COMPLEX_TYPE;
\r
42 public SchemaObject(SchemaObject parent, AttributeGroup attributeGroup) {
\r
43 this.parent = parent;
\r
44 this.obj = attributeGroup;
\r
45 this.type = ObjectType.ATTRIBUTE_GROUP;
\r
49 public SchemaObject(SchemaObject parent, SimpleType simpleType) {
\r
50 this.parent = parent;
\r
51 this.obj = simpleType;
\r
52 this.type = ObjectType.SIMPLE_TYPE;
\r
55 public Element getElement() {
\r
56 if (type != ObjectType.ELEMENT)
\r
58 return (Element)obj;
\r
61 public ComplexType getComplexType() {
\r
62 if (type != ObjectType.COMPLEX_TYPE)
\r
64 return (ComplexType)obj;
\r
67 public SimpleType getSimpleType() {
\r
68 if (type != ObjectType.SIMPLE_TYPE)
\r
70 return (SimpleType)obj;
\r
73 public AttributeGroup getAttributeGroup() {
\r
74 if (type != ObjectType.ATTRIBUTE_GROUP)
\r
76 return (AttributeGroup)obj;
\r
79 public SchemaObject getParent() {
\r
83 public OpenAttrs getObj() {
\r
88 public String getName() {
\r
90 case ATTRIBUTE_GROUP:
\r
91 if (obj instanceof NamedAttributeGroup)
\r
92 return ((NamedAttributeGroup)obj).getName();
\r
94 return ((AttributeGroupRef)obj).getRef().getLocalPart();
\r
96 return ((ComplexType)obj).getName();
\r
98 return ((Element)obj).getName();
\r
100 return ((SimpleType)obj).getName();
\r
102 throw new RuntimeException("Unknown object type " + type);
\r
105 public ObjectType getType() {
\r