]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java
Handling ComplexTypes defined with SimpleContent
[simantics/interop.git] / org.simantics.xml.sax / src / org / simantics / xml / sax / ImporterGenerator.java
index 25fc020084cf89c66a2a6f05d55f7e04fbef5363..f55f9cfeb0ad7a5816cc584f84cf5cba32216ff8 100644 (file)
@@ -5,30 +5,25 @@ import java.io.IOException;
 import java.io.PrintWriter;\r
 import java.io.StringWriter;\r
 import java.util.ArrayList;\r
-import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
 import javax.xml.namespace.QName;\r
 \r
 import org.simantics.utils.datastructures.BijectionMap;\r
-import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
 import org.simantics.xml.sax.configuration.AttributeComposition;\r
 import org.simantics.xml.sax.configuration.Configuration;\r
 import org.simantics.xml.sax.configuration.IDProvider;\r
 import org.simantics.xml.sax.configuration.IDReference;\r
-import org.simantics.xml.sax.configuration.Rename;\r
 import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
 import org.w3._2001.xmlschema.Annotated;\r
 import org.w3._2001.xmlschema.Attribute;\r
 import org.w3._2001.xmlschema.AttributeGroup;\r
-import org.w3._2001.xmlschema.AttributeGroupRef;\r
 import org.w3._2001.xmlschema.ComplexType;\r
 import org.w3._2001.xmlschema.Element;\r
 import org.w3._2001.xmlschema.LocalComplexType;\r
 import org.w3._2001.xmlschema.LocalSimpleType;\r
 import org.w3._2001.xmlschema.NamedAttributeGroup;\r
-import org.w3._2001.xmlschema.OpenAttrs;\r
 import org.w3._2001.xmlschema.Restriction;\r
 import org.w3._2001.xmlschema.Schema;\r
 import org.w3._2001.xmlschema.SimpleType;\r
@@ -40,7 +35,7 @@ public class ImporterGenerator extends JavaGenerator{
                super(configuration);\r
        }\r
        \r
-       public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
+       public void createParser(Schema schema,String ontologyUri, String className, SchemaConverter converter) throws IOException {\r
                this.schema = schema;\r
                this.ontologyClassName = className;\r
                this.converter = converter;\r
@@ -107,15 +102,20 @@ public class ImporterGenerator extends JavaGenerator{
        }\r
 \r
        protected void handle(TopLevelAttribute topLevelAttribute) {\r
-\r
        }\r
        \r
+       @Override\r
+       protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
+       }\r
        \r
        @Override\r
        protected void handleComplexType(SchemaObject complexTypeObj) {\r
                ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
                \r
-               String name = getName(complexTypeObj);//topLevelComplexType.getName();\r
+               String name = getName(complexTypeObj);\r
+               \r
+//             if (topLevelComplexType.getName().equals("Reference"))\r
+//                     System.out.println();\r
                \r
                String className = name;//"_"+name;\r
                \r
@@ -126,17 +126,18 @@ public class ImporterGenerator extends JavaGenerator{
                        throw new RuntimeException(e);\r
                }\r
                writers.put(complexTypeObj, fw);\r
-               \r
-               boolean isList = false;\r
 \r
-               String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
+               String baseClass = getBaseClass();\r
                \r
                boolean inherited = false;\r
                \r
                QName type = getComplexTypeBase(topLevelComplexType);\r
                if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
-                       baseClass = getName(complexTypeName.get(type.getLocalPart()));\r
-                       inherited = true;\r
+                       SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+                       if (obj != null) {\r
+                               baseClass = getName(obj);\r
+                               inherited = true;\r
+                       }\r
                }\r
                \r
                provider = getIDProvider(topLevelComplexType);\r
@@ -149,7 +150,7 @@ public class ImporterGenerator extends JavaGenerator{
                if (unknownChildElement != null)\r
                        intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
                \r
-               createClassHeader(fw.writer, isList);\r
+               createClassHeader(fw.writer, false);\r
                writeClass(fw.writer,false, null, className, baseClass, intrerfaces);\r
                        \r
                writeIDProvider(fw.writer);\r
@@ -158,12 +159,8 @@ public class ImporterGenerator extends JavaGenerator{
                fw.writer.println("   public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
                fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");\r
                fw.writer.println("      "+getOntologyImport());\r
-               if (!isList) {\r
                fw.writer.println("      Resource res = graph.newResource();");\r
                fw.writer.println("      graph.claim(res, L0.InstanceOf, "+ontShort+name+");");\r
-               } else {\r
-               fw.writer.println("      Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");\r
-               }\r
                fw.writer.println("      return res;");\r
                fw.writer.println("   }");\r
                fw.writer.println();\r
@@ -567,10 +564,7 @@ public class ImporterGenerator extends JavaGenerator{
        }\r
        \r
        \r
-       @Override\r
-       protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
-\r
-       }\r
+       \r
 \r
        \r
        IDProvider provider;\r