]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax/src/org/simantics/xml/data/XmlDataConverter.java
Attribute namespace + multi-schema data export
[simantics/interop.git] / org.simantics.xml.sax / src / org / simantics / xml / data / XmlDataConverter.java
index dfd1d6e059d2b2ad3d63ee02e5f8a064183f505e..7a2a5c54bf6d19ee805eb471374038d415b59208 100644 (file)
@@ -180,7 +180,6 @@ public class XmlDataConverter {
                                boolean sameNameSpace = true;
                                
                                if (parentElement != null) {
-                                       //QName parentType = parentElement.getType();
                                        String parentNs = elementNsMap.get(parentElement);
                                        sameNameSpace =currentNS.equals(parentNs);
                                        if (!sameNameSpace) {
@@ -190,50 +189,34 @@ public class XmlDataConverter {
                                                
                                }
                                if (schemaElement == null) {
-                                       LocalElement localElement = null;
-                                       //QName type = null;
                                        if (elementStack.isEmpty()) {
                                                schemaElement = new TopLevelElement();
                                                s.getSimpleTypeOrComplexTypeOrGroup().add(schemaElement);
                                        } else {
-                                               
-                                               
-//                                             if (sameNameSpace) {
-//                                                     localElement = new LocalElement();
-//                                                     schemaElement = localElement;
-//                                                     //type = new QName(elementName);
-//                                                     
-//                                             } else {
-                                                       schemaElement = new TopLevelElement();
-                                                       s.getSimpleTypeOrComplexTypeOrGroup().add(schemaElement);
-                                                       //type = new QName(SchemaConversionBase.SCHEMA_NS,"element");
-                                                       localElement = new LocalElement();
-                                                       localElement.setRef(new QName(parseElement.getName().getNamespaceURI(), elementName));
-                                                               
-//                                             }
+                                               schemaElement = new TopLevelElement();
+                                               s.getSimpleTypeOrComplexTypeOrGroup().add(schemaElement);
                                        }
                                        schemaElement.setName(elementName);
-                                       elementNsMap.put(schemaElement, currentNS);
-//                                     if (sameNameSpace) {
-//                                             schemaElement.setType(new QName(parseElement.getName().getNamespaceURI(),elementName));
-//                                     } else {
-//                                             schemaElement.setType(new QName(parseElement.getName().getNamespaceURI(), elementName));
-//                                     }
-                                       if (!elementStack.isEmpty()) {
-                                               ComplexType complexType = parentElement.getComplexType(); 
-                                               ExplicitGroup choice = complexType.getChoice();
-                                               if (choice == null) {
-                                                       choice = new ExplicitGroup();
-                                                       complexType.setChoice(choice);
-                                                       choice.setMaxOccurs("unbounded");
-                                               }
-                                               addElement(choice, new QName(SchemaConversionBase.SCHEMA_NS,"element"), localElement);
-                                       }
+                                       elementNsMap.put(schemaElement, currentNS);                             
                                        
                                        
                                        elementMap.get(s).put(elementName, schemaElement);
                                        newElement = true;
                                }
+                               if (parentElement != null) {
+                                       ComplexType complexType = parentElement.getComplexType(); 
+                                       ExplicitGroup choice = complexType.getChoice();
+                                       if (choice == null) {
+                                               choice = new ExplicitGroup();
+                                               complexType.setChoice(choice);
+                                               choice.setMaxOccurs("unbounded");
+                                       }
+                                       LocalElement localElement = new LocalElement();
+                                       localElement.setRef(new QName(parseElement.getName().getNamespaceURI(), elementName));
+                                       
+                                       addElement(choice, new QName(SchemaConversionBase.SCHEMA_NS,"element"), localElement);
+                               }
+                               
                                elementStack.push(schemaElement);
                                
                                Iterator<Attribute> attributeIterator = parseElement.getAttributes();
@@ -250,7 +233,7 @@ public class XmlDataConverter {
                                                Attribute attribute = attributeIterator.next();
                                                if ("http://www.w3.org/XML/1998/namespace".equals(attribute.getName().getNamespaceURI()))
                                                        continue;
-                                               addAttribute(attribute, complexType, parseElement.getNamespaceURI(attribute.getName().getPrefix()));
+                                               addAttribute(attribute, complexType, currentNS);
                                        }
                                        
                                } else {
@@ -273,7 +256,7 @@ public class XmlDataConverter {
                                                        continue;
                                                org.w3._2001.xmlschema.Attribute schemaAttribute = currentAttributes.get(attribute.getName().getLocalPart());
                                                if (schemaAttribute == null) {
-                                                       addAttribute(attribute, complexType, parseElement.getNamespaceURI(attribute.getName().getPrefix()));
+                                                       addAttribute(attribute, complexType, currentNS);
                                                } else {
                                                        QName newType = getType(attribute.getValue());
                                                        updateAttributeType(schemaAttribute, newType);
@@ -287,9 +270,9 @@ public class XmlDataConverter {
 //                             System.out.println("End " + element.getName());
                                elementStack.pop();
                        } else if (event.isAttribute()) {
-                               System.out.println(event);
+                       
                        } else if (event.isStartDocument()) {
-                               System.out.println(event);
+
                        } else if (event.isEndDocument()) {
                                
                        } else if (event.isEntityReference()) {
@@ -299,7 +282,7 @@ public class XmlDataConverter {
 //                             if (!characters.isWhiteSpace())
 //                                     System.out.println(characters.getData());
                    } else if (event.isNamespace()) {
-                       System.out.println(event);
+                   
                    }
                }
        }
@@ -352,8 +335,6 @@ public class XmlDataConverter {
        }
        
        private void addAttribute(Attribute attribute, ComplexType complexType, String currentNS) {
-               if (attribute.getName().getLocalPart().equals("Panel.ZIndex"))
-                       System.out.println();
                if (attribute.getName().getNamespaceURI().length() == 0 || attribute.getName().getNamespaceURI().equals(currentNS)) {
                        org.w3._2001.xmlschema.Attribute schemaAttribute = new org.w3._2001.xmlschema.Attribute();
                        schemaAttribute.setName(attribute.getName().getLocalPart());
@@ -406,8 +387,6 @@ public class XmlDataConverter {
                                }
                        }
                }
-               if ("Panel.ZIndex".equals(schemaAttribute.getName()))
-                       System.out.println();
                complexType.getAttributeOrAttributeGroup().add(schemaAttribute);
        }