X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaObject.java;fp=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaObject.java;h=53f9da9fb0b4a749041f8704440aa5b34627f36f;hb=fc60d91049c46ee5b6107da4d4c54eada4a9f21c;hp=4138222913bb100923e0f08748d73a7445cfb55d;hpb=ab4fc05981803ce2c430f93f34b8b6a8f85a53ce;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaObject.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaObject.java index 4138222..53f9da9 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaObject.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaObject.java @@ -1,136 +1,168 @@ -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.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}; - - 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(NamedGroup namedGroup) { - this(null, namedGroup); - } - - 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, NamedGroup namedGroup) { - this.parent = parent; - this.obj = namedGroup; - this.type = ObjectType.MODEL_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 NamedGroup getModelGroup() { - if (type != ObjectType.MODEL_GROUP) - return null; - return (NamedGroup)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; - } - -} +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.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}; + + 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,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(); + } + + 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 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(); + } + throw new RuntimeException("Unknown object type " + type); + } + + public ObjectType getType() { + return type; + } + + public SchemaConversionBase getSc() { + return sc; + } + +}