\r
XMLStreamWriter delegate;\r
int depth = 0;\r
+ boolean indent = true;\r
\r
public IndentingXMLStreamWriter(XMLStreamWriter delegate) {\r
this.delegate = delegate;\r
}\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
\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
\r
@Override\r
public void writeComment(String data) throws XMLStreamException {\r
- delegate.writeComment(data);\r
- \r
+ delegate.writeComment(data); \r
}\r
\r
@Override\r
@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
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
}\r
\r
@Override\r
- protected String getBaseClass() {\r
+ protected String getBaseClass(ObjectType type) {\r
return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
}\r
\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
-// 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
// 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
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
\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
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
\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
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
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
// 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
\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
// } \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(" }");\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
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
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
\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
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
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
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
\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
\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
}\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
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
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
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
\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
} \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
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
}\r
\r
@Override\r
- protected String getBaseClass() {\r
+ protected String getBaseClass(ObjectType type) {\r
return "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
}\r
\r
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
}\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
\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
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
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
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
}\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
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
}\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
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
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
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
}\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
// 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
\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
// 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
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
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
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
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
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
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
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
}\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