]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java
Attribute namespace + multi-schema data export
[simantics/interop.git] / org.simantics.xml.sax / src / org / simantics / xml / sax / SchemaConversionBase.java
index 049b08775cb915dfd28628851f28b38634966c11..51707cb6d351ca7a04556a8f2404afefd8bab3ed 100644 (file)
@@ -204,10 +204,12 @@ public final class SchemaConversionBase {
        private Map<String,SchemaObject> complexTypeName = new HashMap<>();
        private Map<String,SchemaObject> simpleTypeName = new HashMap<>();
        private Map<String,SchemaObject> modelGroupName = new HashMap<>();
+       private Map<String,SchemaObject> attrName = new HashMap<>();
        private Map<Element,SchemaObject> elements = new HashMap<>();
        private Map<ComplexType,SchemaObject> complexTypes = new HashMap<>();
        private Map<SimpleType,SchemaObject> simpleTypes = new HashMap<>();
        private Map<NamedGroup,SchemaObject> modelGroups = new HashMap<>();
+       private Map<Attribute,SchemaObject> attributes = new HashMap<>();
        
        private SchemaObject _getWithName(QName name) {
                SchemaObject obj = elementName.get(name.getLocalPart());
@@ -215,6 +217,8 @@ public final class SchemaConversionBase {
                        obj = complexTypeName.get(name.getLocalPart());
                if (obj == null)
                        obj = simpleTypeName.get(name.getLocalPart());
+               if (obj == null)
+                       obj = attrName.get(name.getLocalPart());
                return obj;
        }
        
@@ -373,7 +377,9 @@ public final class SchemaConversionBase {
                                SchemaObject obj = new SchemaObject(this,simpleType);
                                stack.push(obj);
                        }  else if (attrs instanceof Attribute) {
-                               // Attributes are not cached
+                               Attribute attribute = (Attribute)attrs;
+                               SchemaObject obj = new SchemaObject(this, attribute);
+                               stack.push(obj);
                        } else if (attrs instanceof AttributeGroup) {
                                // Attribute groups are not cached
                        } else if (attrs instanceof NamedGroup) {
@@ -466,6 +472,12 @@ public final class SchemaConversionBase {
                                modelGroups.put(e, object);
                                break;
                        }
+                       case ATTRIBUTE: {
+                               Attribute e = object.getAttribute();
+                               attrName.put(e.getName(), object);
+                               attributes.put(e, object);
+                               break;
+                       }
                        }
                } // while
        }
@@ -730,13 +742,30 @@ public final class SchemaConversionBase {
                return type;
        }
        
+       private SchemaObject _getAttribute(QName name) {
+               return attrName.get(name.getLocalPart());
+       }
+       
        protected Attribute getRefAttribute(QName ref) {
-               for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {
-                       if (attrs instanceof TopLevelAttribute) {
-                               TopLevelAttribute attribute = (TopLevelAttribute)attrs;
-                               if (attribute.getName().equals(ref.getLocalPart()))
-                                       return attribute;
-                       }
+//             for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {
+//                     if (attrs instanceof TopLevelAttribute) {
+//                             TopLevelAttribute attribute = (TopLevelAttribute)attrs;
+//                             if (attribute.getName().equals(ref.getLocalPart()))
+//                                     return attribute;
+//                     }
+//             }
+               SchemaObject obj = _getAttribute(ref);
+               if (obj != null)
+                       return obj.getAttribute();
+               if (ref.getNamespaceURI() != null) {
+                       for (SchemaConverter sc : converter.getConverter(ref.getNamespaceURI())) {
+                               if (sc.base != null) {
+                                       obj = sc.base._getAttribute(ref);
+                                       if (obj != null) {
+                                               return obj.getAttribute();
+                                       }
+                               }
+                       }               
                }
                return null;
        }