]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java
Replace log4j with slf4j
[simantics/interop.git] / org.simantics.xml.sax / src / org / simantics / xml / sax / SchemaConversionBase.java
index 049b08775cb915dfd28628851f28b38634966c11..6621cc716f17853f3549644bf2f6b42cf8cc6d44 100644 (file)
@@ -28,6 +28,7 @@ import org.w3._2001.xmlschema.Any;
 import org.w3._2001.xmlschema.Attribute;
 import org.w3._2001.xmlschema.AttributeGroup;
 import org.w3._2001.xmlschema.ComplexContent;
+import org.w3._2001.xmlschema.ComplexRestrictionType;
 import org.w3._2001.xmlschema.ComplexType;
 import org.w3._2001.xmlschema.Element;
 import org.w3._2001.xmlschema.ExplicitGroup;
@@ -204,10 +205,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 +218,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 +378,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 +473,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
        }
@@ -529,6 +542,13 @@ public final class SchemaConversionBase {
                                QName type = extensionType.getBase();
                                return type;
                        }
+                       ComplexRestrictionType restriction = complexContent.getRestriction();
+                       if (restriction != null)
+                               return restriction.getBase();
+               }
+               if (complexType.isMixed()) {
+                       // Handle characters data of mixed ComplexType as String.
+                       return new QName(SCHEMA_NS, "string");
                }
                return null;
        }
@@ -730,13 +750,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;
        }