X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaConversionBase.java;fp=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaConversionBase.java;h=2bca88d64f5dfd666fee38f5d5cdf6a956fc4e84;hb=f11cbe76b3f4be142c9f84ef9a7b6bc9dcc8ff23;hp=3e6c8818732a102cd5b56601e1847eaeff2963be;hpb=df5314af4f42f8e600d22f74e8e32e126f98a1a8;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 3e6c881..2bca88d 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 @@ -196,41 +196,147 @@ public final class SchemaConversionBase { } } - protected Map elementName = new HashMap<>(); - protected Map complexTypeName = new HashMap<>(); - protected Map simpleTypeName = new HashMap<>(); - protected Map modelGroupName = new HashMap<>(); - protected Map elements = new HashMap<>(); - protected Map complexTypes = new HashMap<>(); - protected Map simpleTypes = new HashMap<>(); - protected Map modelGroups = new HashMap<>(); - - - protected SchemaObject getWithName(SchemaObject referrer, String name) { - SchemaObject obj = elementName.get(name); + private Map elementName = new HashMap<>(); + private Map complexTypeName = new HashMap<>(); + private Map simpleTypeName = new HashMap<>(); + private Map modelGroupName = new HashMap<>(); + private Map elements = new HashMap<>(); + private Map complexTypes = new HashMap<>(); + private Map simpleTypes = new HashMap<>(); + private Map modelGroups = new HashMap<>(); + + private SchemaObject _getWithName(QName name) { + SchemaObject obj = elementName.get(name.getLocalPart()); if (obj == null) - obj = complexTypeName.get(name); + obj = complexTypeName.get(name.getLocalPart()); if (obj == null) - obj = simpleTypeName.get(name); - if (obj == null) { - throw new RuntimeException("Cannot locate referred type " + name + " when handling " + referrer.getName()); - } + obj = simpleTypeName.get(name.getLocalPart()); return obj; } - protected SchemaObject getWithName(String name) { - SchemaObject obj = elementName.get(name); - if (obj == null) - obj = complexTypeName.get(name); - if (obj == null) - obj = simpleTypeName.get(name); - if (obj == null) { - throw new RuntimeException("Cannot locate referred type " + name); + protected SchemaObject getWithName(QName name) { + SchemaObject obj = _getWithName(name); + if (obj != null) + return obj; + if (name.getNamespaceURI() != null) { + for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) { + if (sc.base != null) { + obj = sc.base._getWithName(name); + if (obj != null) { + return obj; + } + } + } } - return obj; + return null; + } + + private NamedAttributeGroup _getAttributeGroup(QName name) { + for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) { + if (attrs instanceof NamedAttributeGroup) { + NamedAttributeGroup group = (NamedAttributeGroup)attrs; + if (group.getName().equals(name.getLocalPart())) + return group; + } + } + return null; + } + + public NamedAttributeGroup getAttributeGroup(QName name) { + NamedAttributeGroup group = _getAttributeGroup(name); + if (group != null) + return group; + if (name.getNamespaceURI() != null) { + for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) { + if (sc.base != null) { + group = sc.base._getAttributeGroup(name); + if (group != null) { + return group; + } + } + } + } + return null; + } + + private SchemaObject _getElement(QName name) { + return elementName.get(name.getLocalPart()); + } + + protected SchemaObject getElement(QName name) { + SchemaObject obj = _getElement(name); + if (obj != null) + return obj; + if (name.getNamespaceURI() != null) { + for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) { + if (sc.base != null) { + obj = sc.base._getElement(name); + if (obj != null) { + return obj; + } + } + } + } + return null; + } + + protected SchemaObject getElement(Element element) { + return elements.get(element); + } + + + private SchemaObject _getComplexType(QName name) { + return complexTypeName.get(name.getLocalPart()); + } + + protected SchemaObject getComplexType(QName name) { + SchemaObject obj = _getComplexType(name); + if (obj != null) + return obj; + if (name.getNamespaceURI() != null) { + for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) { + if (sc.base != null) { + obj = sc.base._getComplexType(name); + if (obj != null) { + return obj; + } + } + } + } + return null; + } + + protected SchemaObject getComplexType(ComplexType complexType) { + return complexTypes.get(complexType); + } + + private SchemaObject _getSimpleType(QName name) { + return simpleTypeName.get(name.getLocalPart()); + } + + protected SchemaObject getSimpleType(QName name) { + SchemaObject obj = _getSimpleType(name); + if (obj != null) + return obj; + if (name.getNamespaceURI() != null) { + for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) { + if (sc.base != null) { + obj = sc.base._getSimpleType(name); + if (obj != null) { + return obj; + } + } + } + } + return null; + } + + protected SchemaObject getSimpleType(SimpleType simpleType) { + return simpleTypes.get(simpleType); } protected SchemaObject getWithObj(SchemaObject referrer, OpenAttrs attrs) { + // FIXME : this method cannot handle references to other schemas. SchemaObject obj = null; if (attrs instanceof Element) obj = elements.get(attrs); @@ -492,13 +598,6 @@ public final class SchemaConversionBase { return null; } - - - - - - - private void handleAttributes(SchemaObject complexType, List attributeOrAttributeGroup) { //name = getComplexTypePrefix()+complexType.getName() @@ -763,6 +862,17 @@ public final class SchemaConversionBase { } } } else { + if (choices.size() == 1 && sequences.size() == 0 && alls.size() == 0 && groups.size() == 0) { + // special case: handle lone choice inside sequence with maxOccurs > 1 + SchemaElement choice = choices.get(0); + // move multiplicity restrictions to choice + if (indicator.getRestriction().max == -1 || (choice.getRestriction().max > 0 && indicator.getRestriction().max > choice.getRestriction().max)) + choice.getRestriction().max = indicator.getRestriction().max; + if (indicator.getRestriction().min == 0 || choice.getRestriction().min > indicator.getRestriction().min) + choice.getRestriction().min = indicator.getRestriction().min; + handle(parent, choice, elements); + return; + } if (sequences.size() > 0 || choices.size() > 0 || alls.size() > 0 || groups.size() > 0) { throw new RuntimeException("Cannot handle Sequence with inner ExplicitGroups"); } @@ -915,17 +1025,6 @@ public final class SchemaConversionBase { return simpleTypeName.containsKey(ref); } - public NamedAttributeGroup getAttributeGroup(String name) { - for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) { - if (attrs instanceof NamedAttributeGroup) { - NamedAttributeGroup group = (NamedAttributeGroup)attrs; - if (group.getName().equals(name)) - return group; - } - } - return null; - } - public IDProvider getIDProvider(Element element) { List idProviders = new ArrayList(2); for (JAXBElement e : configuration.getConversionRule()) { @@ -1279,7 +1378,7 @@ public final class SchemaConversionBase { QName type = getElementBase(topLevelElement); if (type != null) { if (!type.getNamespaceURI().equals(SCHEMA_NS)) { - SchemaObject obj = getWithName(topLevelObj, type.getLocalPart()); + SchemaObject obj = getWithName(type); inheritance.baseClass = getName(obj); inheritance.type = InheritanceType.ComplexType; } else { @@ -1295,7 +1394,7 @@ public final class SchemaConversionBase { QName type = topLevelElement.getSubstitutionGroup(); if (type != null) { if (!type.getNamespaceURI().equals(SCHEMA_NS)) { - SchemaObject obj = getWithName(topLevelObj, type.getLocalPart()); + SchemaObject obj = getWithName(type); inheritance.baseClass = getName(obj); inheritance.type = InheritanceType.ComplexType; } else { @@ -1338,7 +1437,8 @@ public final class SchemaConversionBase { */ public void getAtomicTypeInheritance(QName type, Inheritance inheritance) { if (!type.getNamespaceURI().equals(SCHEMA_NS)) { - SchemaObject obj = getWithName(type.getLocalPart()); + SchemaObject obj = getWithName(type); + System.out.println(); if (obj.getType() != ObjectType.SIMPLE_TYPE) throw new RuntimeException("SimpleContent does not use SimpleType definition"); SimpleType simpleType = obj.getSimpleType();