X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaConversionBase.java;h=2cf2e0c76afd4b3edb400f220902ce96dd910d70;hb=09fb8eafbc9046ead17f0529eebad0b0caf55e2b;hp=5df8c4aefcbf4736d477410f4599c65c26286249;hpb=404be73748777cdd2d09b2f29308ae6f4a3d730c;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java index 5df8c4a..2cf2e0c 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java @@ -348,14 +348,6 @@ public abstract class SchemaConversionBase { return type; } } -// SimpleContent simpleContent = complexType.getSimpleContent(); -// if (simpleContent != null) { -// ExtensionType extensionType = simpleContent.getExtension(); -// if (extensionType != null) { -// QName type = extensionType.getBase(); -// return type; -// } -// } return null; } @@ -640,20 +632,15 @@ public abstract class SchemaConversionBase { protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) { Element localElement = element.getElement(); if (localElement.getName() != null) { - SchemaObject eObj = elements.get(localElement); // FIXME: handleIndicator should be refactored, not this methdof must be overridden in JavaGenerator to handle renaming of Elements properly - //String refName = eObj.getName();//localElement.getName(); + SchemaObject eObj = elements.get(localElement); QName refType = localElement.getType(); if (refType != null) - //handleIndicator(parent, indicator, element, false, refName, refType); handleIndicator(parent, indicator, element, null, RefType.Type); else { handleElement(eObj); - //handleIndicator(parent, indicator, element, false, refName, localElement); handleIndicator(parent, indicator, element, null, RefType.Element); } } else if (localElement.getRef() != null) { - //QName refType = localElement.getRef(); - //handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType); handleIndicator(parent, indicator,element, null, RefType.Reference); } } @@ -1069,5 +1056,129 @@ public abstract class SchemaConversionBase { } } + + public enum InheritanceType{ComplexType,AtomicType,None}; + + public static class Inheritance { + public String baseClass; + public InheritanceType type; + public TypeEntry atomicType; + + public Inheritance(String baseClass) { + this.baseClass = baseClass; + this.type = InheritanceType.None; + } + } + + public abstract String getComplexTypePrefix(); + + public abstract String getAttributeGroupPrefix(); + + public abstract String getName(SchemaObject obj); + + protected abstract String getBaseClass(ObjectType type); + + + + protected Inheritance getInheritance(SchemaObject topLevelObj) { + Inheritance inheritance = null; + if (topLevelObj.getType() == ObjectType.ELEMENT) { + Element topLevelElement = topLevelObj.getElement(); + inheritance = new Inheritance(getBaseClass(ObjectType.ELEMENT)); + if (topLevelElement.getType() != null) { + QName type = topLevelElement.getType(); + if (!type.getNamespaceURI().equals(SCHEMA_NS)) { + SchemaObject obj = complexTypeName.get(type.getLocalPart()); + // if (obj == null) + // obj = simpleTypeName.get(type.getLocalPart()); + if (obj != null) { + inheritance.baseClass = getName(obj); + inheritance.type = InheritanceType.ComplexType; + } + } else { + TypeEntry entry = getTypeEntry(type); + if (entry != null) { + inheritance.type = InheritanceType.AtomicType; + inheritance.atomicType = entry; + } + } + } + if (inheritance.type == InheritanceType.None) { + QName type = getElementBase(topLevelElement); + if (type != null) { + if (!type.getNamespaceURI().equals(SCHEMA_NS)) { + SchemaObject obj = getWithName(topLevelObj, type.getLocalPart()); + inheritance.baseClass = getName(obj); + inheritance.type = InheritanceType.ComplexType; + } else { + TypeEntry entry = getTypeEntry(type); + if (entry != null) { + inheritance.type = InheritanceType.AtomicType; + inheritance.atomicType = entry; + } + } + } + } + if (inheritance.type == InheritanceType.None) { + QName type = topLevelElement.getSubstitutionGroup(); + if (type != null) { + if (!type.getNamespaceURI().equals(SCHEMA_NS)) { + SchemaObject obj = getWithName(topLevelObj, type.getLocalPart()); + inheritance.baseClass = getName(obj); + inheritance.type = InheritanceType.ComplexType; + } else { + TypeEntry entry = getTypeEntry(type); + if (entry != null) { + inheritance.type = InheritanceType.AtomicType; + inheritance.atomicType = entry; + } + } + } + } + } else if (topLevelObj.getType() == ObjectType.COMPLEX_TYPE) { + ComplexType complexType = topLevelObj.getComplexType(); + QName type = getComplexTypeBase(complexType); + inheritance = new Inheritance(getBaseClass(ObjectType.COMPLEX_TYPE)); + if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) { + SchemaObject obj = complexTypeName.get(type.getLocalPart()); + if (obj != null) { + inheritance.baseClass = getName(obj); + inheritance.type = InheritanceType.ComplexType; + } + } + SimpleContent simpleContent = complexType.getSimpleContent(); + if (simpleContent != null) { + ExtensionType extensionType = simpleContent.getExtension(); + if (extensionType != null) { + type = extensionType.getBase(); + getAtomicTypeInheritance(type, topLevelObj, inheritance); + } + } + } + + return inheritance; + } + /** + * Goes through chain of SimpleTypes until locates Atomic Type (type defined in XML schema). + * @param type + * @param topLevelObj + * @param inheritance + */ + protected void getAtomicTypeInheritance(QName type, SchemaObject topLevelObj, Inheritance inheritance) { + if (!type.getNamespaceURI().equals(SCHEMA_NS)) { + SchemaObject obj = getWithName(topLevelObj, type.getLocalPart()); + if (obj.getType() != ObjectType.SIMPLE_TYPE) + throw new RuntimeException("SimpleContent does not use SimpleType definition"); + SimpleType simpleType = obj.getSimpleType(); + type = getSimpleTypeBase(simpleType); + getAtomicTypeInheritance(type, topLevelObj, inheritance); + } else { + TypeEntry entry = getTypeEntry(type); + if (entry != null) { + inheritance.type = InheritanceType.AtomicType; + inheritance.atomicType = entry; + } + } + } }