package org.simantics.xml.sax; import org.simantics.xml.sax.configuration.Rename; import org.w3._2001.xmlschema.AttributeGroup; import org.w3._2001.xmlschema.AttributeGroupRef; import org.w3._2001.xmlschema.ComplexType; import org.w3._2001.xmlschema.Element; import org.w3._2001.xmlschema.NamedAttributeGroup; import org.w3._2001.xmlschema.OpenAttrs; import org.w3._2001.xmlschema.SimpleType; public class SchemaObject { enum ObjectType{ELEMENT,COMPLEX_TYPE,SIMPLE_TYPE,ATTRIBUTE_GROUP}; private SchemaObject parent; private ObjectType type; private OpenAttrs obj; private Rename rename; public SchemaObject(Element element) { this(null,element); } public void setRename(Rename rename) { this.rename = rename; } public SchemaObject(ComplexType complexType) { this(null, complexType); } public SchemaObject(SimpleType simpleType) { this(null, simpleType); } public SchemaObject(SchemaObject parent, Element element) { this.parent = parent; this.obj = element; this.type = ObjectType.ELEMENT; } public SchemaObject(SchemaObject parent, ComplexType complexType) { this.parent = parent; this.obj = complexType; this.type = ObjectType.COMPLEX_TYPE; } public SchemaObject(SchemaObject parent, AttributeGroup attributeGroup) { this.parent = parent; this.obj = attributeGroup; this.type = ObjectType.ATTRIBUTE_GROUP; } public SchemaObject(SchemaObject parent, SimpleType simpleType) { this.parent = parent; this.obj = simpleType; this.type = ObjectType.SIMPLE_TYPE; } public Element getElement() { if (type != ObjectType.ELEMENT) return null; return (Element)obj; } public ComplexType getComplexType() { if (type != ObjectType.COMPLEX_TYPE) return null; return (ComplexType)obj; } public SimpleType getSimpleType() { if (type != ObjectType.SIMPLE_TYPE) return null; return (SimpleType)obj; } public AttributeGroup getAttributeGroup() { if (type != ObjectType.ATTRIBUTE_GROUP) return null; return (AttributeGroup)obj; } public SchemaObject getParent() { return parent; } public OpenAttrs getObj() { return obj; } public String getName() { switch (type) { case ATTRIBUTE_GROUP: if (obj instanceof NamedAttributeGroup) return ((NamedAttributeGroup)obj).getName(); else return ((AttributeGroupRef)obj).getRef().getLocalPart(); case COMPLEX_TYPE: if (rename != null) return rename.getName(); return ((ComplexType)obj).getName(); case ELEMENT: if (rename != null) return rename.getName(); return ((Element)obj).getName(); case SIMPLE_TYPE: return ((SimpleType)obj).getName(); } throw new RuntimeException("Unknown object type " + type); } public ObjectType getType() { return type; } }