]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Handling ComplexTypes inheriting AtomicType
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 26 Jan 2017 15:33:15 +0000 (15:33 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 12:01:35 +0000 (14:01 +0200)
Fixed element specific relation handling

refs #6985

git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@33437 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/IndentingXMLStreamWriter.java
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/JavaGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java

index a912564e87b162e3daa5dfbd33af32765c19ea87..d3a6cfdc3c1a439033512fb481fd1016f913d50e 100644 (file)
@@ -14,6 +14,7 @@ public class IndentingXMLStreamWriter implements XMLStreamWriter{
        \r
        XMLStreamWriter delegate;\r
        int depth = 0;\r
+       boolean indent = true;\r
        \r
        public IndentingXMLStreamWriter(XMLStreamWriter delegate) {\r
                this.delegate = delegate;\r
@@ -55,7 +56,7 @@ public class IndentingXMLStreamWriter implements XMLStreamWriter{
        }\r
        \r
        private String getIdent() {\r
-               String s = "";\r
+               String s = "\n";\r
                for (int i = 0; i < depth; i++)\r
                        s += "  ";\r
                return s;\r
@@ -63,76 +64,91 @@ public class IndentingXMLStreamWriter implements XMLStreamWriter{
 \r
        @Override\r
        public void writeStartElement(String localName) throws XMLStreamException {\r
-               delegate.writeCharacters("\n"+getIdent());\r
+               if(indent)\r
+               delegate.writeCharacters(getIdent());\r
                delegate.writeStartElement(localName);\r
                depth++;\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {\r
-               delegate.writeCharacters("\n"+getIdent());\r
+               if (indent)\r
+               delegate.writeCharacters(getIdent());\r
                delegate.writeStartElement(namespaceURI, localName);\r
                depth++;\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {\r
-               delegate.writeCharacters("\n"+getIdent());\r
+               if (indent)\r
+               delegate.writeCharacters(getIdent());\r
                delegate.writeStartElement(prefix, localName, namespaceURI);\r
                depth++;\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeStartDocument() throws XMLStreamException {\r
                delegate.writeStartDocument();\r
                depth++;\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeStartDocument(String version) throws XMLStreamException {\r
                delegate.writeStartDocument(version);\r
                depth++;\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeStartDocument(String encoding, String version) throws XMLStreamException {\r
                delegate.writeStartDocument(encoding, version);\r
                depth++;\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeEndElement() throws XMLStreamException {\r
                depth--;\r
-               delegate.writeCharacters("\n"+getIdent());\r
+               if(indent)\r
+               delegate.writeCharacters(getIdent());\r
                delegate.writeEndElement();\r
+               indent = true;\r
        }\r
        \r
        @Override\r
        public void writeEndDocument() throws XMLStreamException {\r
                depth--;\r
-               delegate.writeCharacters("\n"+getIdent());\r
+               if (indent)\r
+               delegate.writeCharacters(getIdent());\r
                delegate.writeEndDocument();\r
+               indent = true;\r
        }\r
        \r
        @Override\r
        public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {\r
                delegate.writeEmptyElement(namespaceURI, localName);\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {\r
                delegate.writeEmptyElement(prefix, localName, namespaceURI);\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeEmptyElement(String localName) throws XMLStreamException {\r
                delegate.writeEmptyElement(localName);\r
+               indent = true;\r
        }\r
 \r
        @Override\r
        public void writeAttribute(String localName, String value) throws XMLStreamException {\r
                delegate.writeAttribute( localName, value);\r
-               \r
        }\r
 \r
        @Override\r
@@ -158,8 +174,7 @@ public class IndentingXMLStreamWriter implements XMLStreamWriter{
 \r
        @Override\r
        public void writeComment(String data) throws XMLStreamException {\r
-               delegate.writeComment(data);\r
-               \r
+               delegate.writeComment(data);    \r
        }\r
 \r
        @Override\r
@@ -192,11 +207,13 @@ public class IndentingXMLStreamWriter implements XMLStreamWriter{
        @Override\r
        public void writeCharacters(String text) throws XMLStreamException {\r
                delegate.writeCharacters(text);\r
+               indent=false;\r
        }\r
 \r
        @Override\r
        public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {\r
                delegate.writeCharacters(text, start, len);\r
+               indent=false;\r
        }\r
 \r
        @Override\r
index 1976664fa73b758358a20d98a162379fc5e07381..c5c3f5ec32bfe9ba7fe4191b782eadbccb43c56c 100644 (file)
@@ -11,6 +11,8 @@ import java.util.Map;
 import javax.xml.namespace.QName;\r
 \r
 import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
+import org.simantics.xml.sax.SchemaObject.ObjectType;\r
 import org.simantics.xml.sax.configuration.AttributeComposition;\r
 import org.simantics.xml.sax.configuration.Configuration;\r
 import org.simantics.xml.sax.configuration.IDProvider;\r
@@ -122,7 +124,7 @@ public class ExporterGenerator extends JavaGenerator{
        }\r
        \r
        @Override\r
-       protected String getBaseClass() {\r
+       protected String getBaseClass(ObjectType type) {\r
                return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
        }\r
        \r
@@ -146,20 +148,21 @@ public class ExporterGenerator extends JavaGenerator{
                }\r
                writers.put(complexTypeObj, fw);\r
 \r
-               String baseClass = getBaseClass();\r
-               \r
-               boolean inherited = false;\r
-               \r
-               QName type = getComplexTypeBase(topLevelComplexType);\r
-               if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
-                       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
+//             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 = getInheritance(complexTypeObj);\r
                \r
                provider = getIDProvider(topLevelComplexType);\r
 //             List<IDReference> references = getIDReferences(topLevelComplexType);\r
@@ -172,7 +175,7 @@ public class ExporterGenerator extends JavaGenerator{
 //                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
                \r
                createClassHeader(fw.writer);\r
-               writeClass(fw.writer,false, topLevelComplexType.getName(), className, baseClass, Collections.EMPTY_LIST);\r
+               writeClass(fw.writer,false, topLevelComplexType.getName(), className, inheritance.baseClass, Collections.EMPTY_LIST);\r
                        \r
 //             writeIDProvider(fw.writer);\r
        \r
@@ -225,7 +228,8 @@ public class ExporterGenerator extends JavaGenerator{
                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
                fw.writer.println("   }");\r
                fw.writer.println();\r
                \r
@@ -242,7 +246,7 @@ public class ExporterGenerator extends JavaGenerator{
                \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 (inherited) {\r
+               if (inheritance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("             super.attributes(graph,instance,attributes,writer);");\r
                }\r
                fw.writer.println("        "+getOntologyImport());\r
@@ -252,6 +256,14 @@ public class ExporterGenerator extends JavaGenerator{
                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
@@ -267,19 +279,21 @@ public class ExporterGenerator extends JavaGenerator{
        \r
        \r
        @Override\r
-       //protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element,  boolean reference, String ref, QName refType) {\r
        protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType referenceType) {\r
                FileWriter fw = getWriter(parent);\r
+               String objectName;\r
                if (referenceType != RefType.Element) {\r
                        QName refType;\r
                        if (referenceType == RefType.Type) {\r
                                refType = element.getElement().getType();\r
                                if (refName == null)\r
                                        refName = element.getElement().getName();\r
+                               objectName = element.getElement().getName();\r
                        } else {\r
                                refType = element.getElement().getRef();\r
                                if (refName == null)\r
                                        refName = refType.getLocalPart();\r
+                               objectName = refType.getLocalPart();\r
                        }\r
                        \r
                        String binding = getBindingFromPrimitiveType(refType);\r
@@ -287,26 +301,39 @@ public class ExporterGenerator extends JavaGenerator{
                                SchemaObject refElement = elementName.get(refType.getLocalPart());\r
                                SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
        \r
-                               String className = null;\r
-                               String refClassName = null;\r
+                               // prefer element reference over complex type reference\r
+                               String primaryClassName = null;\r
+                               String secondaryClassName = null;\r
                                if (refElement != null)\r
-                                       className = getName(refElement);\r
+                                       primaryClassName = getName(refElement);\r
                                else\r
-                                       className = getName(refComplexType);\r
+                                       primaryClassName = getName(refComplexType);\r
                                \r
                                if (refComplexType != null) {\r
-                                       refClassName = getName(refComplexType);\r
+                                       secondaryClassName = getName(refComplexType);\r
                                } else {\r
-                                       refClassName = getName(refElement);\r
+                                       secondaryClassName = getName(refElement);\r
                                }\r
                                \r
-                               if (referenceType != RefType.Reference)\r
-                               fw.writer.println("        addTypeWriter("+ontShort+ className +", "+className+".class);");\r
-                               else\r
-                               fw.writer.println("        addWriter("+className+".class);");\r
-                               if (!className.equals(refClassName))\r
-                               fw.writer.println("        addWriter("+refClassName+".class);");\r
-                               \r
+                               if (referenceType == RefType.Type) {\r
+                               // create internal class for handling the element and child attachment\r
+                               secondaryClassName = getName(parent) +"_" +objectName;\r
+                               fw.writer.println("        addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+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(parent, indicator,element, referenceType == RefType.Reference, refName, refType)) {\r
@@ -643,7 +670,7 @@ public class ExporterGenerator extends JavaGenerator{
                writers.put(elementObj, fw);\r
                boolean isList = false;\r
                \r
-               Inheritance inhertiance = getElementInheritance(elementObj);    \r
+               Inheritance inheritance = getInheritance(elementObj);   \r
                \r
                provider = getIDProvider(element);\r
                List<IDReference> references = getIDReferences(element);\r
@@ -656,7 +683,7 @@ public class ExporterGenerator extends JavaGenerator{
 //                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
 \r
                createClassHeader(fw.writer);\r
-               writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, Collections.EMPTY_LIST);\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
@@ -684,7 +711,7 @@ public class ExporterGenerator extends JavaGenerator{
                \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 (inhertiance.type == InheritanceType.ComplexType) {\r
+               if (inheritance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("        super.attributes(graph,instance,attributes,writer);");\r
                }\r
                fw.writer.println("        "+getOntologyImport());\r
@@ -713,7 +740,7 @@ public class ExporterGenerator extends JavaGenerator{
 //             } \r
 //             fw.writer.println("   }");\r
                \r
-               if (inhertiance.type == InheritanceType.AtomicType) {\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
@@ -721,7 +748,7 @@ public class ExporterGenerator extends JavaGenerator{
 //             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("+inhertiance.atomicType.getToString("graph.getValue(instance.getResource(),"+inhertiance.atomicType.binding+")")+");");\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
@@ -756,7 +783,7 @@ public class ExporterGenerator extends JavaGenerator{
                        fw.writer.write(stringWriter.toString());\r
                }\r
                \r
-               if (inhertiance.type == InheritanceType.ComplexType) {\r
+               if (inheritance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("      super.children(graph,instance,result);");\r
                }\r
                \r
index f55f9cfeb0ad7a5816cc584f84cf5cba32216ff8..55ff5ef7e52f32ab0b830e9efa5a8b6ad689d2c1 100644 (file)
@@ -11,6 +11,9 @@ import java.util.Map;
 import javax.xml.namespace.QName;\r
 \r
 import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;\r
+import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
+import org.simantics.xml.sax.SchemaObject.ObjectType;\r
 import org.simantics.xml.sax.configuration.AttributeComposition;\r
 import org.simantics.xml.sax.configuration.Configuration;\r
 import org.simantics.xml.sax.configuration.IDProvider;\r
@@ -114,7 +117,9 @@ public class ImporterGenerator extends JavaGenerator{
                \r
                String name = getName(complexTypeObj);\r
                \r
-//             if (topLevelComplexType.getName().equals("Reference"))\r
+               //if (topLevelComplexType.getName().equals("LocalizedText"))\r
+               //if (topLevelComplexType.getName().equals("Reference"))\r
+//             if (topLevelComplexType.getName().equals("NodeIdAlias"))\r
 //                     System.out.println();\r
                \r
                String className = name;//"_"+name;\r
@@ -126,19 +131,8 @@ public class ImporterGenerator extends JavaGenerator{
                        throw new RuntimeException(e);\r
                }\r
                writers.put(complexTypeObj, fw);\r
-\r
-               String baseClass = getBaseClass();\r
-               \r
-               boolean inherited = false;\r
                \r
-               QName type = getComplexTypeBase(topLevelComplexType);\r
-               if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
-                       SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
-                       if (obj != null) {\r
-                               baseClass = getName(obj);\r
-                               inherited = true;\r
-                       }\r
-               }\r
+               Inheritance inheritance = getInheritance(complexTypeObj);\r
                \r
                provider = getIDProvider(topLevelComplexType);\r
                List<IDReference> references = getIDReferences(topLevelComplexType);\r
@@ -151,7 +145,7 @@ public class ImporterGenerator extends JavaGenerator{
                        intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
                \r
                createClassHeader(fw.writer, false);\r
-               writeClass(fw.writer,false, null, className, baseClass, intrerfaces);\r
+               writeClass(fw.writer,false, null, className, inheritance.baseClass, intrerfaces);\r
                        \r
                writeIDProvider(fw.writer);\r
        \r
@@ -192,9 +186,11 @@ public class ImporterGenerator extends JavaGenerator{
                if (stringWriter.getBuffer().length() > 0) {\r
                        fw.writer.write(stringWriter.toString());\r
                }\r
-               \r
-               \r
+               if (inheritance.type == InheritanceType.ComplexType) {\r
+               fw.writer.println("      return super.connectChild(graph,element,child);");\r
+               }else{\r
                fw.writer.println("      return false;");\r
+               }\r
                fw.writer.println("   }");\r
                fw.writer.println();\r
                \r
@@ -211,7 +207,7 @@ public class ImporterGenerator extends JavaGenerator{
                \r
                fw.writer.println("   @Override");\r
                fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
-               if (inherited) {\r
+               if (inheritance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("             super.configure(graph,parents,element);");\r
                }\r
                fw.writer.println("        "+getOntologyImport());\r
@@ -221,6 +217,14 @@ public class ImporterGenerator extends JavaGenerator{
                \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(inheritance.atomicType,"string")+", "+inheritance.atomicType.binding+");");\r
+               fw.writer.println("   }");\r
+               }\r
+               \r
                writeIDReferences(fw.writer,name, references);\r
                writeUnknownChild(fw.writer,name,unknownChildElement);\r
                \r
@@ -234,19 +238,21 @@ public class ImporterGenerator extends JavaGenerator{
        }\r
        \r
        @Override\r
-       //protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element,  boolean reference, String ref, QName refType) {\r
        protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType referenceType) {\r
                FileWriter fw = getWriter(parent);\r
+               String objectName;\r
                if (referenceType != RefType.Element) {\r
                        QName refType;\r
                        if (referenceType == RefType.Type) {\r
                                refType = element.getElement().getType();\r
                                if (refName == null)\r
                                        refName = element.getElement().getName();\r
+                               objectName = element.getElement().getName();\r
                        } else {\r
                                refType = element.getElement().getRef();\r
                                if (refName == null)\r
                                        refName = refType.getLocalPart();\r
+                               objectName = refType.getLocalPart();\r
                        }\r
                        \r
                        String binding = getBindingFromPrimitiveType(refType);\r
@@ -254,27 +260,35 @@ public class ImporterGenerator extends JavaGenerator{
                                SchemaObject refElement = elementName.get(refType.getLocalPart());\r
                                SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
        \r
-                               String className = null;\r
-                               String refClassName = null;\r
+                               // prefer element reference over complex type reference\r
+                               String primaryClassName = null;\r
+                               String secondaryClassName = null;\r
                                if (refElement != null)\r
-                                       className = getName(refElement);\r
+                                       primaryClassName = getName(refElement);\r
                                else\r
-                                       className = getName(refComplexType);\r
+                                       primaryClassName = getName(refComplexType);\r
                                \r
                                if (refComplexType != null) {\r
-                                       refClassName = getName(refComplexType);\r
+                                       secondaryClassName = getName(refComplexType);\r
                                } else {\r
-                                       refClassName = getName(refElement);\r
+                                       secondaryClassName = getName(refElement);\r
                                }\r
                                \r
-                               if (referenceType != RefType.Reference)\r
-                               fw.writer.println("        addParser(\""+ refName +"\", "+className+".class);");\r
-                               else\r
-                               fw.writer.println("        addParser("+className+".class);");\r
-                               if (!className.equals(refClassName))\r
-                               fw.writer.println("        addParser("+refClassName+".class);");\r
+                               if (referenceType == RefType.Type) {\r
+                               // create internal class for handling the element and child attachment\r
+                               secondaryClassName = getName(parent) +"_" +objectName;\r
+                               fw.writer.println("        addParser(\""+ objectName +"\", "+secondaryClassName+".class);");\r
+                               fw.delayedWriter2.println("   public static class " + secondaryClassName +" extends " + primaryClassName +"{");\r
+                               fw.delayedWriter2.println("      public "+ secondaryClassName +"(){");\r
+                               fw.delayedWriter2.println("      }");\r
+                               fw.delayedWriter2.println("   }");\r
+                               } else { // referenceType == RefType.Reference\r
+                               fw.writer.println("        addParser("+primaryClassName+".class);");\r
+                               if (!primaryClassName.equals(secondaryClassName))\r
+                               fw.writer.println("        addParser("+secondaryClassName+".class);");\r
+                               }\r
                                \r
-                               fw.delayedWriter.println("         if (child.getElementParser() instanceof "+refClassName+"){");\r
+                               fw.delayedWriter.println("         if (child.getElementParser() instanceof "+secondaryClassName+"){");\r
                                fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+refName + ", child.getData());");\r
                                if (useElementList(parent, indicator,element, referenceType == RefType.Reference, refName, refType)) {\r
                \r
@@ -584,7 +598,7 @@ public class ImporterGenerator extends JavaGenerator{
                writers.put(elementObj, fw);\r
                boolean isList = false;\r
                \r
-               Inheritance inhertiance = getElementInheritance(elementObj);    \r
+               Inheritance inheritance = getInheritance(elementObj);   \r
                \r
                provider = getIDProvider(element);\r
                List<IDReference> references = getIDReferences(element);\r
@@ -597,7 +611,7 @@ public class ImporterGenerator extends JavaGenerator{
                        intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
 \r
                createClassHeader(fw.writer, isList);\r
-               writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, intrerfaces);\r
+               writeClass(fw.writer,false, element.getName(), className, inheritance.baseClass, intrerfaces);\r
                writeIDProvider(fw.writer);\r
                fw.writer.println("   @Override");\r
                fw.writer.println("   public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
@@ -623,7 +637,7 @@ public class ImporterGenerator extends JavaGenerator{
                \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
+               if (inheritance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("             super.configure(graph,parents,element);");\r
                }\r
                fw.writer.println("        "+getOntologyImport());\r
@@ -637,11 +651,11 @@ public class ImporterGenerator extends JavaGenerator{
                } \r
                fw.writer.println("   }");\r
                \r
-               if (inhertiance.type == InheritanceType.AtomicType) {\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("      graph.claimValue(element.getData(), "+getValueGetter(inheritance.atomicType,"string")+", "+inheritance.atomicType.binding+");");\r
                fw.writer.println("   }");\r
                }\r
 //             if (simpleType != null) {\r
@@ -674,7 +688,7 @@ public class ImporterGenerator extends JavaGenerator{
                if (stringWriter.getBuffer().length() > 0) {\r
                        fw.writer.write(stringWriter.toString());\r
                }\r
-               if (inhertiance.type == InheritanceType.ComplexType) {\r
+               if (inheritance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("      return super.connectChild(graph,element,child);");     \r
                } else {\r
                fw.writer.println("      return false;");\r
@@ -767,7 +781,7 @@ public class ImporterGenerator extends JavaGenerator{
        }\r
        \r
        @Override\r
-       protected String getBaseClass() {\r
+       protected String getBaseClass(ObjectType type) {\r
                return "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
        }\r
        \r
index 887bd1ec34e3611ccb0d715eaa6fba71d1abc7b2..bf52b9bac6889e608746176e9e14edbb316f92d7 100644 (file)
@@ -65,11 +65,11 @@ public abstract class JavaGenerator extends SchemaConversionBase{
                return binding.getValueGetter();\r
        }\r
        \r
-       public static String getComplexTypePrefix() {\r
+       public String getComplexTypePrefix() {\r
                return "ComplexTypes_";\r
        }       \r
        \r
-       public static String getAttributeGroupPrefix() {\r
+       public String getAttributeGroupPrefix() {\r
                return "AttributeGroups_";\r
        }\r
                \r
@@ -122,7 +122,7 @@ public abstract class JavaGenerator extends SchemaConversionBase{
        }\r
        \r
        \r
-       public static String getName(SchemaObject obj) {\r
+       public String getName(SchemaObject obj) {\r
                if (obj.getParent() == null) {\r
                        switch (obj.getType()) {\r
                        case COMPLEX_TYPE:\r
@@ -162,7 +162,7 @@ public abstract class JavaGenerator extends SchemaConversionBase{
                \r
        }\r
        \r
-       public static String getName(SchemaObject obj, String rel) {\r
+       public String getName(SchemaObject obj, String rel) {\r
                if (obj.getParent() == null) {\r
                        switch (obj.getType()) {\r
                        case COMPLEX_TYPE:\r
@@ -199,18 +199,7 @@ public abstract class JavaGenerator extends SchemaConversionBase{
                throw new RuntimeException();\r
        }\r
        \r
-       protected enum InheritanceType{ComplexType,AtomicType,None};\r
        \r
-       protected class Inheritance {\r
-               public String baseClass;\r
-               public InheritanceType type;\r
-               public TypeEntry atomicType;\r
-               \r
-               public Inheritance(String baseClass) {\r
-                       this.baseClass = baseClass;\r
-                       this.type = InheritanceType.None;\r
-               }\r
-       }\r
        \r
        protected void writeClass(PrintWriter writer,boolean abst, String elementId, String className, String baseClass, List<String> interfaces) {\r
                writer.println("@SuppressWarnings(\"unused\")");\r
@@ -235,63 +224,8 @@ public abstract class JavaGenerator extends SchemaConversionBase{
                writer.println();\r
        }\r
        \r
-       protected abstract String getBaseClass();\r
        \r
-       protected Inheritance getElementInheritance(SchemaObject topLevelElementObj) {\r
-               Element topLevelElement = topLevelElementObj.getElement();\r
-               Inheritance inheritance = new Inheritance(getBaseClass());\r
-               if (topLevelElement.getType() != null) {\r
-                       QName type = topLevelElement.getType();\r
-                       if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
-                               SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
-//                             if (obj == null)\r
-//                                     obj = simpleTypeName.get(type.getLocalPart());\r
-                               if (obj != null) {\r
-                                       inheritance.baseClass = getName(obj);\r
-                                       inheritance.type = InheritanceType.ComplexType;\r
-                               }\r
-                       } else {\r
-                               TypeEntry entry = getTypeEntry(type);\r
-                               if (entry != null) {\r
-                                       inheritance.type = InheritanceType.AtomicType;\r
-                                       inheritance.atomicType = entry;\r
-                               }\r
-                       }\r
-               }\r
-               if (inheritance.type == InheritanceType.None) {\r
-                       QName type = getElementBase(topLevelElement);\r
-                       if (type != null) {\r
-                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
-                                       SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
-                                       inheritance.baseClass = getName(obj);\r
-                                       inheritance.type = InheritanceType.ComplexType;\r
-                               } else {\r
-                                       TypeEntry entry = getTypeEntry(type);\r
-                                       if (entry != null) {\r
-                                               inheritance.type = InheritanceType.AtomicType;\r
-                                               inheritance.atomicType = entry;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               if (inheritance.type == InheritanceType.None) {\r
-                       QName type = topLevelElement.getSubstitutionGroup();\r
-                       if (type != null) {\r
-                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
-                                       SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
-                                       inheritance.baseClass = getName(obj);\r
-                                       inheritance.type = InheritanceType.ComplexType;\r
-                               } else {\r
-                                       TypeEntry entry = getTypeEntry(type);\r
-                                       if (entry != null) {\r
-                                               inheritance.type = InheritanceType.AtomicType;\r
-                                               inheritance.atomicType = entry;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               return inheritance;\r
-       }       \r
+       \r
+\r
 \r
 }\r
index e64a59bf3f296fb0fae84e84e3341502b406d522..741e197f0e2ff50bf9bb6b41c619fe94fd78471e 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Set;
 import javax.xml.namespace.QName;\r
 \r
 import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.SchemaObject.ObjectType;\r
 import org.simantics.xml.sax.configuration.AttributeComposition;\r
 import org.simantics.xml.sax.configuration.Configuration;\r
 import org.simantics.xml.sax.configuration.IDReference;\r
@@ -140,11 +141,11 @@ public class OntologyGenerator extends SchemaConversionBase {
        }\r
        \r
        \r
-       public static String getComplexTypePrefix() {\r
+       public String getComplexTypePrefix() {\r
                return "ComplexTypes.";\r
        }\r
        \r
-       public static String getAttributeGroupPrefix() {\r
+       public String getAttributeGroupPrefix() {\r
                return "AttributeGroups.";\r
        }\r
        \r
@@ -163,7 +164,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                                        break;\r
                                }\r
                        }\r
-                       String relationName = ontRoot+getName(parent)+".has"+name;\r
+                       String relationName = getName(parent)+".has"+name;\r
                        writer.print(relationName);\r
                        \r
                        List<String> types = new ArrayList<String>();\r
@@ -181,7 +182,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                                }\r
                                if (type == null) {\r
                                        SchemaObject obj = getWithName(parent, refType.getLocalPart());\r
-                                       types.add(ontRoot+getName(obj,"has"));\r
+                                       types.add(getName(obj,"has"));\r
                                } \r
                        }\r
                        if (types.size() > 0) {\r
@@ -248,21 +249,21 @@ public class OntologyGenerator extends SchemaConversionBase {
                        if (type == null) {\r
                                obj = getWithName(parent, referenceType.getLocalPart());\r
                                \r
-                               writer.println(ontRoot+getName(parent)+".has"+refName + " <R " +  ontRoot+ getName(obj,"has"));\r
-                               writer.println("   --> " + ontRoot+getName(obj));\r
+                               writer.println(getName(parent)+".has"+refName + " <R " +  getName(obj,"has"));\r
+                               writer.println("   --> " + getName(obj));\r
                        } else {\r
-                               writer.println(ontRoot+getName(parent)+".has"+refName + " <R XML.hasElement");\r
+                               writer.println(getName(parent)+".has"+refName + " <R XML.hasElement");\r
                                writer.println("   --> " + getType(referenceType));\r
                        }\r
                        \r
                        if (useElementList(parent, indicator,element, refType == RefType.Reference, refName, referenceType)) {\r
                                \r
                                if (type == null) {\r
-                                       writer.println(ontRoot+getName(parent)+"."+refName + "List <T XML.ElementList");\r
-                                       writer.println(ontRoot+getName(parent)+".has"+refName + "List <R " +  ontRoot+getName(obj,"has")+"List : L0.FunctionalRelation");\r
+                                       writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");\r
+                                       writer.println(getName(parent)+".has"+refName + "List <R " +  getName(obj,"has")+"List : L0.FunctionalRelation");\r
                                } else {\r
-                                       writer.println(ontRoot+getName(parent)+"."+refName + "List <T XML.ElementList");\r
-                                       writer.println(ontRoot+getName(parent)+".has"+refName + "List <R XML.hasElementList : L0.FunctionalRelation");  \r
+                                       writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");\r
+                                       writer.println(getName(parent)+".has"+refName + "List <R XML.hasElementList : L0.FunctionalRelation");  \r
                                }\r
                        }\r
                } else {\r
@@ -271,11 +272,11 @@ public class OntologyGenerator extends SchemaConversionBase {
                        if (refName == null)\r
                                refName = obj.getName();\r
                        \r
-                       writer.println(ontRoot+getName(parent)+".has"+refName + " <R " +  ontRoot+ getName(obj,"has"));\r
-                       writer.println("   --> " + ontRoot+getName(obj));\r
+                       writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));\r
+                       writer.println("   --> " + getName(obj));\r
                        if (useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {\r
-                               writer.println(ontRoot+getName(parent)+"."+refName + "List <T XML.ElementList");\r
-                               writer.println(ontRoot+getName(parent)+".has"+refName + "List <R " +  ontRoot+getName(obj,"has")+"List : L0.FunctionalRelation");\r
+                               writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");\r
+                               writer.println(getName(parent)+".has"+refName + "List <R " +  getName(obj,"has")+"List : L0.FunctionalRelation");\r
                        }\r
                }\r
                \r
@@ -298,11 +299,11 @@ public class OntologyGenerator extends SchemaConversionBase {
                if (name != null) {\r
                        relationName = ontRoot+"has"+name;\r
                        if (parent != null)\r
-                               relationName = ontRoot+getName(parent)+".has"+name;\r
+                               relationName = getName(parent)+".has"+name;\r
                        relationType = "XML.hasAttribute";\r
                }\r
                else if (ref != null && parent != null) {\r
-                       relationName = ontRoot+getName(parent)+".has"+ref.getLocalPart();\r
+                       relationName = getName(parent)+".has"+ref.getLocalPart();\r
                        relationType = ontRoot+"has"+ref.getLocalPart();\r
                } else {\r
                        throw new RuntimeException();\r
@@ -370,7 +371,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                                }\r
                        }\r
                } else {\r
-                       writer.println(ontRoot+getName(parent) +" L0.Inherits " + ontRoot + getAttributeGroupPrefix() + attributeGroup.getRef().getLocalPart());\r
+                       writer.println(getName(parent) +" L0.Inherits " + ontRoot + getAttributeGroupPrefix() + attributeGroup.getRef().getLocalPart());\r
                }\r
                \r
        }\r
@@ -394,7 +395,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                        // TODO : process restriction in lists\r
                        String relationName = ontRoot+"has"+name;\r
                        if (parent != null)\r
-                               relationName = ontRoot+getName(parent)+".has"+name;\r
+                               relationName = getName(parent)+".has"+name;\r
                        writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");\r
                        \r
                        String ontType = getL0Type(new QName(SCHEMA_NS, "string"));\r
@@ -407,7 +408,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                        \r
                        String relationName = ontRoot+"has"+name;\r
                        if (parent != null)\r
-                               relationName = ontRoot+getName(parent)+".has"+name;\r
+                               relationName = getName(parent)+".has"+name;\r
                        \r
                        writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");\r
                        \r
@@ -422,25 +423,34 @@ public class OntologyGenerator extends SchemaConversionBase {
 //             if (topLevelComplexType.getName().equals("Reference"))\r
 //                     System.out.println();\r
                \r
-               String relationName = ontRoot+getName(topLevelComplexType,"has");//ontRoot+"has"+name;\r
+               String relationName = getName(topLevelComplexType,"has");//ontRoot+"has"+name;\r
                \r
                writer.println(relationName+ " <R XML.hasComplexType");\r
                writer.println(relationName+ "List <R XML.hasElementList");\r
                //writer.println("   --> " + ontRoot+getComplexTypePrefix()+name);\r
-               writer.println("   --> " + ontRoot+name);\r
+               writer.println("   --> " + name);\r
                writer.println();\r
-               String baseType = "XML.ComplexType";\r
-\r
-               QName base = getComplexTypeBase(topLevelComplexType.getComplexType());\r
-               if (base != null) {\r
-                       baseType = getType(base);\r
-               }\r
-               base = getSimpleTypeBase(topLevelComplexType.getSimpleType());\r
-               if (base != null) {\r
-                       baseType = getType(base);\r
+//             String baseType = "XML.ComplexType";\r
+//\r
+//             QName base = getComplexTypeBase(topLevelComplexType.getComplexType());\r
+//             if (base != null) {\r
+//                     baseType = getType(base);\r
+//             }\r
+//             base = getSimpleTypeBase(topLevelComplexType.getSimpleType());\r
+//             if (base != null) {\r
+//                     baseType = getType(base);\r
+//             }\r
+               Inheritance inheritance = getInheritance(topLevelComplexType);\r
+               \r
+//             writer.println(name+ " <T "+baseType);\r
+               \r
+               if(inheritance.type == InheritanceType.AtomicType) {\r
+                       writer.println(name+ " <T "+inheritance.baseClass + " <T "+inheritance.atomicType.l0Type);\r
+               } else {\r
+                       writer.println(name+ " <T "+inheritance.baseClass);\r
                }\r
-               //writer.println(ontRoot+getComplexTypePrefix()+name+ " <T "+baseType);\r
-               writer.println(ontRoot+name+ " <T "+baseType);\r
+//             if (!baseType.equals(inheritance.baseClass))\r
+//                     System.out.println();\r
                super.handleComplexType(topLevelComplexType);\r
                writer.println();\r
        }\r
@@ -481,7 +491,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                        type += " <T " + t;\r
                }\r
 \r
-               String relationName =  ontRoot+getName(elementObj,"has");//ontRoot+"has"+name;\r
+               String relationName =  getName(elementObj,"has");//ontRoot+"has"+name;\r
 //             if (elementObj.getParent() != null) {\r
 //                     //relationName = ontRoot+getComplexTypePrefix()+"has"+name.substring(getComplexTypePrefix().length());\r
 //                     relationName = ontRoot+getName(elementObj.getParent()) + "has"+element.getName();\r
@@ -489,7 +499,7 @@ public class OntologyGenerator extends SchemaConversionBase {
                writer.println(relationName+ " <R XML.hasElement");\r
                writer.println(relationName+ "List <R XML.hasElementList");\r
                \r
-               writer.println(ontRoot+name+ " <T "+type);\r
+               writer.println(name+ " <T "+type);\r
                \r
                LocalComplexType complexType = element.getComplexType();\r
                LocalSimpleType simpleType = element.getSimpleType();\r
@@ -506,23 +516,32 @@ public class OntologyGenerator extends SchemaConversionBase {
                List<IDReference> references = getIDReferences(element);\r
        \r
                for (IDReference ref : references) {\r
-                       writer.println(ontRoot+name+"."+ref.getReference().getName()+ " <R XML.hasReference");\r
+                       writer.println(name+"."+ref.getReference().getName()+ " <R XML.hasReference");\r
                }\r
                \r
                writer.println();\r
        }\r
        \r
-       public static String getName(SchemaObject obj) {\r
+       @Override\r
+       protected String getBaseClass(ObjectType type) {\r
+               if (type == ObjectType.ELEMENT)\r
+                       return "XML.Element";\r
+               if (type == ObjectType.COMPLEX_TYPE)\r
+                       return "XML.ComplexType";\r
+               throw new RuntimeException("ObjectType " + type + " has no base class");\r
+       }\r
+       \r
+       public String getName(SchemaObject obj) {\r
                if (obj.getParent() == null) {\r
                        switch (obj.getType()) {\r
                        case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+obj.getName();\r
+                               return ontRoot+getComplexTypePrefix()+obj.getName();\r
                        case ELEMENT:\r
-                               return obj.getName();\r
+                               return ontRoot+obj.getName();\r
                        case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+obj.getName();\r
+                               return ontRoot+getAttributeGroupPrefix()+obj.getName();\r
                        case SIMPLE_TYPE:\r
-                               return obj.getName();\r
+                               return ontRoot+obj.getName();\r
                        }\r
                } else {\r
                        SchemaObject o = obj;\r
@@ -537,30 +556,30 @@ public class OntologyGenerator extends SchemaConversionBase {
                        name = name.substring(0, name.length()-1);\r
                        switch (prev.getType()) {\r
                        case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+name;\r
+                               return ontRoot+getComplexTypePrefix()+name;\r
                        case ELEMENT:\r
-                               return name;\r
+                               return ontRoot+name;\r
                        case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+name;\r
+                               return ontRoot+getAttributeGroupPrefix()+name;\r
                        case SIMPLE_TYPE:\r
-                               return name;\r
+                               return ontRoot+name;\r
                        }\r
                }\r
                throw new RuntimeException();\r
                \r
        }\r
        \r
-       public static String getName(SchemaObject obj, String rel) {\r
+       public String getName(SchemaObject obj, String rel) {\r
                if (obj.getParent() == null) {\r
                        switch (obj.getType()) {\r
                        case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+rel+obj.getName();\r
+                               return ontRoot+getComplexTypePrefix()+rel+obj.getName();\r
                        case ELEMENT:\r
-                               return rel+obj.getName();\r
+                               return ontRoot+rel+obj.getName();\r
                        case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+rel+obj.getName();\r
+                               return ontRoot+getAttributeGroupPrefix()+rel+obj.getName();\r
                        case SIMPLE_TYPE:\r
-                               return rel+obj.getName();\r
+                               return ontRoot+rel+obj.getName();\r
                        }\r
                } else {\r
                        SchemaObject o = obj;\r
@@ -575,13 +594,13 @@ public class OntologyGenerator extends SchemaConversionBase {
                        name = name.substring(0, name.length()-1);\r
                        switch (prev.getType()) {\r
                        case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+rel+name;\r
+                               return ontRoot+getComplexTypePrefix()+rel+name;\r
                        case ELEMENT:\r
-                               return rel+name;\r
+                               return ontRoot+rel+name;\r
                        case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+rel+name;\r
+                               return ontRoot+getAttributeGroupPrefix()+rel+name;\r
                        case SIMPLE_TYPE:\r
-                               return rel+name;\r
+                               return ontRoot+rel+name;\r
                        }\r
                }\r
                throw new RuntimeException();\r
index 5df8c4aefcbf4736d477410f4599c65c26286249..2cf2e0c76afd4b3edb400f220902ce96dd910d70 100644 (file)
@@ -348,14 +348,6 @@ public abstract class SchemaConversionBase {
                                return type;\r
                        }\r
                }\r
-//             SimpleContent simpleContent = complexType.getSimpleContent();\r
-//             if (simpleContent != null) {\r
-//                     ExtensionType extensionType = simpleContent.getExtension();\r
-//                     if (extensionType != null) {\r
-//                             QName type = extensionType.getBase();\r
-//                             return type;\r
-//                     }\r
-//             }\r
                return null;\r
        }\r
        \r
@@ -640,20 +632,15 @@ public abstract class SchemaConversionBase {
        protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {\r
                Element localElement = element.getElement();\r
                if (localElement.getName() != null) {\r
-                       SchemaObject eObj = elements.get(localElement); // FIXME: handleIndicator should be refactored, not this methdof must be overridden in JavaGenerator to handle renaming of Elements properly\r
-                       //String refName = eObj.getName();//localElement.getName();\r
+                       SchemaObject eObj = elements.get(localElement); \r
                        QName refType = localElement.getType();\r
                        if (refType != null)\r
-                               //handleIndicator(parent, indicator, element, false, refName, refType);\r
                                handleIndicator(parent, indicator, element, null, RefType.Type);\r
                        else {\r
                                handleElement(eObj);\r
-                               //handleIndicator(parent, indicator, element, false, refName, localElement);\r
                                handleIndicator(parent, indicator, element, null, RefType.Element);\r
                        }\r
                } else if (localElement.getRef() != null) {\r
-                       //QName refType = localElement.getRef();\r
-                       //handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType);\r
                        handleIndicator(parent, indicator,element, null, RefType.Reference);\r
                }\r
        }\r
@@ -1069,5 +1056,129 @@ public abstract class SchemaConversionBase {
                }\r
                \r
        }\r
+       \r
+       public enum InheritanceType{ComplexType,AtomicType,None};\r
+       \r
+       public static class Inheritance {\r
+               public String baseClass;\r
+               public InheritanceType type;\r
+               public TypeEntry atomicType;\r
+               \r
+               public Inheritance(String baseClass) {\r
+                       this.baseClass = baseClass;\r
+                       this.type = InheritanceType.None;\r
+               }\r
+       }\r
+       \r
+       public abstract String getComplexTypePrefix();  \r
+       \r
+       public abstract String getAttributeGroupPrefix();\r
+       \r
+       public abstract String getName(SchemaObject obj);\r
+       \r
+       protected abstract String getBaseClass(ObjectType type);\r
+       \r
+       \r
+       \r
+       protected Inheritance getInheritance(SchemaObject topLevelObj) {\r
+               Inheritance inheritance = null;\r
+               if (topLevelObj.getType() == ObjectType.ELEMENT) {\r
+                       Element topLevelElement = topLevelObj.getElement();\r
+                       inheritance = new Inheritance(getBaseClass(ObjectType.ELEMENT));\r
+                       if (topLevelElement.getType() != null) {\r
+                               QName type = topLevelElement.getType();\r
+                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                                       SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+       //                              if (obj == null)\r
+       //                                      obj = simpleTypeName.get(type.getLocalPart());\r
+                                       if (obj != null) {\r
+                                               inheritance.baseClass = getName(obj);\r
+                                               inheritance.type = InheritanceType.ComplexType;\r
+                                       }\r
+                               } else {\r
+                                       TypeEntry entry = getTypeEntry(type);\r
+                                       if (entry != null) {\r
+                                               inheritance.type = InheritanceType.AtomicType;\r
+                                               inheritance.atomicType = entry;\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (inheritance.type == InheritanceType.None) {\r
+                               QName type = getElementBase(topLevelElement);\r
+                               if (type != null) {\r
+                                       if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                                               SchemaObject obj = getWithName(topLevelObj, type.getLocalPart());\r
+                                               inheritance.baseClass = getName(obj);\r
+                                               inheritance.type = InheritanceType.ComplexType;\r
+                                       } else {\r
+                                               TypeEntry entry = getTypeEntry(type);\r
+                                               if (entry != null) {\r
+                                                       inheritance.type = InheritanceType.AtomicType;\r
+                                                       inheritance.atomicType = entry;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (inheritance.type == InheritanceType.None) {\r
+                               QName type = topLevelElement.getSubstitutionGroup();\r
+                               if (type != null) {\r
+                                       if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                                               SchemaObject obj = getWithName(topLevelObj, type.getLocalPart());\r
+                                               inheritance.baseClass = getName(obj);\r
+                                               inheritance.type = InheritanceType.ComplexType;\r
+                                       } else {\r
+                                               TypeEntry entry = getTypeEntry(type);\r
+                                               if (entry != null) {\r
+                                                       inheritance.type = InheritanceType.AtomicType;\r
+                                                       inheritance.atomicType = entry;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               } else if (topLevelObj.getType() == ObjectType.COMPLEX_TYPE) {\r
+                       ComplexType complexType = topLevelObj.getComplexType();\r
+                       QName type = getComplexTypeBase(complexType);\r
+                       inheritance = new Inheritance(getBaseClass(ObjectType.COMPLEX_TYPE));\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
+                                       inheritance.baseClass = getName(obj);\r
+                                       inheritance.type = InheritanceType.ComplexType;\r
+                               }\r
+                       }\r
+                       SimpleContent simpleContent = complexType.getSimpleContent();\r
+                       if (simpleContent != null) {\r
+                               ExtensionType extensionType = simpleContent.getExtension();\r
+                               if (extensionType != null) {\r
+                                       type = extensionType.getBase();\r
+                                       getAtomicTypeInheritance(type, topLevelObj, inheritance);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return inheritance;\r
+       }       \r
+       /**\r
+        * Goes through chain of SimpleTypes until locates Atomic Type (type defined in XML schema). \r
+        * @param type\r
+        * @param topLevelObj\r
+        * @param inheritance\r
+        */\r
+       protected void getAtomicTypeInheritance(QName type, SchemaObject topLevelObj, Inheritance inheritance) {\r
+               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                       SchemaObject obj = getWithName(topLevelObj, type.getLocalPart());\r
+                       if (obj.getType() != ObjectType.SIMPLE_TYPE)\r
+                               throw new RuntimeException("SimpleContent does not use SimpleType definition");\r
+                       SimpleType simpleType = obj.getSimpleType();\r
+                       type = getSimpleTypeBase(simpleType);\r
+                       getAtomicTypeInheritance(type, topLevelObj, inheritance);\r
+               } else {\r
+                       TypeEntry entry = getTypeEntry(type);\r
+                       if (entry != null) {\r
+                               inheritance.type = InheritanceType.AtomicType;\r
+                               inheritance.atomicType = entry;\r
+                       }\r
+               }\r
+       }\r
 \r
 }\r