1 package org.simantics.xml.sax;
3 import org.simantics.xml.sax.configuration.Rename;
4 import org.w3._2001.xmlschema.Attribute;
5 import org.w3._2001.xmlschema.AttributeGroup;
6 import org.w3._2001.xmlschema.AttributeGroupRef;
7 import org.w3._2001.xmlschema.ComplexType;
8 import org.w3._2001.xmlschema.Element;
9 import org.w3._2001.xmlschema.NamedAttributeGroup;
10 import org.w3._2001.xmlschema.NamedGroup;
11 import org.w3._2001.xmlschema.OpenAttrs;
12 import org.w3._2001.xmlschema.SimpleType;
14 public class SchemaObject {
15 enum ObjectType{ELEMENT,COMPLEX_TYPE,SIMPLE_TYPE,ATTRIBUTE_GROUP,MODEL_GROUP,ATTRIBUTE};
17 private SchemaConversionBase sc;
19 private SchemaObject parent;
20 private ObjectType type;
21 private OpenAttrs obj;
22 private Rename rename;
24 public SchemaObject(SchemaConversionBase sc, Element element) {
25 this(sc,null,element);
28 public void setRename(Rename rename) {
33 public SchemaObject(SchemaConversionBase sc,ComplexType complexType) {
34 this(sc,null, complexType);
37 public SchemaObject(SchemaConversionBase sc,SimpleType simpleType) {
38 this(sc,null, simpleType);
41 public SchemaObject(SchemaConversionBase sc,NamedGroup namedGroup) {
42 this(sc,null, namedGroup);
45 public SchemaObject(SchemaConversionBase sc, Attribute attribute) {
46 this(sc,null, attribute);
49 public SchemaObject(SchemaConversionBase sc,SchemaObject parent, Element element) {
52 this.type = ObjectType.ELEMENT;
57 public SchemaObject(SchemaConversionBase sc,SchemaObject parent, ComplexType complexType) {
59 this.obj = complexType;
60 this.type = ObjectType.COMPLEX_TYPE;
65 public SchemaObject(SchemaConversionBase sc,SchemaObject parent, AttributeGroup attributeGroup) {
67 this.obj = attributeGroup;
68 this.type = ObjectType.ATTRIBUTE_GROUP;
73 public SchemaObject(SchemaConversionBase sc,SchemaObject parent, NamedGroup namedGroup) {
75 this.obj = namedGroup;
76 this.type = ObjectType.MODEL_GROUP;
82 public SchemaObject(SchemaConversionBase sc,SchemaObject parent, SimpleType simpleType) {
84 this.obj = simpleType;
85 this.type = ObjectType.SIMPLE_TYPE;
90 public SchemaObject(SchemaConversionBase sc,SchemaObject parent, Attribute attribute) {
93 this.type = ObjectType.ATTRIBUTE;
98 private void _init() {
101 name = name.replaceAll("\\.", "_");
104 public Element getElement() {
105 if (type != ObjectType.ELEMENT)
110 public ComplexType getComplexType() {
111 if (type != ObjectType.COMPLEX_TYPE)
113 return (ComplexType)obj;
116 public SimpleType getSimpleType() {
117 if (type != ObjectType.SIMPLE_TYPE)
119 return (SimpleType)obj;
122 public AttributeGroup getAttributeGroup() {
123 if (type != ObjectType.ATTRIBUTE_GROUP)
125 return (AttributeGroup)obj;
128 public NamedGroup getModelGroup() {
129 if (type != ObjectType.MODEL_GROUP)
131 return (NamedGroup)obj;
134 public Attribute getAttribute() {
135 if (type != ObjectType.ATTRIBUTE)
137 return (Attribute)obj;
140 public SchemaObject getParent() {
144 public OpenAttrs getObj() {
149 public String getName() {
153 public String getLibShortName() {
154 return sc.converter.shortName;
158 private String _getName() {
160 case ATTRIBUTE_GROUP:
161 if (obj instanceof NamedAttributeGroup)
162 return ((NamedAttributeGroup)obj).getName();
164 return ((AttributeGroupRef)obj).getRef().getLocalPart();
167 return rename.getName();
168 return ((ComplexType)obj).getName();
171 return rename.getName();
172 return ((Element)obj).getName();
174 return ((SimpleType)obj).getName();
176 return ((Attribute)obj).getName();
178 throw new RuntimeException("Unknown object type " + type);
181 public ObjectType getType() {
185 public SchemaConversionBase getSc() {