]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Schema conversion changes
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 4 May 2017 10:28:35 +0000 (13:28 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 4 May 2017 10:28:35 +0000 (13:28 +0300)
Multiline base64 data import fixed
Use '_List' postfix with LinkedList
Processing a SimpleType when schema contains an Element with the same
name failed

Change-Id: I76607517d2e60dc87c0fc6e07c7b81b65e6d4d8a

org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java

index 121a6352b8e73401ad894c00b90add2e29083c7d..deb5f11cf2d27484d12cb5f5dc6622a4dc17f65b 100644 (file)
-package org.simantics.xml.sax;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.io.PrintWriter;\r
-import java.io.StringWriter;\r
-import java.util.Collections;\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.Inheritance;\r
-import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;\r
-import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
-import org.simantics.xml.sax.SchemaConversionBase.TypeEntry;\r
-import org.simantics.xml.sax.SchemaObject.ObjectType;\r
-import org.simantics.xml.sax.configuration.AttributeComposition;\r
-import org.simantics.xml.sax.configuration.IDProvider;\r
-import org.simantics.xml.sax.configuration.IDReference;\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.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.NamedGroup;\r
-import org.w3._2001.xmlschema.Restriction;\r
-import org.w3._2001.xmlschema.SimpleType;\r
-\r
-public class ExporterGenerator extends JavaGenerator{\r
-       \r
-       public ExporterGenerator(SchemaConverter converter, SchemaConversionBase base) {\r
-               super(converter, base);\r
-       }\r
-\r
-       public void createParser() throws IOException {\r
-               \r
-               String parserPackagePostfix = "_exp";\r
-               String importerClassPostfix = "Exporter";\r
-               String parserClassPostfix = "Writer";\r
-               elementPackageName = name+parserPackagePostfix;\r
-               \r
-               importParserDir= new File(converter.getParserDir().getAbsolutePath()+"/"+elementPackageName);\r
-               if (!importParserDir.exists())\r
-                       importParserDir.mkdirs();\r
-               \r
-               base.handle(this);\r
-               // Create Importer class\r
-               File importerFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+importerClassPostfix+".java");\r
-               PrintWriter mainWriter = createFile(importerFile);\r
-               mainWriter.println("package " + converter.getPluginName() +";");\r
-               mainWriter.println();\r
-               mainWriter.println("import java.io.File;");\r
-               mainWriter.println("import org.simantics.db.Resource;");\r
-               mainWriter.println("import org.simantics.db.Session;");\r
-               mainWriter.println("import org.simantics.db.exception.DatabaseException;");\r
-               mainWriter.println("import org.simantics.xml.sax.base.AbstractExporter;");\r
-               mainWriter.println();\r
-               mainWriter.println("public class " + name + importerClassPostfix+" extends AbstractExporter {");\r
-               mainWriter.println();\r
-               mainWriter.println("   public " + name + importerClassPostfix+"(Session session, File file, Resource root) throws DatabaseException {");\r
-               mainWriter.println("      super(session, file, root);");\r
-               mainWriter.println("      setXmlWriter(new "+name + parserClassPostfix+"(session));");\r
-               mainWriter.println("   }");\r
-               mainWriter.println();\r
-               mainWriter.println("}");\r
-               \r
-               mainWriter.println();\r
-               mainWriter.flush();\r
-               mainWriter.close();\r
-               \r
-               // Create Parser class\r
-               File parserFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+parserClassPostfix+".java");\r
-               mainWriter = createFile(parserFile);\r
-               mainWriter.println("package " + converter.getPluginName() +";");\r
-               mainWriter.println();\r
-               mainWriter.println("import org.simantics.xml.sax.base.XMLWriter;");\r
-               mainWriter.println("import org.simantics.db.ReadGraph;");\r
-               mainWriter.println("import org.simantics.db.Session;");\r
-               mainWriter.println("import org.simantics.db.exception.DatabaseException;");\r
-               mainWriter.println("import org.simantics.db.common.request.ReadRequest;");\r
-               mainWriter.println();\r
-               mainWriter.println("public class " + name + parserClassPostfix+" extends XMLWriter {");\r
-               mainWriter.println();\r
-               mainWriter.println("   public " + name + parserClassPostfix+"(Session session) throws DatabaseException {");\r
-               if (schema.getTargetNamespace() != null)\r
-               mainWriter.println("      setSchemaURI(\""+schema.getTargetNamespace()+"\");");\r
-               mainWriter.println("      setOntologyURI(\""+ontologyUri+"\");");\r
-               mainWriter.println("      session.syncRequest(new ReadRequest() {");\r
-               mainWriter.println("        @Override");\r
-               mainWriter.println("        public void run(ReadGraph graph) throws DatabaseException {");\r
-               mainWriter.println("          setGraph(graph);");\r
-               for (String s : ruleClassNames) {\r
-               mainWriter.println("          add(new "+s+"(graph));");\r
-               }\r
-               mainWriter.println("        }");\r
-               mainWriter.println("      });");\r
-               mainWriter.println("   }");\r
-               mainWriter.println("}");\r
-               \r
-               mainWriter.println();\r
-               mainWriter.flush();\r
-               mainWriter.close();\r
-       }\r
-       \r
-//     @Override\r
-//     protected void handle(TopLevelAttribute topLevelAttribute) {\r
-//\r
-//     }\r
-       \r
-       @Override\r
-       public String getBaseClass(ObjectType type) {\r
-               return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
-       }\r
-       \r
-       @Override\r
-       public void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
-       }\r
-       \r
-       @Override\r
-       public void handle(SchemaObject parent, NamedGroup attribute) {\r
-               // TODO Auto-generated method stub\r
-               \r
-       }\r
-\r
-       @Override\r
-       public void handleComplexType(SchemaObject complexTypeObj) {\r
-               ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
-               \r
-               String name = getName(complexTypeObj);\r
-               \r
-               String className = name;//"_"+name;\r
-               \r
-               FileWriter fw = new FileWriter();\r
-               try {\r
-                       fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));\r
-               } catch (IOException e) {\r
-                       throw new RuntimeException(e);\r
-               }\r
-               writers.put(complexTypeObj, fw);\r
-\r
-//             String baseClass = getBaseClass(ObjectType.COMPLEX_TYPE);\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
-//                     SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
-////                   if (obj == null)\r
-////                           obj = simpleTypeName.get(type.getLocalPart());\r
-//                     if (obj != null) {\r
-//                             baseClass = getName(obj);\r
-//                             inherited = true;\r
-//                     }\r
-//             }\r
-               Inheritance inheritance = base.getInheritance(complexTypeObj);\r
-               \r
-               provider = base.getIDProvider(topLevelComplexType);\r
-//             List<IDReference> references = getIDReferences(topLevelComplexType);\r
-//             UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
-\r
-//             List<String> intrerfaces = new ArrayList<String>();\r
-//             if (references.size() > 0)\r
-//                     intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");\r
-//             if (unknownChildElement != null)\r
-//                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
-               \r
-               createClassHeader(fw.writer);\r
-               writeClass(fw.writer,false, topLevelComplexType.getName(), className, inheritance.baseClass, Collections.EMPTY_LIST);\r
-                       \r
-//             writeIDProvider(fw.writer);\r
-       \r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public Resource getType(ReadGraph graph) throws DatabaseException {");\r
-               fw.writer.println("      "+getOntologyImport());\r
-               fw.writer.println("      return "+ontShort+name+";");\r
-               fw.writer.println("   }");\r
-               fw.writer.println();\r
-               \r
-//             fw.writer.println("   @Override");\r
-//             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
-               \r
-//             fw.writer.println("   @Override");\r
-//             fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
-//             fw.writer.println("      "+getOntologyImport());\r
-//             fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(complexTypeObj,"has")+", element.getData());");\r
-//             fw.writer.println("      return true;");\r
-//             fw.writer.println("   }");\r
-//             fw.writer.println();\r
-                               \r
-               StringWriter stringWriter = new StringWriter();\r
-               fw.delayedWriter = new PrintWriter(stringWriter);\r
-               StringWriter stringWriter2 = new StringWriter();\r
-               fw.delayedWriter2 = new PrintWriter(stringWriter2);\r
-               \r
-               fw.writer.println("   public " + className + "(ReadGraph graph) {");\r
-               fw.writer.println("      super(graph);");\r
-               fw.writer.println("      "+getOntologyImport());\r
-               \r
-               base.handleComplexTypeExtension(complexTypeObj);\r
-               \r
-               fw.writer.println("   }");\r
-               \r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void children(ReadGraph graph, WriterElement instance, java.util.Set<org.simantics.db.Resource> result) throws XMLStreamException, DatabaseException {");\r
-               fw.writer.println("      "+getOntologyImport());\r
-               \r
-               if (stringWriter.getBuffer().length() > 0) {\r
-                       fw.writer.write(stringWriter.toString());\r
-               }\r
-               if (inheritance.type == InheritanceType.ComplexType)\r
-               fw.writer.println("      super.children(graph,instance,result);");\r
-               fw.writer.println("   }");\r
-               fw.writer.println();\r
-               \r
-               if (stringWriter2.getBuffer().length() > 0) {\r
-                       fw.writer.write(stringWriter2.toString());\r
-               }\r
-               \r
-               stringWriter = null;\r
-               fw.delayedWriter.close();\r
-               fw.delayedWriter=null;\r
-               stringWriter2 = null;\r
-               fw.delayedWriter2.close();\r
-               fw.delayedWriter2 = null;\r
-               \r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");\r
-               if (inheritance.type == InheritanceType.ComplexType) {\r
-               fw.writer.println("             super.attributes(graph,instance,attributes,writer);");\r
-               }\r
-               fw.writer.println("        "+getOntologyImport());\r
-               fw.writer.println("        for (Statement attribute : attributes) {");\r
-               base.handleComplexTypeAttributes(complexTypeObj);\r
-               base.handleExtensionAttributes(complexTypeObj);\r
-               fw.writer.println("        }");\r
-               fw.writer.println("   }");\r
-               \r
-               if (inheritance.type == InheritanceType.AtomicType) {\r
-               fw.writer.println();\r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
-               fw.writer.println("            writer.writeCharacters("+inheritance.atomicType.getToString("graph.getValue(instance.getResource(),"+inheritance.atomicType.binding+")")+");");\r
-               fw.writer.println("   }");\r
-               }\r
-               \r
-//             writeIDReferences(fw.writer,name, references);\r
-//             writeUnknownChild(fw.writer,name,unknownChildElement);\r
-               \r
-               fw.writer.println("}");\r
-               fw.writer.println();\r
-               fw.writer.flush();\r
-               fw.writer.close();\r
-               fw.writer = null;\r
-               writers.remove(complexTypeObj);\r
-               provider = null;\r
-       }\r
-       \r
-       @Override\r
-       protected void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName,\r
-                       String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList) {\r
-               FileWriter fw = getWriter(parent);\r
-               if ("TextOrField".equals(refName))\r
-                       System.out.println();\r
-               if (referenceType == RefType.Type) {\r
-               // create internal class for handling the element and child attachment\r
-               secondaryClassName = getName(parent) +"_" +objectName;\r
-               if (objectName.equals(refName))\r
-               fw.writer.println("      addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+secondaryClassName+".class);");\r
-               else // FIXME : type name may not be correct\r
-               fw.writer.println("      addRelationTypeWriter("+ontShort+ getName(parent)+"_has"+refName +", " +ontShort+primaryClassName +", "+secondaryClassName+".class);");\r
-               fw.delayedWriter2.println("   public static class " + secondaryClassName +" extends " + primaryClassName +"{");\r
-               fw.delayedWriter2.println("      public "+ secondaryClassName +"(ReadGraph graph){");\r
-               fw.delayedWriter2.println("         super(graph);");\r
-               fw.delayedWriter2.println("      }");\r
-               fw.delayedWriter2.println("      ");\r
-               fw.delayedWriter2.println("      @Override");\r
-               fw.delayedWriter2.println("      public java.lang.String getElementId() {");\r
-               fw.delayedWriter2.println("         return \"" + refName +"\";");\r
-               fw.delayedWriter2.println("      }");\r
-               fw.delayedWriter2.println("   }");\r
-               } else { //referenceType == RefType.Reference\r
-               fw.writer.println("        addWriter("+primaryClassName+".class);");\r
-               if (!primaryClassName.equals(secondaryClassName))\r
-               fw.writer.println("        addWriter("+secondaryClassName+".class);");\r
-               }\r
-//                     fw.delayedWriter.println("         if (child.getElementParser() instanceof "+refClassName+"){");\r
-//                     fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
-               if (useElementList) {\r
-\r
-               // element type specific list\r
-               fw.delayedWriter.println("      {");\r
-               fw.delayedWriter.println("         org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
-               fw.delayedWriter.println("         if (list != null) {");\r
-               fw.delayedWriter.println("            java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");\r
-               fw.delayedWriter.println("            result.addAll(l);");\r
-               fw.delayedWriter.println("         } else {");\r
-               fw.delayedWriter.println("            result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
-               fw.delayedWriter.println("         }");\r
-               fw.delayedWriter.println("      }");\r
-               } else {\r
-               fw.delayedWriter.println("      result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
-               }\r
-//                     if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
-//                     // generic list\r
-//                     fw.delayedWriter.println("            {");\r
-//                     fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");\r
-//                     fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\r
-//                     fw.delayedWriter.println("               if (list == null) {");\r
-//                     fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
-//                     fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");\r
-//                     fw.delayedWriter.println("               } else {");\r
-//                     fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
-//                     fw.delayedWriter.println("               }");\r
-//                     fw.delayedWriter.println("            }");\r
-//                     }\r
-               \r
-//                     fw.delayedWriter.println("            return true;");\r
-//                     fw.delayedWriter.println("         }");\r
-               \r
-       }\r
-       \r
-       @Override\r
-       protected void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName) {\r
-               FileWriter fw = getWriter(parent);\r
-               String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());\r
-               String typeURI = ontologyClassName != null ? ontologyClassName + ".URIs." + getName(base.getSimpleType(typeName)) : "null";\r
-               \r
-               fw.writer.println("      addRelationWriter("+ ontShort +getName(parent) + "_has"+refName+", "+getName(parent) +"_" +refName+".class);");\r
-               \r
-               fw.delayedWriter2.println("   public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementWriter {");\r
-               fw.delayedWriter2.println("      public "+ getName(parent) +"_" +refName +"(){");\r
-               fw.delayedWriter2.println("         super(\""+refName+"\", " + typeURI + ", " + typeEntry.binding+");");\r
-               fw.delayedWriter2.println("      }\n");\r
-               fw.delayedWriter2.println("      @Override");\r
-               fw.delayedWriter2.println("      public String decode(Object value) {");\r
-               fw.delayedWriter2.println("         return " + typeEntry.stringPrefix + "(" + typeEntry.javaType + ")value" + typeEntry.stringPostfix + ";");\r
-               fw.delayedWriter2.println("      }");\r
-               fw.delayedWriter2.println("   }");\r
-       }\r
-       \r
-       @Override\r
-       protected void createElementIndicator(SchemaObject parent, boolean useElementList, String refName, String className,\r
-                       boolean useOriginalList) {\r
-               FileWriter fw = getWriter(parent);\r
-               //if (!reference)\r
-               fw.writer.println("        addTypeWriter("+ ontShort+className +", "+className+".class);");\r
-//             else\r
-//             fw.writer.println("        addWriter("+className+".class);");\r
-               \r
-//             fw.delayedWriter.println("         if (child.getElementParser() instanceof "+className+"){");\r
-//             fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
-               if (useElementList) {\r
-                       \r
-               // element type specific list\r
-               fw.delayedWriter.println("            {");\r
-               fw.delayedWriter.println("               org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
-               fw.delayedWriter.println("               if (list != null) {");\r
-               fw.delayedWriter.println("                  java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");\r
-               fw.delayedWriter.println("                  result.addAll(l);");\r
-               fw.delayedWriter.println("               } else {");\r
-               fw.delayedWriter.println("                  result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
-               fw.delayedWriter.println("               }");\r
-               fw.delayedWriter.println("            }");\r
-               } else {\r
-               fw.delayedWriter.println("         result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
-               }\r
-//             if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
-//             // generic list\r
-//             fw.delayedWriter.println("            {");\r
-//             fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");\r
-//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\r
-//             fw.delayedWriter.println("               if (list == null) {");\r
-//             fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
-//             fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");\r
-//             fw.delayedWriter.println("               } else {");\r
-//             fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
-//             fw.delayedWriter.println("               }");\r
-//             fw.delayedWriter.println("            }");\r
-//             }\r
-//             \r
-//             fw.delayedWriter.println("            return true;");\r
-//             fw.delayedWriter.println("         }");\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) {          \r
-               // generates overriding method that allows writing any element\r
-               FileWriter fw = getWriter(parent);\r
-               fw.delayedWriter2.println("   @Override");\r
-               fw.delayedWriter2.println("   public Class<? extends org.simantics.xml.sax.base.XMLElementWriter> getWriter(ReadGraph graph, java.util.Map<Resource, org.simantics.xml.sax.base.XMLElementWriter> writers, WriterElement child) throws DatabaseException{");\r
-               fw.delayedWriter2.println("      Class<? extends org.simantics.xml.sax.base.XMLElementWriter> writerClass = super.getWriter(graph, writers, child);");\r
-               fw.delayedWriter2.println("      if (writerClass != null) return writerClass;");\r
-               fw.delayedWriter2.println("      Resource type = graph.getSingleType(child.instance);");\r
-               fw.delayedWriter2.println("      org.simantics.xml.sax.base.XMLElementWriter writer = writers.get(type);");\r
-               fw.delayedWriter2.println("      if (writer != null) return writer.getClass();");\r
-               fw.delayedWriter2.println("      return null;");\r
-               fw.delayedWriter2.println("   }");\r
-       }\r
-\r
-       @Override       \r
-       public void handle(SchemaObject parent, Attribute attribute) {\r
-               if (parent == null)\r
-                       return;\r
-               String name = attribute.getName();\r
-               QName primitiveType = attribute.getType();\r
-               SimpleType simpleType = attribute.getSimpleType();\r
-               QName ref = attribute.getRef();\r
-               \r
-               String relationName;\r
-               String attrName;\r
-               if (name != null) {\r
-                       attrName = name;\r
-                       relationName = ontShort+"has"+name;\r
-                       if (parent != null)\r
-                               relationName = ontShort+getName(parent)+"_has"+name;\r
-               }\r
-               else if (ref != null && parent != null) {\r
-                       attrName = ref.getLocalPart();\r
-                       relationName = ontShort+getName(parent)+"_has"+ref.getLocalPart();\r
-                       \r
-                       Attribute referred = base.getRefAttribute(ref);\r
-                       if (referred != null) {\r
-                               primitiveType = referred.getType();\r
-                               simpleType = referred.getSimpleType();\r
-                       }\r
-                       \r
-               } else {\r
-                       throw new RuntimeException();\r
-               }\r
-               boolean isReference = false;\r
-               if (provider!= null && provider.getAttribute().getName().equals(attrName))\r
-                       isReference = true;\r
-               \r
-               FileWriter fw = getWriter(parent);\r
-               if (primitiveType != null) {\r
-                       \r
-                       //String binding = getBindingFromPrimitiveType(primitiveType);\r
-                       TypeEntry binding = base.getTypeEntry(primitiveType);\r
-                       \r
-                       if (binding != null) {\r
-                               writeAttribute(fw, attrName, relationName, binding, isReference);\r
-                               return;\r
-                   } else {\r
-                       if (simpleType == null) {\r
-                               SchemaObject simpleTypeObj = base.getSimpleType(primitiveType);\r
-                               if (simpleTypeObj != null)\r
-                                       simpleType = simpleTypeObj.getSimpleType();\r
-                       }       \r
-                   }\r
-               } \r
-               if (simpleType != null) {\r
-                       org.w3._2001.xmlschema.List list = simpleType.getList();\r
-                       if (list != null) {\r
-                               TypeEntry binding = base.getTypeEntry(new QName(SchemaConversionBase.SCHEMA_NS, "string"));\r
-                               writeAttribute(fw, attrName, relationName, binding, isReference);\r
-                       } else {\r
-                               Restriction restriction = simpleType.getRestriction();\r
-                               if (restriction == null)\r
-                                       throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()+ ", SimpleType restriction is unset");\r
-                               QName base = restriction.getBase();\r
-                               \r
-                               \r
-                               //String binding = getBindingFromPrimitiveType(base);\r
-                               TypeEntry binding = this.base.getTypeEntry(base);\r
-                               writeAttribute(fw, attrName, relationName, binding, isReference);\r
-                       }\r
-               } else {\r
-                       // TODO : using default String attribute should be configured with rules.\r
-                       //throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());\r
-                       fw.writer.println("    //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");\r
-                       //writeAttribute(fw, attrName, relationName, "STRING", isReference);\r
-                       writeAttribute(fw, attrName, relationName, base.getTypeEntry("string"), isReference);\r
-               }\r
-       }\r
-       \r
-       private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {\r
-               fw.writer.println("      {");\r
-               fw.writer.println("         if (attribute.getPredicate().equals("+relationName+")) {"); \r
-               fw.writer.println("            writer.writeAttribute(\""+attrName+"\", " + binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");\r
-       //      fw.writer.println("            graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");\r
-       //      if (isReference)\r
-       //      fw.writer.println("            idProviderValue = a.getValue();");       \r
-               fw.writer.println("         }");\r
-               fw.writer.println("      }");\r
-       }\r
-       \r
-       @Override\r
-       public void handleAttributes(SchemaObject simpleTypeObj) {\r
-               SchemaObject parent = simpleTypeObj.getParent();\r
-               FileWriter fw = getWriter(parent);\r
-               \r
-               SimpleType simpleType = simpleTypeObj.getSimpleType();\r
-               Restriction restriction = simpleType.getRestriction();\r
-               if (restriction == null)\r
-                       throw new RuntimeException("Cannot resolve type for Element " + getName(parent));\r
-               QName base = restriction.getBase();\r
-               \r
-               \r
-               //String binding = getBindingFromPrimitiveType(base);\r
-               TypeEntry binding = this.base.getTypeEntry(base);\r
-               \r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
-               fw.writer.println("            writer.writeCharacters("+ binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");\r
-//             fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
-               fw.writer.println("   }");\r
-       }\r
-       \r
-       @Override\r
-       public void handle(SchemaObject parent, AttributeGroup attribute) {\r
-               if (parent != null) {\r
-                       FileWriter fw = getWriter(parent);\r
-                       NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef());\r
-                       fw.writer.println(commentTag+"    AttributeGroup " + group.getName());\r
-                       SchemaObject obj = new SchemaObject(parent,attribute);\r
-                       for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
-                               if (annotated instanceof Attribute) {\r
-                                       //handle("AttributeGroups_"+group.getName(),(Attribute)annotated);\r
-                                       handle(obj,(Attribute)annotated);\r
-                               } else if (annotated instanceof AttributeGroup) {\r
-                                       //handle("AttributeGroups_"+group.getName(),(AttributeGroup)annotated);\r
-                                       handle(obj,(AttributeGroup)annotated);\r
-                               }\r
-                       }\r
-                       fw.writer.println(commentTag+"    End of AttributeGroup " + group.getName());\r
-               }\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
-               FileWriter fw = getWriter(parent);\r
-               QName type = new QName(SchemaConversionBase.CONVERSION_NS, composition.getType());\r
-               TypeEntry typeEntry = this.base.getTypeEntry(type);\r
-               String arrayBinding = typeEntry.binding;//getBindingFromPrimitiveType(type);\r
-               String javaType = typeEntry.javaType;//getJavaTypeFromPrimitiveType(type);\r
-               String name = composition.getName();\r
-               \r
-               String relationName;\r
-               if (name != null) {\r
-                       relationName = ontShort+"has"+name;\r
-                       if (parent != null)\r
-                               relationName = ontShort+getName(parent)+"_has"+name;\r
-               } else {\r
-                       throw new RuntimeException();\r
-               }\r
-               fw.writer.println("      if (attribute.getPredicate().equals("+relationName+")) {");\r
-               fw.writer.println("            "+javaType+" value = ("+javaType+")graph.getValue(attribute.getObject(),"+arrayBinding+");");\r
-               //fw.writer.println("            writer.writeAttribute("+attrName+", graph.getValue(attribute.getObject(),"+binding.binding+").toString());");\r
-\r
-               int i = 0;\r
-               for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute())\r
-               fw.writer.println("            writer.writeAttribute(\""+a.getName()+"\","+typeEntry.getElementToString("value["+(i++)+"]")+");");\r
-               //fw.writer.println("            writer.writeAttribute(\""+a.getName()+"\",value["+(i++)+"].toString());");\r
-//             fw.writer.println("         Attribute a"+(i++)+" = element.getAttribute(\"" +a.getName()+"\");");\r
-//             fw.writer.print  ("         "+javaType + " value = new "+javaType+"{");\r
-               i = 0;\r
-               // FIXME : handle optional attributes properly.\r
-//             for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute()) {\r
-//                     Attribute attribute = ((Attribute)attributes.getRight(a));\r
-//                     //QName atype = getBaseType(attribute);\r
-//                     QName atype = getPrimitiveType(attribute);\r
-//                     String defaultValue = attribute.getDefault();\r
-//                     if (defaultValue == null)\r
-//                         defaultValue = getDefaultValue(atype);\r
-//                             \r
-//                     //String binding = getBindingFromPrimitiveType(atype);\r
-//                     TypeEntry binding = getTypeEntry(atype);\r
-//                     if (i > 0)\r
-//                             fw.writer.print(",");\r
-//                     if (defaultValue != null)\r
-//                             fw.writer.print("a"+(i)+"!= null ? "+ getValueGetterMethod(binding,"a"+(i++)) + " : " +defaultValue);\r
-//                     else\r
-//                             fw.writer.print(getValueGetterMethod(binding,"a"+(i++)));\r
-//             }\r
-//             fw.writer.println("};");\r
-//             fw.writer.println("         graph.claimLiteral(element.getData(),"+relationName+", value, "+arrayBinding+");");\r
-               fw.writer.println("      }");\r
-               \r
-       }\r
-       \r
-       protected String getDefaultValue(QName atype) {\r
-               Map<String,TypeEntry> types = this.base.typeMap.get(atype.getNamespaceURI());\r
-               if (types == null)\r
-                       return null;\r
-               TypeEntry entry =  types.get(atype.getLocalPart());\r
-               if (entry == null)\r
-                       return null;\r
-               return entry.defaultValue;\r
-       }\r
-       \r
-       IDProvider provider;\r
-       @Override\r
-       public void handleElement(SchemaObject elementObj)  {\r
-               Element element = elementObj.getElement();\r
-               \r
-               String name = getName(elementObj);//topLevelElement.getName();\r
-               String className = name;\r
-               \r
-               FileWriter fw = new FileWriter();\r
-               try {\r
-                       fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));\r
-               } catch (IOException e) {\r
-                       throw new RuntimeException(e);\r
-               }\r
-               writers.put(elementObj, fw);\r
-               boolean isList = false;\r
-               \r
-               Inheritance inheritance = this.base.getInheritance(elementObj); \r
-               \r
-               provider = this.base.getIDProvider(element);\r
-               List<IDReference> references = this.base.getIDReferences(element);\r
-               UnrecognizedChildElement unknownChildElement = this.base.getUnknown(element);\r
-\r
-//             List<String> intrerfaces = new ArrayList<String>();\r
-//             if (references.size() > 0)\r
-//                     intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");\r
-//             if (unknownChildElement != null)\r
-//                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
-\r
-               createClassHeader(fw.writer);\r
-               writeClass(fw.writer,false, element.getName(), className, inheritance.baseClass, Collections.EMPTY_LIST);\r
-//             writeIDProvider(fw.writer);\r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public Resource getType(ReadGraph graph) throws DatabaseException {");\r
-               fw.writer.println("      "+getOntologyImport());\r
-               fw.writer.println("      return "+ontShort+name+";");\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
-               \r
-//             fw.writer.println("   @Override");\r
-//             fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
-//             fw.writer.println("      "+getOntologyImport());\r
-//             fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(elementObj,"has")+", element.getData());");\r
-//             fw.writer.println("      return true;");\r
-//             fw.writer.println("   }");\r
-//             fw.writer.println();\r
-               LocalComplexType complexType = element.getComplexType();\r
-               LocalSimpleType simpleType = element.getSimpleType();\r
-               \r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");\r
-               if (inheritance.type == InheritanceType.ComplexType) {\r
-               fw.writer.println("        super.attributes(graph,instance,attributes,writer);");\r
-               }\r
-               fw.writer.println("        "+getOntologyImport());\r
-               fw.writer.println("        for (Statement attribute : attributes) {");\r
-               if (complexType != null) {\r
-                       SchemaObject obj = this.base.getComplexType(complexType);\r
-                       this.base.handleElementComplexTypeAttributes(obj);\r
-               } \r
-               fw.writer.println("        }");\r
-               fw.writer.println("   }");\r
-               \r
-               \r
-//             fw.writer.println("   @Override");\r
-//             fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
-//             if (inhertiance.type == InheritanceType.ComplexType) {\r
-//             fw.writer.println("             super.configure(graph,parents,element);");\r
-//             }\r
-//             fw.writer.println("        "+getOntologyImport());\r
-//             \r
-//             LocalComplexType complexType = element.getComplexType();\r
-//             LocalSimpleType simpleType = element.getSimpleType();\r
-//             \r
-//             if (complexType != null) {\r
-//                     SchemaObject obj = complexTypes.get(complexType);\r
-//                     handleElementComplexTypeAttributes(obj);\r
-//             } \r
-//             fw.writer.println("   }");\r
-               \r
-               if (inheritance.type == InheritanceType.AtomicType) {\r
-               fw.writer.println();\r
-//             fw.writer.println("   @Override");\r
-//             fw.writer.println("   public void configure(WriteGraph graph, ParserElement element, java.lang.String string) throws DatabaseException {");\r
-//             fw.writer.println("      graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");\r
-//             fw.writer.println("   }");\r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
-               fw.writer.println("            writer.writeCharacters("+inheritance.atomicType.getToString("graph.getValue(instance.getResource(),"+inheritance.atomicType.binding+")")+");");\r
-//             fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
-               fw.writer.println("   }");\r
-               }\r
-//             if (simpleType != null) {\r
-//                     SchemaObject obj = simpleTypes.get(simpleType);\r
-//                     handleElementSimpleTypeAttributes(obj);\r
-//             }\r
-               \r
-               \r
-               StringWriter stringWriter = new StringWriter();\r
-               fw.delayedWriter = new PrintWriter(stringWriter);\r
-               StringWriter stringWriter2 = new StringWriter();\r
-               fw.delayedWriter2 = new PrintWriter(stringWriter2);\r
-               \r
-               fw.writer.println("   public " + className + "(ReadGraph graph) {");\r
-               fw.writer.println("      super(graph);");\r
-               fw.writer.println("      "+getOntologyImport());\r
-               if (complexType != null) {\r
-                       SchemaObject obj = this.base.getComplexType(complexType);\r
-                       this.base.handleComplexTypeExtension(obj);\r
-               } else if (simpleType != null) {\r
-                       \r
-               }\r
-               \r
-               fw.writer.println("   }");\r
-               \r
-               fw.writer.println("   @Override");\r
-               fw.writer.println("   public void children(ReadGraph graph, WriterElement instance, java.util.Set<org.simantics.db.Resource> result) throws XMLStreamException, DatabaseException {");\r
-               fw.writer.println("      "+getOntologyImport());\r
-               \r
-               if (stringWriter.getBuffer().length() > 0) {\r
-                       fw.writer.write(stringWriter.toString());\r
-               }\r
-               \r
-               if (inheritance.type == InheritanceType.ComplexType) {\r
-               fw.writer.println("      super.children(graph,instance,result);");\r
-               }\r
-               \r
-               fw.writer.println("   }");\r
-               fw.writer.println();\r
-                               \r
-               if (stringWriter2.getBuffer().length() > 0) {\r
-                       fw.writer.write(stringWriter2.toString());\r
-               }\r
-               \r
-               stringWriter = null;\r
-               fw.delayedWriter.close();\r
-               fw.delayedWriter = null;\r
-               stringWriter2 = null;\r
-               fw.delayedWriter2.close();\r
-               fw.delayedWriter2 = null;\r
-               \r
-//             writeIDReferences(fw.writer,name, references);\r
-//             writeUnknownChild(fw.writer,name,unknownChildElement);\r
-\r
-               fw.writer.println("}");\r
-               fw.writer.println();\r
-               fw.writer.flush();\r
-               fw.writer.close();\r
-               fw.writer = null;\r
-               writers.remove(elementObj);\r
-               provider = null;\r
-               \r
-               ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);\r
-       }\r
-       \r
-       \r
-//     private void writeIDProvider(PrintWriter writer) {\r
-//             if (provider != null) {\r
-//             writer.println("   java.lang.String idProviderValue = null;");\r
-//             writer.println();\r
-//             writer.println("   @Override");\r
-//             writer.println("   public java.lang.String getID() {");\r
-//             writer.println("        java.lang.String s = idProviderValue;");\r
-//             writer.println("        idProviderValue = null;");\r
-//             writer.println("        return s;");\r
-//             writer.println("   }");\r
-//             writer.println();\r
-//             if (provider.getPriority() != null) {\r
-//             writer.println("   @Override");\r
-//             writer.println("   public int idPriority() {");\r
-//             writer.println("        return " + provider.getPriority().intValue()+";");\r
-//             writer.println("   }"); \r
-//             }\r
-//             }\r
-//     }\r
-//     \r
-//     private void writeIDReferences(PrintWriter writer,String name, List<IDReference> references) {\r
-//             if (references.size() > 0) {\r
-//             writer.println("   @Override");\r
-//             writer.println("   public boolean connectReferences(WriteGraph graph, ParserElement element, java.util.Map<java.lang.String, ParserElement> map) throws DatabaseException {");\r
-//             writer.println("      "+getOntologyImport());\r
-//             writer.println("      boolean result = true;");\r
-//             for (IDReference ref : references) {\r
-//             writer.println("      {");\r
-//             writer.println("         Attribute a = element.getAttribute(\"" + ref.getIDSource().getName() +"\");");\r
-//             writer.println("         if (a != null) {");\r
-//             writer.println("            ParserElement refEle = map.get(a.value);");\r
-//             writer.println("            if (refEle != null) {");\r
-//             writer.println("               Resource ref = refEle.getData();");\r
-//             writer.println("               graph.claim(element.getData(), "+ontShort+name+"_"+ref.getReference().getName()+", ref);");\r
-//             writer.println("            } else {");\r
-//             writer.println("               result = false;");\r
-//             writer.println("            }");\r
-//             writer.println("         }");\r
-//             writer.println("      }");\r
-//             }\r
-//             writer.println("      return result;");\r
-//             writer.println("   }");\r
-//             writer.println();\r
-//             }\r
-//     }\r
-       \r
-//     private void writeUnknownChild(PrintWriter writer,String name, UnrecognizedChildElement unknownChildElement) {\r
-//             if (unknownChildElement == null)\r
-//                     return;\r
-//             \r
-//             writer.println("   @Override");\r
-//             writer.println("   public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException {");\r
-//             writer.println("    " + unknownChildElement.getJavaMethod());\r
-//             writer.println("   }");\r
-//             writer.println();\r
-//             \r
-//     }\r
-       \r
-       protected void createClassHeader(PrintWriter writer) {\r
-               writer.println("package " + converter.getPluginName() +"."+elementPackageName+";");\r
-               writer.println();\r
-               writer.println("import org.simantics.databoard.Bindings;");\r
-               writer.println("import org.simantics.db.Resource;");\r
-               writer.println("import org.simantics.db.ReadGraph;");\r
-               writer.println("import org.simantics.db.Statement;");\r
-               writer.println("import org.simantics.db.exception.DatabaseException;");\r
-               writer.println("import org.simantics.xml.sax.base.WriterElement;");\r
-               writer.println("import org.simantics.xml.sax.ontology.XMLResource;");\r
-               writer.println("import java.util.Collection;");\r
-               writer.println("import javax.xml.stream.XMLStreamException;");\r
-               writer.println("import javax.xml.stream.XMLStreamWriter;");\r
-//             if (!isList) {\r
-//             writer.println("import org.simantics.layer0.Layer0;");\r
-//         } else {\r
-//         writer.println("import java.util.Collections;");\r
-//             writer.println("import org.simantics.db.common.utils.ListUtils;");\r
-//             }\r
-               writer.println();\r
-       }\r
-       \r
-\r
-\r
-}\r
+package org.simantics.xml.sax;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.simantics.utils.datastructures.BijectionMap;
+import org.simantics.xml.sax.SchemaConversionBase.Inheritance;
+import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;
+import org.simantics.xml.sax.SchemaConversionBase.RefType;
+import org.simantics.xml.sax.SchemaConversionBase.TypeEntry;
+import org.simantics.xml.sax.SchemaObject.ObjectType;
+import org.simantics.xml.sax.configuration.AttributeComposition;
+import org.simantics.xml.sax.configuration.IDProvider;
+import org.simantics.xml.sax.configuration.IDReference;
+import org.simantics.xml.sax.configuration.UnrecognizedChildElement;
+import org.w3._2001.xmlschema.Annotated;
+import org.w3._2001.xmlschema.Attribute;
+import org.w3._2001.xmlschema.AttributeGroup;
+import org.w3._2001.xmlschema.ComplexType;
+import org.w3._2001.xmlschema.Element;
+import org.w3._2001.xmlschema.LocalComplexType;
+import org.w3._2001.xmlschema.LocalSimpleType;
+import org.w3._2001.xmlschema.NamedAttributeGroup;
+import org.w3._2001.xmlschema.NamedGroup;
+import org.w3._2001.xmlschema.Restriction;
+import org.w3._2001.xmlschema.SimpleType;
+
+public class ExporterGenerator extends JavaGenerator{
+       
+       public ExporterGenerator(SchemaConverter converter, SchemaConversionBase base) {
+               super(converter, base);
+       }
+
+       public void createParser() throws IOException {
+               
+               String parserPackagePostfix = "_exp";
+               String importerClassPostfix = "Exporter";
+               String parserClassPostfix = "Writer";
+               elementPackageName = name+parserPackagePostfix;
+               
+               importParserDir= new File(converter.getParserDir().getAbsolutePath()+"/"+elementPackageName);
+               if (!importParserDir.exists())
+                       importParserDir.mkdirs();
+               
+               base.handle(this);
+               // Create Importer class
+               File importerFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+importerClassPostfix+".java");
+               PrintWriter mainWriter = createFile(importerFile);
+               mainWriter.println("package " + converter.getPluginName() +";");
+               mainWriter.println();
+               mainWriter.println("import java.io.File;");
+               mainWriter.println("import org.simantics.db.Resource;");
+               mainWriter.println("import org.simantics.db.Session;");
+               mainWriter.println("import org.simantics.db.exception.DatabaseException;");
+               mainWriter.println("import org.simantics.xml.sax.base.AbstractExporter;");
+               mainWriter.println();
+               mainWriter.println("public class " + name + importerClassPostfix+" extends AbstractExporter {");
+               mainWriter.println();
+               mainWriter.println("   public " + name + importerClassPostfix+"(Session session, File file, Resource root) throws DatabaseException {");
+               mainWriter.println("      super(session, file, root);");
+               mainWriter.println("      setXmlWriter(new "+name + parserClassPostfix+"(session));");
+               mainWriter.println("   }");
+               mainWriter.println();
+               mainWriter.println("}");
+               
+               mainWriter.println();
+               mainWriter.flush();
+               mainWriter.close();
+               
+               // Create Parser class
+               File parserFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+parserClassPostfix+".java");
+               mainWriter = createFile(parserFile);
+               mainWriter.println("package " + converter.getPluginName() +";");
+               mainWriter.println();
+               mainWriter.println("import org.simantics.xml.sax.base.XMLWriter;");
+               mainWriter.println("import org.simantics.db.ReadGraph;");
+               mainWriter.println("import org.simantics.db.Session;");
+               mainWriter.println("import org.simantics.db.exception.DatabaseException;");
+               mainWriter.println("import org.simantics.db.common.request.ReadRequest;");
+               mainWriter.println();
+               mainWriter.println("public class " + name + parserClassPostfix+" extends XMLWriter {");
+               mainWriter.println();
+               mainWriter.println("   public " + name + parserClassPostfix+"(Session session) throws DatabaseException {");
+               if (schema.getTargetNamespace() != null)
+               mainWriter.println("      setSchemaURI(\""+schema.getTargetNamespace()+"\");");
+               mainWriter.println("      setOntologyURI(\""+ontologyUri+"\");");
+               mainWriter.println("      session.syncRequest(new ReadRequest() {");
+               mainWriter.println("        @Override");
+               mainWriter.println("        public void run(ReadGraph graph) throws DatabaseException {");
+               mainWriter.println("          setGraph(graph);");
+               for (String s : ruleClassNames) {
+               mainWriter.println("          add(new "+s+"(graph));");
+               }
+               mainWriter.println("        }");
+               mainWriter.println("      });");
+               mainWriter.println("   }");
+               mainWriter.println("}");
+               
+               mainWriter.println();
+               mainWriter.flush();
+               mainWriter.close();
+       }
+       
+//     @Override
+//     protected void handle(TopLevelAttribute topLevelAttribute) {
+//
+//     }
+       
+       @Override
+       public String getBaseClass(ObjectType type) {
+               return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";
+       }
+       
+       @Override
+       public void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {
+       }
+       
+       @Override
+       public void handle(SchemaObject parent, NamedGroup attribute) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void handleComplexType(SchemaObject complexTypeObj) {
+               ComplexType topLevelComplexType = complexTypeObj.getComplexType();
+               
+               String name = getName(complexTypeObj);
+               
+               String className = name;//"_"+name;
+               
+               FileWriter fw = new FileWriter();
+               try {
+                       fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));
+               } catch (IOException e) {
+                       throw new RuntimeException(e);
+               }
+               writers.put(complexTypeObj, fw);
+
+//             String baseClass = getBaseClass(ObjectType.COMPLEX_TYPE);
+//             
+//             boolean inherited = false;
+               
+//             QName type = getComplexTypeBase(topLevelComplexType);
+//             if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {
+//                     SchemaObject obj = complexTypeName.get(type.getLocalPart());
+////                   if (obj == null)
+////                           obj = simpleTypeName.get(type.getLocalPart());
+//                     if (obj != null) {
+//                             baseClass = getName(obj);
+//                             inherited = true;
+//                     }
+//             }
+               Inheritance inheritance = base.getInheritance(complexTypeObj);
+               
+               provider = base.getIDProvider(topLevelComplexType);
+//             List<IDReference> references = getIDReferences(topLevelComplexType);
+//             UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);
+
+//             List<String> intrerfaces = new ArrayList<String>();
+//             if (references.size() > 0)
+//                     intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");
+//             if (unknownChildElement != null)
+//                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");
+               
+               createClassHeader(fw.writer);
+               writeClass(fw.writer,false, topLevelComplexType.getName(), className, inheritance.baseClass, Collections.EMPTY_LIST);
+                       
+//             writeIDProvider(fw.writer);
+       
+               fw.writer.println("   @Override");
+               fw.writer.println("   public Resource getType(ReadGraph graph) throws DatabaseException {");
+               fw.writer.println("      "+getOntologyImport());
+               fw.writer.println("      return "+ontShort+name+";");
+               fw.writer.println("   }");
+               fw.writer.println();
+               
+//             fw.writer.println("   @Override");
+//             fw.writer.println("   public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");
+//             fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");
+//             fw.writer.println("      "+getOntologyImport());
+//             if (!isList) {
+//             fw.writer.println("      Resource res = graph.newResource();");
+//             fw.writer.println("      graph.claim(res, L0.InstanceOf, "+ontShort+name+");");
+//             } else {
+//             fw.writer.println("      Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");
+//             }
+//             fw.writer.println("      return res;");
+//             fw.writer.println("   }");
+//             fw.writer.println();
+               
+//             fw.writer.println("   @Override");
+//             fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");
+//             fw.writer.println("      "+getOntologyImport());
+//             fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(complexTypeObj,"has")+", element.getData());");
+//             fw.writer.println("      return true;");
+//             fw.writer.println("   }");
+//             fw.writer.println();
+                               
+               StringWriter stringWriter = new StringWriter();
+               fw.delayedWriter = new PrintWriter(stringWriter);
+               StringWriter stringWriter2 = new StringWriter();
+               fw.delayedWriter2 = new PrintWriter(stringWriter2);
+               
+               fw.writer.println("   public " + className + "(ReadGraph graph) {");
+               fw.writer.println("      super(graph);");
+               fw.writer.println("      "+getOntologyImport());
+               
+               base.handleComplexTypeExtension(complexTypeObj);
+               
+               fw.writer.println("   }");
+               
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void children(ReadGraph graph, WriterElement instance, java.util.Set<org.simantics.db.Resource> result) throws XMLStreamException, DatabaseException {");
+               fw.writer.println("      "+getOntologyImport());
+               
+               if (stringWriter.getBuffer().length() > 0) {
+                       fw.writer.write(stringWriter.toString());
+               }
+               if (inheritance.type == InheritanceType.ComplexType)
+               fw.writer.println("      super.children(graph,instance,result);");
+               fw.writer.println("   }");
+               fw.writer.println();
+               
+               if (stringWriter2.getBuffer().length() > 0) {
+                       fw.writer.write(stringWriter2.toString());
+               }
+               
+               stringWriter = null;
+               fw.delayedWriter.close();
+               fw.delayedWriter=null;
+               stringWriter2 = null;
+               fw.delayedWriter2.close();
+               fw.delayedWriter2 = null;
+               
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");
+               if (inheritance.type == InheritanceType.ComplexType) {
+               fw.writer.println("             super.attributes(graph,instance,attributes,writer);");
+               }
+               fw.writer.println("        "+getOntologyImport());
+               fw.writer.println("        for (Statement attribute : attributes) {");
+               base.handleComplexTypeAttributes(complexTypeObj);
+               base.handleExtensionAttributes(complexTypeObj);
+               fw.writer.println("        }");
+               fw.writer.println("   }");
+               
+               if (inheritance.type == InheritanceType.AtomicType) {
+               fw.writer.println();
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");
+               fw.writer.println("            writer.writeCharacters("+inheritance.atomicType.getToString("graph.getValue(instance.getResource(),"+inheritance.atomicType.binding+")")+");");
+               fw.writer.println("   }");
+               }
+               
+//             writeIDReferences(fw.writer,name, references);
+//             writeUnknownChild(fw.writer,name,unknownChildElement);
+               
+               fw.writer.println("}");
+               fw.writer.println();
+               fw.writer.flush();
+               fw.writer.close();
+               fw.writer = null;
+               writers.remove(complexTypeObj);
+               provider = null;
+       }
+       
+       @Override
+       protected void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName,
+                       String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList) {
+               FileWriter fw = getWriter(parent);
+               if ("TextOrField".equals(refName))
+                       System.out.println();
+               if (referenceType == RefType.Type) {
+               // create internal class for handling the element and child attachment
+               secondaryClassName = getName(parent) +"_" +objectName;
+               if (objectName.equals(refName))
+               fw.writer.println("      addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+secondaryClassName+".class);");
+               else // FIXME : type name may not be correct
+               fw.writer.println("      addRelationTypeWriter("+ontShort+ getName(parent)+"_has"+refName +", " +ontShort+primaryClassName +", "+secondaryClassName+".class);");
+               fw.delayedWriter2.println("   public static class " + secondaryClassName +" extends " + primaryClassName +"{");
+               fw.delayedWriter2.println("      public "+ secondaryClassName +"(ReadGraph graph){");
+               fw.delayedWriter2.println("         super(graph);");
+               fw.delayedWriter2.println("      }");
+               fw.delayedWriter2.println("      ");
+               fw.delayedWriter2.println("      @Override");
+               fw.delayedWriter2.println("      public java.lang.String getElementId() {");
+               fw.delayedWriter2.println("         return \"" + refName +"\";");
+               fw.delayedWriter2.println("      }");
+               fw.delayedWriter2.println("   }");
+               } else { //referenceType == RefType.Reference
+               fw.writer.println("        addWriter("+primaryClassName+".class);");
+               if (!primaryClassName.equals(secondaryClassName))
+               fw.writer.println("        addWriter("+secondaryClassName+".class);");
+               }
+//                     fw.delayedWriter.println("         if (child.getElementParser() instanceof "+refClassName+"){");
+//                     fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");
+               if (useElementList) {
+
+               // element type specific list
+               fw.delayedWriter.println("      {");
+               fw.delayedWriter.println("         org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
+               fw.delayedWriter.println("         if (list != null) {");
+               fw.delayedWriter.println("            java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");
+               fw.delayedWriter.println("            result.addAll(l);");
+               fw.delayedWriter.println("         } else {");
+               fw.delayedWriter.println("            result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");
+               fw.delayedWriter.println("         }");
+               fw.delayedWriter.println("      }");
+               } else {
+               fw.delayedWriter.println("      result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");
+               }
+//                     if (useOriginalList(parent, indicator,element, reference, ref, refType)) {
+//                     // generic list
+//                     fw.delayedWriter.println("            {");
+//                     fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");
+//                     fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
+//                     fw.delayedWriter.println("               if (list == null) {");
+//                     fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+//                     fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");
+//                     fw.delayedWriter.println("               } else {");
+//                     fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+//                     fw.delayedWriter.println("               }");
+//                     fw.delayedWriter.println("            }");
+//                     }
+               
+//                     fw.delayedWriter.println("            return true;");
+//                     fw.delayedWriter.println("         }");
+               
+       }
+       
+       @Override
+       protected void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName) {
+               FileWriter fw = getWriter(parent);
+               String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());
+               String typeURI = ontologyClassName != null ? ontologyClassName + ".URIs." + getName(base.getSimpleType(typeName)) : "null";
+               
+               fw.writer.println("      addRelationWriter("+ ontShort +getName(parent) + "_has"+refName+", "+getName(parent) +"_" +refName+".class);");
+               
+               fw.delayedWriter2.println("   public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementWriter {");
+               fw.delayedWriter2.println("      public "+ getName(parent) +"_" +refName +"(){");
+               fw.delayedWriter2.println("         super(\""+refName+"\", " + typeURI + ", " + typeEntry.binding+");");
+               fw.delayedWriter2.println("      }\n");
+               fw.delayedWriter2.println("      @Override");
+               fw.delayedWriter2.println("      public java.lang.String decode(java.lang.Object value) {");
+               fw.delayedWriter2.println("         return " + typeEntry.stringPrefix + "(" + typeEntry.javaType + ")value" + typeEntry.stringPostfix + ";");
+               fw.delayedWriter2.println("      }");
+               fw.delayedWriter2.println("   }");
+       }
+       
+       @Override
+       protected void createElementIndicator(SchemaObject parent, boolean useElementList, String refName, String className,
+                       boolean useOriginalList) {
+               FileWriter fw = getWriter(parent);
+               //if (!reference)
+               fw.writer.println("        addTypeWriter("+ ontShort+className +", "+className+".class);");
+//             else
+//             fw.writer.println("        addWriter("+className+".class);");
+               
+//             fw.delayedWriter.println("         if (child.getElementParser() instanceof "+className+"){");
+//             fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");
+               if (useElementList) {
+                       
+               // element type specific list
+               fw.delayedWriter.println("            {");
+               fw.delayedWriter.println("               org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
+               fw.delayedWriter.println("               if (list != null) {");
+               fw.delayedWriter.println("                  java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");
+               fw.delayedWriter.println("                  result.addAll(l);");
+               fw.delayedWriter.println("               } else {");
+               fw.delayedWriter.println("                  result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");
+               fw.delayedWriter.println("               }");
+               fw.delayedWriter.println("            }");
+               } else {
+               fw.delayedWriter.println("         result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");
+               }
+//             if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {
+//             // generic list
+//             fw.delayedWriter.println("            {");
+//             fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");
+//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
+//             fw.delayedWriter.println("               if (list == null) {");
+//             fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");
+//             fw.delayedWriter.println("               } else {");
+//             fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("               }");
+//             fw.delayedWriter.println("            }");
+//             }
+//             
+//             fw.delayedWriter.println("            return true;");
+//             fw.delayedWriter.println("         }");
+               
+       }
+       
+       @Override
+       public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) {          
+               // generates overriding method that allows writing any element
+               FileWriter fw = getWriter(parent);
+               fw.delayedWriter2.println("   @Override");
+               fw.delayedWriter2.println("   public Class<? extends org.simantics.xml.sax.base.XMLElementWriter> getWriter(ReadGraph graph, java.util.Map<Resource, org.simantics.xml.sax.base.XMLElementWriter> writers, WriterElement child) throws DatabaseException{");
+               fw.delayedWriter2.println("      Class<? extends org.simantics.xml.sax.base.XMLElementWriter> writerClass = super.getWriter(graph, writers, child);");
+               fw.delayedWriter2.println("      if (writerClass != null) return writerClass;");
+               fw.delayedWriter2.println("      Resource type = graph.getSingleType(child.instance);");
+               fw.delayedWriter2.println("      org.simantics.xml.sax.base.XMLElementWriter writer = writers.get(type);");
+               fw.delayedWriter2.println("      if (writer != null) return writer.getClass();");
+               fw.delayedWriter2.println("      return null;");
+               fw.delayedWriter2.println("   }");
+       }
+
+       @Override       
+       public void handle(SchemaObject parent, Attribute attribute) {
+               if (parent == null)
+                       return;
+               String name = attribute.getName();
+               QName primitiveType = attribute.getType();
+               SimpleType simpleType = attribute.getSimpleType();
+               QName ref = attribute.getRef();
+               
+               String relationName;
+               String attrName;
+               if (name != null) {
+                       attrName = name;
+                       relationName = ontShort+"has"+name;
+                       if (parent != null)
+                               relationName = ontShort+getName(parent)+"_has"+name;
+               }
+               else if (ref != null && parent != null) {
+                       attrName = ref.getLocalPart();
+                       relationName = ontShort+getName(parent)+"_has"+ref.getLocalPart();
+                       
+                       Attribute referred = base.getRefAttribute(ref);
+                       if (referred != null) {
+                               primitiveType = referred.getType();
+                               simpleType = referred.getSimpleType();
+                       }
+                       
+               } else {
+                       throw new RuntimeException();
+               }
+               boolean isReference = false;
+               if (provider!= null && provider.getAttribute().getName().equals(attrName))
+                       isReference = true;
+               
+               FileWriter fw = getWriter(parent);
+               if (primitiveType != null) {
+                       
+                       //String binding = getBindingFromPrimitiveType(primitiveType);
+                       TypeEntry binding = base.getTypeEntry(primitiveType);
+                       
+                       if (binding != null) {
+                               writeAttribute(fw, attrName, relationName, binding, isReference);
+                               return;
+                   } else {
+                       if (simpleType == null) {
+                               SchemaObject simpleTypeObj = base.getSimpleType(primitiveType);
+                               if (simpleTypeObj != null)
+                                       simpleType = simpleTypeObj.getSimpleType();
+                       }       
+                   }
+               } 
+               if (simpleType != null) {
+                       org.w3._2001.xmlschema.List list = simpleType.getList();
+                       if (list != null) {
+                               TypeEntry binding = base.getTypeEntry(new QName(SchemaConversionBase.SCHEMA_NS, "string"));
+                               writeAttribute(fw, attrName, relationName, binding, isReference);
+                       } else {
+                               Restriction restriction = simpleType.getRestriction();
+                               if (restriction == null)
+                                       throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()+ ", SimpleType restriction is unset");
+                               QName base = restriction.getBase();
+                               
+                               
+                               //String binding = getBindingFromPrimitiveType(base);
+                               TypeEntry binding = this.base.getTypeEntry(base);
+                               writeAttribute(fw, attrName, relationName, binding, isReference);
+                       }
+               } else {
+                       // TODO : using default String attribute should be configured with rules.
+                       //throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());
+                       fw.writer.println("    //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");
+                       //writeAttribute(fw, attrName, relationName, "STRING", isReference);
+                       writeAttribute(fw, attrName, relationName, base.getTypeEntry("string"), isReference);
+               }
+       }
+       
+       private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {
+               fw.writer.println("      {");
+               fw.writer.println("         if (attribute.getPredicate().equals("+relationName+")) {"); 
+               fw.writer.println("            writer.writeAttribute(\""+attrName+"\", " + binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");
+       //      fw.writer.println("            graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");
+       //      if (isReference)
+       //      fw.writer.println("            idProviderValue = a.getValue();");       
+               fw.writer.println("         }");
+               fw.writer.println("      }");
+       }
+       
+       @Override
+       public void handleAttributes(SchemaObject simpleTypeObj) {
+               SchemaObject parent = simpleTypeObj.getParent();
+               FileWriter fw = getWriter(parent);
+               
+               SimpleType simpleType = simpleTypeObj.getSimpleType();
+               Restriction restriction = simpleType.getRestriction();
+               if (restriction == null)
+                       throw new RuntimeException("Cannot resolve type for Element " + getName(parent));
+               QName base = restriction.getBase();
+               
+               
+               //String binding = getBindingFromPrimitiveType(base);
+               TypeEntry binding = this.base.getTypeEntry(base);
+               
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");
+               fw.writer.println("            writer.writeCharacters("+ binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");
+//             fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");
+               fw.writer.println("   }");
+       }
+       
+       @Override
+       public void handle(SchemaObject parent, AttributeGroup attribute) {
+               if (parent != null) {
+                       FileWriter fw = getWriter(parent);
+                       NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef());
+                       fw.writer.println(commentTag+"    AttributeGroup " + group.getName());
+                       SchemaObject obj = new SchemaObject(parent,attribute);
+                       for (Annotated annotated : group.getAttributeOrAttributeGroup()) {
+                               if (annotated instanceof Attribute) {
+                                       //handle("AttributeGroups_"+group.getName(),(Attribute)annotated);
+                                       handle(obj,(Attribute)annotated);
+                               } else if (annotated instanceof AttributeGroup) {
+                                       //handle("AttributeGroups_"+group.getName(),(AttributeGroup)annotated);
+                                       handle(obj,(AttributeGroup)annotated);
+                               }
+                       }
+                       fw.writer.println(commentTag+"    End of AttributeGroup " + group.getName());
+               }
+               
+       }
+       
+       @Override
+       public void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {
+               FileWriter fw = getWriter(parent);
+               QName type = new QName(SchemaConversionBase.CONVERSION_NS, composition.getType());
+               TypeEntry typeEntry = this.base.getTypeEntry(type);
+               String arrayBinding = typeEntry.binding;//getBindingFromPrimitiveType(type);
+               String javaType = typeEntry.javaType;//getJavaTypeFromPrimitiveType(type);
+               String name = composition.getName();
+               
+               String relationName;
+               if (name != null) {
+                       relationName = ontShort+"has"+name;
+                       if (parent != null)
+                               relationName = ontShort+getName(parent)+"_has"+name;
+               } else {
+                       throw new RuntimeException();
+               }
+               fw.writer.println("      if (attribute.getPredicate().equals("+relationName+")) {");
+               fw.writer.println("            "+javaType+" value = ("+javaType+")graph.getValue(attribute.getObject(),"+arrayBinding+");");
+               //fw.writer.println("            writer.writeAttribute("+attrName+", graph.getValue(attribute.getObject(),"+binding.binding+").toString());");
+
+               int i = 0;
+               for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute())
+               fw.writer.println("            writer.writeAttribute(\""+a.getName()+"\","+typeEntry.getElementToString("value["+(i++)+"]")+");");
+               //fw.writer.println("            writer.writeAttribute(\""+a.getName()+"\",value["+(i++)+"].toString());");
+//             fw.writer.println("         Attribute a"+(i++)+" = element.getAttribute(\"" +a.getName()+"\");");
+//             fw.writer.print  ("         "+javaType + " value = new "+javaType+"{");
+               i = 0;
+               // FIXME : handle optional attributes properly.
+//             for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute()) {
+//                     Attribute attribute = ((Attribute)attributes.getRight(a));
+//                     //QName atype = getBaseType(attribute);
+//                     QName atype = getPrimitiveType(attribute);
+//                     String defaultValue = attribute.getDefault();
+//                     if (defaultValue == null)
+//                         defaultValue = getDefaultValue(atype);
+//                             
+//                     //String binding = getBindingFromPrimitiveType(atype);
+//                     TypeEntry binding = getTypeEntry(atype);
+//                     if (i > 0)
+//                             fw.writer.print(",");
+//                     if (defaultValue != null)
+//                             fw.writer.print("a"+(i)+"!= null ? "+ getValueGetterMethod(binding,"a"+(i++)) + " : " +defaultValue);
+//                     else
+//                             fw.writer.print(getValueGetterMethod(binding,"a"+(i++)));
+//             }
+//             fw.writer.println("};");
+//             fw.writer.println("         graph.claimLiteral(element.getData(),"+relationName+", value, "+arrayBinding+");");
+               fw.writer.println("      }");
+               
+       }
+       
+       protected String getDefaultValue(QName atype) {
+               Map<String,TypeEntry> types = this.base.typeMap.get(atype.getNamespaceURI());
+               if (types == null)
+                       return null;
+               TypeEntry entry =  types.get(atype.getLocalPart());
+               if (entry == null)
+                       return null;
+               return entry.defaultValue;
+       }
+       
+       IDProvider provider;
+       @Override
+       public void handleElement(SchemaObject elementObj)  {
+               Element element = elementObj.getElement();
+               
+               String name = getName(elementObj);//topLevelElement.getName();
+               String className = name;
+               
+               FileWriter fw = new FileWriter();
+               try {
+                       fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));
+               } catch (IOException e) {
+                       throw new RuntimeException(e);
+               }
+               writers.put(elementObj, fw);
+               boolean isList = false;
+               
+               Inheritance inheritance = this.base.getInheritance(elementObj); 
+               
+               provider = this.base.getIDProvider(element);
+               List<IDReference> references = this.base.getIDReferences(element);
+               UnrecognizedChildElement unknownChildElement = this.base.getUnknown(element);
+
+//             List<String> intrerfaces = new ArrayList<String>();
+//             if (references.size() > 0)
+//                     intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");
+//             if (unknownChildElement != null)
+//                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");
+
+               createClassHeader(fw.writer);
+               writeClass(fw.writer,false, element.getName(), className, inheritance.baseClass, Collections.EMPTY_LIST);
+//             writeIDProvider(fw.writer);
+               fw.writer.println("   @Override");
+               fw.writer.println("   public Resource getType(ReadGraph graph) throws DatabaseException {");
+               fw.writer.println("      "+getOntologyImport());
+               fw.writer.println("      return "+ontShort+name+";");
+//             if (!isList) {
+//             fw.writer.println("      Resource res = graph.newResource();");
+//             fw.writer.println("      graph.claim(res, L0.InstanceOf, "+ontShort+name+");");
+//             } else {
+//             fw.writer.println("      Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");
+//             }
+//             fw.writer.println("      return res;");
+               fw.writer.println("   }");
+               fw.writer.println();
+               
+//             fw.writer.println("   @Override");
+//             fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");
+//             fw.writer.println("      "+getOntologyImport());
+//             fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(elementObj,"has")+", element.getData());");
+//             fw.writer.println("      return true;");
+//             fw.writer.println("   }");
+//             fw.writer.println();
+               LocalComplexType complexType = element.getComplexType();
+               LocalSimpleType simpleType = element.getSimpleType();
+               
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");
+               if (inheritance.type == InheritanceType.ComplexType) {
+               fw.writer.println("        super.attributes(graph,instance,attributes,writer);");
+               }
+               fw.writer.println("        "+getOntologyImport());
+               fw.writer.println("        for (Statement attribute : attributes) {");
+               if (complexType != null) {
+                       SchemaObject obj = this.base.getComplexType(complexType);
+                       this.base.handleElementComplexTypeAttributes(obj);
+               } 
+               fw.writer.println("        }");
+               fw.writer.println("   }");
+               
+               
+//             fw.writer.println("   @Override");
+//             fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");
+//             if (inhertiance.type == InheritanceType.ComplexType) {
+//             fw.writer.println("             super.configure(graph,parents,element);");
+//             }
+//             fw.writer.println("        "+getOntologyImport());
+//             
+//             LocalComplexType complexType = element.getComplexType();
+//             LocalSimpleType simpleType = element.getSimpleType();
+//             
+//             if (complexType != null) {
+//                     SchemaObject obj = complexTypes.get(complexType);
+//                     handleElementComplexTypeAttributes(obj);
+//             } 
+//             fw.writer.println("   }");
+               
+               if (inheritance.type == InheritanceType.AtomicType) {
+               fw.writer.println();
+//             fw.writer.println("   @Override");
+//             fw.writer.println("   public void configure(WriteGraph graph, ParserElement element, java.lang.String string) throws DatabaseException {");
+//             fw.writer.println("      graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");
+//             fw.writer.println("   }");
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");
+               fw.writer.println("            writer.writeCharacters("+inheritance.atomicType.getToString("graph.getValue(instance.getResource(),"+inheritance.atomicType.binding+")")+");");
+//             fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");
+               fw.writer.println("   }");
+               }
+//             if (simpleType != null) {
+//                     SchemaObject obj = simpleTypes.get(simpleType);
+//                     handleElementSimpleTypeAttributes(obj);
+//             }
+               
+               
+               StringWriter stringWriter = new StringWriter();
+               fw.delayedWriter = new PrintWriter(stringWriter);
+               StringWriter stringWriter2 = new StringWriter();
+               fw.delayedWriter2 = new PrintWriter(stringWriter2);
+               
+               fw.writer.println("   public " + className + "(ReadGraph graph) {");
+               fw.writer.println("      super(graph);");
+               fw.writer.println("      "+getOntologyImport());
+               if (complexType != null) {
+                       SchemaObject obj = this.base.getComplexType(complexType);
+                       this.base.handleComplexTypeExtension(obj);
+               } else if (simpleType != null) {
+                       
+               }
+               
+               fw.writer.println("   }");
+               
+               fw.writer.println("   @Override");
+               fw.writer.println("   public void children(ReadGraph graph, WriterElement instance, java.util.Set<org.simantics.db.Resource> result) throws XMLStreamException, DatabaseException {");
+               fw.writer.println("      "+getOntologyImport());
+               
+               if (stringWriter.getBuffer().length() > 0) {
+                       fw.writer.write(stringWriter.toString());
+               }
+               
+               if (inheritance.type == InheritanceType.ComplexType) {
+               fw.writer.println("      super.children(graph,instance,result);");
+               }
+               
+               fw.writer.println("   }");
+               fw.writer.println();
+                               
+               if (stringWriter2.getBuffer().length() > 0) {
+                       fw.writer.write(stringWriter2.toString());
+               }
+               
+               stringWriter = null;
+               fw.delayedWriter.close();
+               fw.delayedWriter = null;
+               stringWriter2 = null;
+               fw.delayedWriter2.close();
+               fw.delayedWriter2 = null;
+               
+//             writeIDReferences(fw.writer,name, references);
+//             writeUnknownChild(fw.writer,name,unknownChildElement);
+
+               fw.writer.println("}");
+               fw.writer.println();
+               fw.writer.flush();
+               fw.writer.close();
+               fw.writer = null;
+               writers.remove(elementObj);
+               provider = null;
+               
+               ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);
+       }
+       
+       
+//     private void writeIDProvider(PrintWriter writer) {
+//             if (provider != null) {
+//             writer.println("   java.lang.String idProviderValue = null;");
+//             writer.println();
+//             writer.println("   @Override");
+//             writer.println("   public java.lang.String getID() {");
+//             writer.println("        java.lang.String s = idProviderValue;");
+//             writer.println("        idProviderValue = null;");
+//             writer.println("        return s;");
+//             writer.println("   }");
+//             writer.println();
+//             if (provider.getPriority() != null) {
+//             writer.println("   @Override");
+//             writer.println("   public int idPriority() {");
+//             writer.println("        return " + provider.getPriority().intValue()+";");
+//             writer.println("   }"); 
+//             }
+//             }
+//     }
+//     
+//     private void writeIDReferences(PrintWriter writer,String name, List<IDReference> references) {
+//             if (references.size() > 0) {
+//             writer.println("   @Override");
+//             writer.println("   public boolean connectReferences(WriteGraph graph, ParserElement element, java.util.Map<java.lang.String, ParserElement> map) throws DatabaseException {");
+//             writer.println("      "+getOntologyImport());
+//             writer.println("      boolean result = true;");
+//             for (IDReference ref : references) {
+//             writer.println("      {");
+//             writer.println("         Attribute a = element.getAttribute(\"" + ref.getIDSource().getName() +"\");");
+//             writer.println("         if (a != null) {");
+//             writer.println("            ParserElement refEle = map.get(a.value);");
+//             writer.println("            if (refEle != null) {");
+//             writer.println("               Resource ref = refEle.getData();");
+//             writer.println("               graph.claim(element.getData(), "+ontShort+name+"_"+ref.getReference().getName()+", ref);");
+//             writer.println("            } else {");
+//             writer.println("               result = false;");
+//             writer.println("            }");
+//             writer.println("         }");
+//             writer.println("      }");
+//             }
+//             writer.println("      return result;");
+//             writer.println("   }");
+//             writer.println();
+//             }
+//     }
+       
+//     private void writeUnknownChild(PrintWriter writer,String name, UnrecognizedChildElement unknownChildElement) {
+//             if (unknownChildElement == null)
+//                     return;
+//             
+//             writer.println("   @Override");
+//             writer.println("   public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException {");
+//             writer.println("    " + unknownChildElement.getJavaMethod());
+//             writer.println("   }");
+//             writer.println();
+//             
+//     }
+       
+       protected void createClassHeader(PrintWriter writer) {
+               writer.println("package " + converter.getPluginName() +"."+elementPackageName+";");
+               writer.println();
+               writer.println("import org.simantics.databoard.Bindings;");
+               writer.println("import org.simantics.db.Resource;");
+               writer.println("import org.simantics.db.ReadGraph;");
+               writer.println("import org.simantics.db.Statement;");
+               writer.println("import org.simantics.db.exception.DatabaseException;");
+               writer.println("import org.simantics.xml.sax.base.WriterElement;");
+               writer.println("import org.simantics.xml.sax.ontology.XMLResource;");
+               writer.println("import java.util.Collection;");
+               writer.println("import javax.xml.stream.XMLStreamException;");
+               writer.println("import javax.xml.stream.XMLStreamWriter;");
+//             if (!isList) {
+//             writer.println("import org.simantics.layer0.Layer0;");
+//         } else {
+//         writer.println("import java.util.Collections;");
+//             writer.println("import org.simantics.db.common.utils.ListUtils;");
+//             }
+               writer.println();
+       }
+       
+
+
+}
index ba1eff9cc261e62331fb1b865c25783785aec6c2..206acc0eca84f78d30a1aac4778f070bda1a33c2 100644 (file)
@@ -203,6 +203,7 @@ public class ImporterGenerator extends JavaGenerator{
                }
                fw.writer.println("      "+getOntologyImport());
                fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");
+               fw.writer.println("      XMLResource XML = XMLResource.getInstance(graph);");
                this.base.handleComplexTypeAttributes(complexTypeObj);
                this.base.handleExtensionAttributes(complexTypeObj);
                
@@ -251,10 +252,10 @@ public class ImporterGenerator extends JavaGenerator{
 
                // element type specific list
                fw.delayedWriter.println("            {");
-               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List);");
+               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
                fw.delayedWriter.println("               if (list == null) {");
                fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List,list);");
+               fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
                fw.delayedWriter.println("               } else {");
                fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
                fw.delayedWriter.println("               }");
@@ -288,7 +289,7 @@ public class ImporterGenerator extends JavaGenerator{
                fw.delayedWriter2.println("         super(\""+refName+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+refName+", "+typeEntry.binding+");");
                fw.delayedWriter2.println("      }\n");
                fw.delayedWriter2.println("      @Override");
-               fw.delayedWriter2.println("      public void configure(WriteGraph graph, ParserElement element, String value)   throws DatabaseException {");
+               fw.delayedWriter2.println("      public void configure(WriteGraph graph, ParserElement element, java.lang.String value) throws DatabaseException {");
                fw.delayedWriter2.println("         Layer0 L0 = Layer0.getInstance(graph);");
 
                SchemaObject simpleType = base.getSimpleType(typeName);
@@ -320,10 +321,10 @@ public class ImporterGenerator extends JavaGenerator{
 
                // element type specific list
                fw.delayedWriter.println("            {");
-               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List);");
+               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
                fw.delayedWriter.println("               if (list == null) {");
                fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List,list);");
+               fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
                fw.delayedWriter.println("               } else {");
                fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
                fw.delayedWriter.println("               }");
index 3e0ffb1d3136327fb703a8421d01af176f384499..64def5d59f223c601b6f8969b5b098dc5689ecc9 100644 (file)
@@ -138,9 +138,9 @@ public class OntologyGenerator implements SchemaConversionComponent {
                writer.println();
                
                if (!single) {
-                       String elementListType = getName(parent) + "." + name + "List";
+                       String elementListType = getName(parent) + "." + name + "_List";
                        writer.println(elementListType + " <T XML.ElementList");
-                       writer.println(relationName + "List <R XML.hasElementList : L0.FunctionalRelation");
+                       writer.println(relationName + "_List <R XML.hasElementList : L0.FunctionalRelation");
                        writer.println("   --> " + elementListType);
                }
                
@@ -182,10 +182,10 @@ public class OntologyGenerator implements SchemaConversionComponent {
                                
                                if (type == null) {
                                        writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");
-                                       writer.println(getName(parent)+".has"+refName + "List <R " +  getName(obj,"has")+"List : L0.FunctionalRelation");
+                                       writer.println(getName(parent)+".has"+refName + "_List <R " +  getName(obj,"has")+"_List : L0.FunctionalRelation");
                                } else {
-                                       writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");
-                                       writer.println(getName(parent)+".has"+refName + "List <R XML.hasElementList : L0.FunctionalRelation");  
+                                       writer.println(getName(parent)+"."+refName + "_List <T XML.ElementList");
+                                       writer.println(getName(parent)+".has"+refName + "_List <R XML.hasElementList : L0.FunctionalRelation"); 
                                }
                        }
                } else {
@@ -199,8 +199,8 @@ public class OntologyGenerator implements SchemaConversionComponent {
                        writer.println();
                        writer.println("   --> " + getName(obj));
                        if (base.useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {
-                               writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");
-                               writer.println(getName(parent)+".has"+refName + "List <R " +  getName(obj,"has")+"List : L0.FunctionalRelation");
+                               writer.println(getName(parent)+"."+refName + "_List <T XML.ElementList");
+                               writer.println(getName(parent)+".has"+refName + "_List <R " +  getName(obj,"has")+"_List : L0.FunctionalRelation");
                        }
                }
                
@@ -412,14 +412,14 @@ public class OntologyGenerator implements SchemaConversionComponent {
                
                // Type definition
                writer.println(name+ " <T " + inheritance.baseClass);
-               writer.println(name + "List <T XML.ElementList");
+               writer.println(name + "_List <T XML.ElementList");
                
                // Access relations
                String relationName = getName(topLevelComplexType,"has");
                writer.println(relationName+ " <R XML.hasComplexType");
                writer.println("   --> " + name);
-               writer.println(relationName+ "List <R XML.hasElementList");
-               writer.println("   --> " + name + "List");
+               writer.println(relationName+ "_List <R XML.hasElementList");
+               writer.println("   --> " + name + "_List");
                writer.println();
                
                // Attributes 
@@ -474,7 +474,7 @@ public class OntologyGenerator implements SchemaConversionComponent {
 //                     relationName = ontRoot+getName(elementObj.getParent()) + "has"+element.getName();
 //             }
                writer.println(relationName+ " <R XML.hasElement");
-               writer.println(relationName+ "List <R XML.hasElementList");
+               writer.println(relationName+ "_List <R XML.hasElementList");
                
                writer.println(name+ " <T "+type);
                
index f349cde8960667c3ac33004c6fd1c5d62c538c5f..863162c2ca873ad5d8180a69524fda1a22a73360 100644 (file)
@@ -111,7 +111,7 @@ public final class SchemaConversionBase {
                schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte",                        "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));
                schemaTypes.put("long",                 new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));
                schemaTypes.put("unsignedLong", new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));
-               schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray",           "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","java.util.Base64.getDecoder().decode(",")","java.util.Base64.getEncoder().encodeToString(",")"));
+               schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray",           "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","java.util.Base64.getDecoder().decode(",".replaceAll(\"\\n\", \"\").getBytes(java.nio.charset.StandardCharsets.UTF_8))","java.util.Base64.getEncoder().encodeToString(",")"));
                
                l0Types.put("doubleArray",              new TypeEntry("L0.DoubleArray",  "Bindings.DOUBLE_ARRAY", "double[]", null,null,null,"java.lang.Double.toString(",")"));
                l0Types.put("stringArray",              new TypeEntry("L0.StringArray",  "Bindings.STRING_ARRAY", "string[]", null,null,null,"",""));
@@ -1469,9 +1469,9 @@ public final class SchemaConversionBase {
         */
        public void getAtomicTypeInheritance(QName type, Inheritance inheritance) {
                if (!type.getNamespaceURI().equals(SCHEMA_NS)) {
-                       SchemaObject obj = getWithName(type);
-                       if (obj.getType() != ObjectType.SIMPLE_TYPE)
-                               throw new RuntimeException("SimpleContent does not use SimpleType definition");
+                       SchemaObject obj = getSimpleType(type);
+                       if (obj == null)
+                               throw new RuntimeException("Cannot locate SimpleType " + type.getLocalPart());
                        SimpleType simpleType = obj.getSimpleType();
                        type = getSimpleTypeBase(simpleType);
                        getAtomicTypeInheritance(type, inheritance);