-package org.simantics.xml.sax;\r
-\r
-import org.w3._2001.xmlschema.AttributeGroup;\r
-import org.w3._2001.xmlschema.AttributeGroupRef;\r
-import org.w3._2001.xmlschema.ComplexType;\r
-import org.w3._2001.xmlschema.Element;\r
-import org.w3._2001.xmlschema.NamedAttributeGroup;\r
-import org.w3._2001.xmlschema.OpenAttrs;\r
-import org.w3._2001.xmlschema.SimpleType;\r
-\r
-public class SchemaObject {\r
- enum ObjectType{ELEMENT,COMPLEX_TYPE,SIMPLE_TYPE,ATTRIBUTE_GROUP};\r
- \r
- private SchemaObject parent;\r
- private ObjectType type;\r
- private OpenAttrs obj;\r
- \r
- public SchemaObject(Element element) {\r
- this(null,element);\r
- }\r
- \r
- public SchemaObject(ComplexType complexType) {\r
- this(null, complexType);\r
- }\r
- \r
- public SchemaObject(SimpleType simpleType) {\r
- this(null, simpleType);\r
- }\r
- \r
- public SchemaObject(SchemaObject parent, Element element) {\r
- this.parent = parent;\r
- this.obj = element;\r
- this.type = ObjectType.ELEMENT;\r
- }\r
- \r
- public SchemaObject(SchemaObject parent, ComplexType complexType) {\r
- this.parent = parent;\r
- this.obj = complexType;\r
- this.type = ObjectType.COMPLEX_TYPE;\r
- }\r
- \r
- public SchemaObject(SchemaObject parent, AttributeGroup attributeGroup) {\r
- this.parent = parent;\r
- this.obj = attributeGroup;\r
- this.type = ObjectType.ATTRIBUTE_GROUP;\r
- }\r
- \r
-\r
- public SchemaObject(SchemaObject parent, SimpleType simpleType) {\r
- this.parent = parent;\r
- this.obj = simpleType;\r
- this.type = ObjectType.SIMPLE_TYPE;\r
- }\r
- \r
- public Element getElement() {\r
- if (type != ObjectType.ELEMENT)\r
- return null;\r
- return (Element)obj;\r
- }\r
- \r
- public ComplexType getComplexType() {\r
- if (type != ObjectType.COMPLEX_TYPE)\r
- return null;\r
- return (ComplexType)obj;\r
- }\r
- \r
- public SimpleType getSimpleType() {\r
- if (type != ObjectType.SIMPLE_TYPE)\r
- return null;\r
- return (SimpleType)obj;\r
- }\r
- \r
- public AttributeGroup getAttributeGroup() {\r
- if (type != ObjectType.ATTRIBUTE_GROUP)\r
- return null;\r
- return (AttributeGroup)obj;\r
- }\r
- \r
- public SchemaObject getParent() {\r
- return parent;\r
- }\r
- \r
- public OpenAttrs getObj() {\r
- return obj;\r
- }\r
- \r
- \r
- public String getName() {\r
- switch (type) {\r
- case ATTRIBUTE_GROUP:\r
- if (obj instanceof NamedAttributeGroup)\r
- return ((NamedAttributeGroup)obj).getName();\r
- else\r
- return ((AttributeGroupRef)obj).getRef().getLocalPart();\r
- case COMPLEX_TYPE:\r
- return ((ComplexType)obj).getName();\r
- case ELEMENT:\r
- return ((Element)obj).getName();\r
- case SIMPLE_TYPE:\r
- return ((SimpleType)obj).getName();\r
- }\r
- throw new RuntimeException("Unknown object type " + type); \r
- }\r
- \r
- public ObjectType getType() {\r
- return type;\r
- }\r
-\r
-}\r
+package org.simantics.xml.sax;
+
+import org.simantics.xml.sax.configuration.Rename;
+import org.w3._2001.xmlschema.Attribute;
+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.NamedGroup;
+import org.w3._2001.xmlschema.OpenAttrs;
+import org.w3._2001.xmlschema.SimpleType;
+
+public class SchemaObject {
+ enum ObjectType{ELEMENT,COMPLEX_TYPE,SIMPLE_TYPE,ATTRIBUTE_GROUP,MODEL_GROUP,ATTRIBUTE};
+
+ private SchemaConversionBase sc;
+ private String name;
+ private SchemaObject parent;
+ private ObjectType type;
+ private OpenAttrs obj;
+ private Rename rename;
+
+ public SchemaObject(SchemaConversionBase sc, Element element) {
+ this(sc,null,element);
+ }
+
+ public void setRename(Rename rename) {
+ this.rename = rename;
+ _init();
+ }
+
+ public SchemaObject(SchemaConversionBase sc,ComplexType complexType) {
+ this(sc,null, complexType);
+ }
+
+ public SchemaObject(SchemaConversionBase sc,SimpleType simpleType) {
+ this(sc,null, simpleType);
+ }
+
+ public SchemaObject(SchemaConversionBase sc,NamedGroup namedGroup) {
+ this(sc,null, namedGroup);
+ }
+
+ public SchemaObject(SchemaConversionBase sc, Attribute attribute) {
+ this(sc,null, attribute);
+ }
+
+ public SchemaObject(SchemaConversionBase sc,SchemaObject parent, Element element) {
+ this.parent = parent;
+ this.obj = element;
+ this.type = ObjectType.ELEMENT;
+ this.sc = sc;
+ _init();
+ }
+
+ public SchemaObject(SchemaConversionBase sc,SchemaObject parent, ComplexType complexType) {
+ this.parent = parent;
+ this.obj = complexType;
+ this.type = ObjectType.COMPLEX_TYPE;
+ this.sc = sc;
+ _init();
+ }
+
+ public SchemaObject(SchemaConversionBase sc,SchemaObject parent, AttributeGroup attributeGroup) {
+ this.parent = parent;
+ this.obj = attributeGroup;
+ this.type = ObjectType.ATTRIBUTE_GROUP;
+ this.sc = sc;
+ _init();
+ }
+
+ public SchemaObject(SchemaConversionBase sc,SchemaObject parent, NamedGroup namedGroup) {
+ this.parent = parent;
+ this.obj = namedGroup;
+ this.type = ObjectType.MODEL_GROUP;
+ this.sc = sc;
+ _init();
+ }
+
+
+ public SchemaObject(SchemaConversionBase sc,SchemaObject parent, SimpleType simpleType) {
+ this.parent = parent;
+ this.obj = simpleType;
+ this.type = ObjectType.SIMPLE_TYPE;
+ this.sc = sc;
+ _init();
+ }
+
+ public SchemaObject(SchemaConversionBase sc,SchemaObject parent, Attribute attribute) {
+ this.parent = parent;
+ this.obj = attribute;
+ this.type = ObjectType.ATTRIBUTE;
+ this.sc = sc;
+ _init();
+ }
+
+ private void _init() {
+ name = _getName();
+ if (name != null)
+ name = name.replaceAll("\\.", "_");
+ }
+
+ 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 NamedGroup getModelGroup() {
+ if (type != ObjectType.MODEL_GROUP)
+ return null;
+ return (NamedGroup)obj;
+ }
+
+ public Attribute getAttribute() {
+ if (type != ObjectType.ATTRIBUTE)
+ return null;
+ return (Attribute)obj;
+ }
+
+ public SchemaObject getParent() {
+ return parent;
+ }
+
+ public OpenAttrs getObj() {
+ return obj;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public String getLibShortName() {
+ return sc.converter.shortName;
+ }
+
+
+ private 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();
+ case ATTRIBUTE:
+ return ((Attribute)obj).getName();
+ }
+ throw new RuntimeException("Unknown object type " + type);
+ }
+
+ public ObjectType getType() {
+ return type;
+ }
+
+ public SchemaConversionBase getSc() {
+ return sc;
+ }
+
+}