package org.simantics.xml.sax.base;\r
\r
+import java.io.BufferedOutputStream;\r
import java.io.File;\r
import java.io.FileOutputStream;\r
import java.io.IOException;\r
+import java.io.OutputStream;\r
\r
import javax.xml.stream.XMLOutputFactory;\r
import javax.xml.stream.XMLStreamException;\r
private ILogger logger;\r
private Resource root;\r
private XMLWriter xmlWriter;\r
+ private boolean indentOutput = true;\r
\r
public AbstractExporter(Session session, File file , Resource root, XMLWriter xmlWriter) {\r
this.session = session;\r
this.xmlWriter = xmlWriter;\r
}\r
\r
+ public void setIndentOutput(boolean indentOutput) {\r
+ this.indentOutput = indentOutput;\r
+ }\r
+ \r
public void doExport() throws DatabaseException {\r
doExport(MessageService.getDefault()); \r
}\r
session.syncRequest(req);\r
}\r
\r
+ private static XMLStreamWriter createIdentXMLStreamWriter(OutputStream textWriter) throws XMLStreamException {\r
+ XMLOutputFactory output = XMLOutputFactory.newInstance();\r
+ return new IndentingXMLStreamWriter(output.createXMLStreamWriter(textWriter, "UTF-8"));\r
+ //return new com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter(output.createXMLStreamWriter(textWriter, "UTF-8"));\r
+ }\r
+ \r
+ private static XMLStreamWriter createXMLStreamWriter(OutputStream textWriter) throws XMLStreamException {\r
+ XMLOutputFactory output = XMLOutputFactory.newInstance();\r
+ return output.createXMLStreamWriter(textWriter, "UTF-8");\r
+ }\r
+ \r
\r
private class ExportRequest extends ReadRequest {\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
XMLStreamWriter writer = null;\r
+ OutputStream os = null;\r
try {\r
- XMLOutputFactory output = XMLOutputFactory.newInstance();\r
- writer = output.createXMLStreamWriter(new FileOutputStream(file),"UTF-8");\r
- writer.writeStartDocument("UTF-8", "1.0");\r
+ os = new BufferedOutputStream(new FileOutputStream(file));\r
+ if (indentOutput)\r
+ writer =createIdentXMLStreamWriter(os);\r
+ else\r
+ writer =createXMLStreamWriter(os);\r
+ writer.writeStartDocument("UTF-8", "1.1");\r
+ \r
xmlWriter.write(root, writer);\r
\r
writer.writeEndDocument();\r
+ writer.flush();\r
writer.close();\r
+ os.close();\r
} catch (IOException|XMLStreamException e) {\r
try {\r
writer.close();\r
} catch (XMLStreamException err) {\r
\r
+ }\r
+ try {\r
+ os.close();\r
+ }catch (IOException err) {\r
+ \r
}\r
throw new DatabaseException(e);\r
} \r
--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import javax.xml.namespace.NamespaceContext;\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+/**\r
+ * Rather dummy indenting XML Stream Writer.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class IndentingXMLStreamWriter implements XMLStreamWriter{\r
+ \r
+ XMLStreamWriter delegate;\r
+ int depth = 0;\r
+ \r
+ public IndentingXMLStreamWriter(XMLStreamWriter delegate) {\r
+ this.delegate = delegate;\r
+ }\r
+ \r
+ @Override\r
+ public void close() throws XMLStreamException {\r
+ delegate.close();\r
+ }\r
+ \r
+ @Override\r
+ public void flush() throws XMLStreamException {\r
+ delegate.close();\r
+ }\r
+ \r
+ @Override\r
+ public NamespaceContext getNamespaceContext() {\r
+ return delegate.getNamespaceContext();\r
+ }\r
+ \r
+ @Override\r
+ public String getPrefix(String uri) throws XMLStreamException {\r
+ return delegate.getPrefix(uri);\r
+ }\r
+ \r
+ @Override\r
+ public Object getProperty(String name) throws IllegalArgumentException {\r
+ return delegate.getProperty(name);\r
+ }\r
+ \r
+ @Override\r
+ public void setDefaultNamespace(String uri) throws XMLStreamException {\r
+ delegate.setDefaultNamespace(uri);\r
+ }\r
+ \r
+ @Override\r
+ public void setPrefix(String prefix, String uri) throws XMLStreamException {\r
+ delegate.setPrefix(prefix, uri);\r
+ }\r
+ \r
+ private String getIdent() {\r
+ String s = "";\r
+ for (int i = 0; i < depth; i++)\r
+ s += " ";\r
+ return s;\r
+ }\r
+\r
+ @Override\r
+ public void writeStartElement(String localName) throws XMLStreamException {\r
+ delegate.writeCharacters("\n"+getIdent());\r
+ delegate.writeStartElement(localName);\r
+ depth++;\r
+ }\r
+\r
+ @Override\r
+ public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {\r
+ delegate.writeCharacters("\n"+getIdent());\r
+ delegate.writeStartElement(namespaceURI, localName);\r
+ depth++;\r
+ }\r
+\r
+ @Override\r
+ public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {\r
+ delegate.writeCharacters("\n"+getIdent());\r
+ delegate.writeStartElement(prefix, localName, namespaceURI);\r
+ depth++;\r
+ }\r
+\r
+ @Override\r
+ public void writeStartDocument() throws XMLStreamException {\r
+ delegate.writeStartDocument();\r
+ depth++;\r
+ }\r
+\r
+ @Override\r
+ public void writeStartDocument(String version) throws XMLStreamException {\r
+ delegate.writeStartDocument(version);\r
+ depth++;\r
+ }\r
+\r
+ @Override\r
+ public void writeStartDocument(String encoding, String version) throws XMLStreamException {\r
+ delegate.writeStartDocument(encoding, version);\r
+ depth++;\r
+ }\r
+\r
+ @Override\r
+ public void writeEndElement() throws XMLStreamException {\r
+ depth--;\r
+ delegate.writeCharacters("\n"+getIdent());\r
+ delegate.writeEndElement();\r
+ }\r
+ \r
+ @Override\r
+ public void writeEndDocument() throws XMLStreamException {\r
+ depth--;\r
+ delegate.writeCharacters("\n"+getIdent());\r
+ delegate.writeEndDocument();\r
+ }\r
+ \r
+ @Override\r
+ public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {\r
+ delegate.writeEmptyElement(namespaceURI, localName);\r
+ }\r
+\r
+ @Override\r
+ public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {\r
+ delegate.writeEmptyElement(prefix, localName, namespaceURI);\r
+ }\r
+\r
+ @Override\r
+ public void writeEmptyElement(String localName) throws XMLStreamException {\r
+ delegate.writeEmptyElement(localName);\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
+ public void writeAttribute(String prefix, String namespaceURI, String localName, String value)\r
+ throws XMLStreamException {\r
+ delegate.writeAttribute(prefix, namespaceURI, localName, value);\r
+ }\r
+\r
+ @Override\r
+ public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {\r
+ delegate.writeAttribute(namespaceURI, localName, value);\r
+ }\r
+\r
+ @Override\r
+ public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {\r
+ delegate.writeNamespace(prefix, namespaceURI); \r
+ }\r
+\r
+ @Override\r
+ public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {\r
+ delegate.writeDefaultNamespace(namespaceURI);\r
+ }\r
+\r
+ @Override\r
+ public void writeComment(String data) throws XMLStreamException {\r
+ delegate.writeComment(data);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void writeProcessingInstruction(String target) throws XMLStreamException {\r
+ delegate.writeProcessingInstruction(target);\r
+ }\r
+\r
+ @Override\r
+ public void writeProcessingInstruction(String target, String data) throws XMLStreamException {\r
+ delegate.writeProcessingInstruction(target, data);\r
+ }\r
+\r
+ @Override\r
+ public void writeCData(String data) throws XMLStreamException {\r
+ delegate.writeCData(data);\r
+ }\r
+\r
+ @Override\r
+ public void writeDTD(String dtd) throws XMLStreamException {\r
+ delegate.writeDTD(dtd); \r
+ }\r
+\r
+ @Override\r
+ public void writeEntityRef(String name) throws XMLStreamException {\r
+ delegate.writeEntityRef(name);\r
+ }\r
+\r
+ \r
+\r
+ @Override\r
+ public void writeCharacters(String text) throws XMLStreamException {\r
+ delegate.writeCharacters(text);\r
+ }\r
+\r
+ @Override\r
+ public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {\r
+ delegate.writeCharacters(text, start, len);\r
+ }\r
+\r
+ @Override\r
+ public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {\r
+ delegate.setNamespaceContext(context);\r
+ }\r
+ \r
+\r
+}\r
import java.util.Collection;\r
import java.util.Collections;\r
import java.util.List;\r
+import java.util.Set;\r
\r
import javax.xml.stream.XMLStreamException;\r
import javax.xml.stream.XMLStreamWriter;\r
}\r
\r
@Override\r
- public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ public void children(ReadGraph graph, WriterElement instance, Set<Resource> sorted)\r
throws XMLStreamException, DatabaseException {\r
- return Collections.EMPTY_LIST;\r
+ \r
}\r
\r
@Override\r
package org.simantics.xml.sax.base;\r
\r
-import java.util.Collections;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
-import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.scl.compiler.elaboration.errors.ElabNode;\r
\r
public abstract class XMLElementNamedChildWriterBase implements XMLElementNamedChildWriter{\r
\r
}\r
\r
@Override\r
- public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ public void children(ReadGraph graph, WriterElement instance, Set<Resource> sorted)\r
throws XMLStreamException, DatabaseException {\r
- return Collections.EMPTY_LIST;\r
+ \r
}\r
\r
@Override\r
package org.simantics.xml.sax.base;\r
\r
import java.util.Collection;\r
-import java.util.List;\r
+import java.util.Set;\r
\r
import javax.xml.stream.XMLStreamException;\r
import javax.xml.stream.XMLStreamWriter;\r
public void start(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
- public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+ public void children(ReadGraph graph, WriterElement instance, Set<Resource> writer) throws XMLStreamException, DatabaseException;\r
public void end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
\r
}\r
import java.lang.reflect.InvocationTargetException;\r
import java.util.Collection;\r
import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.LinkedHashSet;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
\r
XMLElementWriter elementWriter = instance.writer;\r
elementWriter.start(graph, instance, writer);\r
+ if (instance.parent == null) {\r
+ if(getSchemaURI() != null) {\r
+ writer.writeDefaultNamespace(getSchemaURI());\r
+ }\r
+ }\r
elementWriter.attributes(graph, instance, graph.getStatements(instance.instance, XML.hasAttribute), writer);\r
if (graph.hasValue(instance.instance))\r
elementWriter.characters(graph, instance, writer);\r
loadElement(c);\r
elementMap.put(s.getObject(), c);\r
}\r
- List<Resource> sorted = elementWriter.children(graph, instance, writer);\r
- \r
+ LinkedHashSet<Resource> sorted = new LinkedHashSet<>();\r
+ if (graph.hasStatement(instance.instance, XML.hasOriginalElementList)) {\r
+ Resource originalList = graph.getSingleObject(instance.instance, XML.hasOriginalElementList);\r
+ List<Resource> l = ListUtils.toList(graph, originalList);\r
+ sorted.addAll(l);\r
+ }\r
+ elementWriter.children(graph, instance, sorted);\r
+ Set<Resource> processed = new HashSet<>();\r
for (Resource r : sorted) {\r
+ if (processed.contains(r)) // badly generated writer could report elements several times. \r
+ continue;\r
WriterElement child = elementMap.get(r);\r
write(child, writer);\r
+ processed.add(r);\r
}\r
//write the rest of the elements (in random order) \r
for (Statement stm : childElements) {\r
- if (sorted.contains(stm.getObject()))\r
+ if (processed.contains(stm.getObject()))\r
continue;\r
WriterElement child = elementMap.get(stm.getObject());\r
write(child, writer);\r
\r
}\r
\r
-// public void write(Resource root, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
-// XMLResource XML = XMLResource.getInstance(graph);\r
-// \r
-// Deque<Element> stack = new ArrayDeque<>();\r
-// Element rootElement = new Element(root);\r
-// loadElement(rootElement);\r
-// stack.push(rootElement);\r
-// while (!stack.isEmpty()) {\r
-// \r
-// Element instance = stack.pop();\r
-// XMLElementWriter elementWriter = instance.writer;\r
-// elementWriter.start(graph, instance.instance, writer);\r
-// elementWriter.attributes(graph, graph.getStatements(instance.instance, XML.hasAttribute), writer);\r
-// // get all child elements\r
-// Collection<Statement> childElements = graph.getStatements(instance.instance, XML.hasElement);\r
-// // get original element order, if available\r
-// Resource originalElementList = graph.getPossibleObject(instance.instance, XML.hasOriginalElementList);\r
-// List<Resource> originalList = null;\r
-// if (originalElementList != null) {\r
-// originalList = ListUtils.toList(graph, originalElementList);\r
-// }\r
-// if (originalList != null) {\r
-// // check for elements that are missing form the original list (should be empty). \r
-// for (Statement stm : childElements) {\r
-// if (originalList.contains(stm.getObject()))\r
-// continue;\r
-// Element child = new Element(instance,stm.getObject());\r
-// loadElement(child);\r
-// stack.push(child);\r
-// }\r
-// // process the list in reverse order so that the stack processing processes the items in correct order.\r
-// for (int i = originalList.size()-1; i >= 0; i--) {\r
-// Resource r = originalList.get(i);\r
-// Element child = new Element(instance, r);\r
-// loadElement(child);\r
-// stack.push(child);\r
-// }\r
-// } else {\r
-// for (Statement stm : childElements) {\r
-// Element child = new Element(instance, stm.getObject());\r
-// loadElement(child);\r
-// stack.push(child);\r
-// }\r
-// }\r
-// }\r
-// }\r
- \r
private void loadElement(WriterElement child) throws DatabaseException {\r
XMLElementWriter childWriter = null;\r
if (child.parent != null && child.parent.writer instanceof XMLElementNamedChildWriter) {\r
\r
@Override\r
public String toString() {\r
- return year + "-" + month + "-"+day;\r
+ return year + "-" +(month<10?"0":"")+ month + "-"+(day<10?"0":"")+day;\r
}\r
\r
\r
\r
@Override\r
public String toString() {\r
- return year + "-" + month + "-"+day + "T"+hours+ ":" + minutes + ":"+seconds;\r
+ return year + "-" +(month<10?"0":"")+ month + "-"+(day<10?"0":"")+day + "T"+(hours<10?"0":"")+hours+ ":" + (minutes<10?"0":"")+ minutes + ":"+(seconds<10?"0":"")+seconds;\r
}\r
\r
}\r
\r
@Override\r
public String toString() {\r
- return hours+ ":" + minutes + ":"+seconds;\r
+ return (hours<10?"0":"")+hours+ ":" + (minutes<10?"0":"")+ minutes + ":"+(seconds<10?"0":"")+seconds;\r
}\r
\r
}\r
import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
import org.simantics.xml.sax.configuration.AttributeComposition;\r
import org.simantics.xml.sax.configuration.Configuration;\r
import org.simantics.xml.sax.configuration.IDProvider;\r
import org.simantics.xml.sax.configuration.IDReference;\r
-import org.simantics.xml.sax.configuration.Rename;\r
import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
import org.w3._2001.xmlschema.Annotated;\r
import org.w3._2001.xmlschema.Attribute;\r
\r
fw.writer.println(" }");\r
\r
-// fw.writer.println(" @Override");\r
-// fw.writer.println(" public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException{");\r
-// fw.writer.println(" "+getOntologyImport());\r
-// \r
-// if (stringWriter.getBuffer().length() > 0) {\r
-// fw.writer.write(stringWriter.toString());\r
-// }\r
-// \r
-// \r
-// fw.writer.println(" return false;");\r
-// fw.writer.println(" }");\r
-// fw.writer.println();\r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void children(ReadGraph graph, WriterElement instance, java.util.Set<org.simantics.db.Resource> result) throws XMLStreamException, DatabaseException {");\r
+ fw.writer.println(" "+getOntologyImport());\r
+ \r
+ if (stringWriter.getBuffer().length() > 0) {\r
+ fw.writer.write(stringWriter.toString());\r
+ }\r
+ \r
+ fw.writer.println(" }");\r
+ fw.writer.println();\r
\r
if (stringWriter2.getBuffer().length() > 0) {\r
fw.writer.write(stringWriter2.toString());\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, 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 binding = getBindingFromPrimitiveType(refType);\r
- if (binding == null) {\r
- SchemaObject refElement = elementName.get(refType.getLocalPart());\r
- SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
-\r
- String className = null;\r
- String refClassName = null;\r
- if (refElement != null)\r
- className = getName(refElement);\r
- else\r
- className = getName(refComplexType);\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
+ } else {\r
+ refType = element.getElement().getRef();\r
+ if (refName == null)\r
+ refName = refType.getLocalPart();\r
+ }\r
\r
- if (refComplexType != null) {\r
- refClassName = getName(refComplexType);\r
+ String binding = getBindingFromPrimitiveType(refType);\r
+ if (binding == null) {\r
+ SchemaObject refElement = elementName.get(refType.getLocalPart());\r
+ SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
+ \r
+ String className = null;\r
+ String refClassName = null;\r
+ if (refElement != null)\r
+ className = getName(refElement);\r
+ else\r
+ className = getName(refComplexType);\r
+ \r
+ if (refComplexType != null) {\r
+ refClassName = getName(refComplexType);\r
+ } else {\r
+ refClassName = 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
+ // 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
+ \r
+ // element type specific list\r
+ fw.delayedWriter.println(" {");\r
+ fw.delayedWriter.println(" org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
+ fw.delayedWriter.println(" if (list != null) {");\r
+ fw.delayedWriter.println(" java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");\r
+ fw.delayedWriter.println(" result.addAll(l);");\r
+ fw.delayedWriter.println(" } else {");\r
+ fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
+ fw.delayedWriter.println(" }");\r
+ fw.delayedWriter.println(" }");\r
+ } else {\r
+ fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
+ }\r
+ // if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
+ // // generic list\r
+ // fw.delayedWriter.println(" {");\r
+ // fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");\r
+ // fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\r
+ // fw.delayedWriter.println(" if (list == null) {");\r
+ // fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
+ // fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");\r
+ // fw.delayedWriter.println(" } else {");\r
+ // fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
+ // fw.delayedWriter.println(" }");\r
+ // fw.delayedWriter.println(" }");\r
+ // }\r
+ \r
+ // fw.delayedWriter.println(" return true;");\r
+ // fw.delayedWriter.println(" }");\r
} else {\r
- refClassName = getName(refElement);\r
+ SchemaObject refElement = elementName.get(refType.getLocalPart());\r
+ //writer.println(commentTag+ontShort+"."+parent+".has"+ref + " <R " + ontShort+".hasElement");\r
+ fw.writer.println(" addRelationWriter("+ ontShort +getName(parent) + "_has"+refName+", "+getName(parent) +"_" +refName+".class);");\r
+ \r
+ fw.delayedWriter2.println(" public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementWriter {");\r
+ fw.delayedWriter2.println(" public "+ getName(parent) +"_" +refName +"(){");\r
+ //fw.delayedWriter2.println(" super(\""+ref+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+ref+", "+binding+");");\r
+ fw.delayedWriter2.println(" super(\""+refName+"\",null, "+binding+");");\r
+ fw.delayedWriter2.println(" }");\r
+ fw.delayedWriter2.println(" }");\r
}\r
+ } else {\r
+ Element attrs= element.getElement();\r
+ SchemaObject obj = getWithObj(parent, attrs);\r
\r
- if (!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
+ String className = getName(obj);\r
+ if (refName == null) {\r
+ refName = obj.getName();//attrs.getName();\r
+ }\r
+\r
+ //if (!reference)\r
+ fw.writer.println(" addTypeWriter("+ ontShort+getName(obj) +", "+className+".class);");\r
+// else\r
+// fw.writer.println(" addWriter("+className+".class);");\r
\r
-// fw.delayedWriter.println(" if (child.getElementParser() instanceof "+refClassName+"){");\r
+// fw.delayedWriter.println(" if (child.getElementParser() instanceof "+className+"){");\r
// fw.delayedWriter.println(" graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
-// if (useElementList(parent, indicator,element, reference, ref, refType)) {\r
-// \r
+ if (useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {\r
+ \r
+ // element type specific list\r
+ fw.delayedWriter.println(" {");\r
+ fw.delayedWriter.println(" org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
+ fw.delayedWriter.println(" if (list != null) {");\r
+ fw.delayedWriter.println(" java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");\r
+ fw.delayedWriter.println(" result.addAll(l);");\r
+ fw.delayedWriter.println(" } else {");\r
+ fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
+ fw.delayedWriter.println(" }");\r
+ fw.delayedWriter.println(" }");\r
+ } else {\r
+ fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
+ }\r
// // element type specific list\r
// fw.delayedWriter.println(" {");\r
// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List);");\r
// fw.delayedWriter.println(" }");\r
// fw.delayedWriter.println(" }");\r
// }\r
-// if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
+// if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
// // generic list\r
// fw.delayedWriter.println(" {");\r
// fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");\r
// \r
// fw.delayedWriter.println(" return true;");\r
// fw.delayedWriter.println(" }");\r
- } else {\r
- SchemaObject refElement = elementName.get(refType.getLocalPart());\r
- //writer.println(commentTag+ontShort+"."+parent+".has"+ref + " <R " + ontShort+".hasElement");\r
- fw.writer.println(" addRelationWriter("+ ontShort +getName(parent) + "_has"+ref+", "+getName(parent) +"_" +ref+".class);");\r
- \r
- fw.delayedWriter2.println(" public static class " + getName(parent) +"_" +ref+" extends org.simantics.xml.sax.base.ValueElementWriter {");\r
- fw.delayedWriter2.println(" public "+ getName(parent) +"_" +ref +"(){");\r
- //fw.delayedWriter2.println(" super(\""+ref+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+ref+", "+binding+");");\r
- fw.delayedWriter2.println(" super(\""+ref+"\",null, "+binding+");");\r
- fw.delayedWriter2.println(" }");\r
- fw.delayedWriter2.println(" }");\r
}\r
}\r
\r
- @Override\r
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String ref, OpenAttrs attrs) {\r
- FileWriter fw = getWriter(parent);\r
- SchemaObject obj = getWithObj(parent, attrs);\r
\r
- String className = getName(obj);\r
-\r
- if (!reference)\r
- fw.writer.println(" addTypeWriter("+ ontShort+getName(obj) +", "+className+".class);");\r
- else\r
- fw.writer.println(" addWriter("+className+".class);");\r
- \r
- fw.delayedWriter.println(" if (child.getElementParser() instanceof "+className+"){");\r
- fw.delayedWriter.println(" graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
-// if (useElementList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
-//\r
-// // element type specific list\r
-// fw.delayedWriter.println(" {");\r
-// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List);");\r
-// fw.delayedWriter.println(" if (list == null) {");\r
-// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
-// fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List,list);");\r
-// fw.delayedWriter.println(" } else {");\r
-// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
-// fw.delayedWriter.println(" }");\r
-// fw.delayedWriter.println(" }");\r
-// }\r
-// if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
-// // generic list\r
-// fw.delayedWriter.println(" {");\r
-// fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");\r
-// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\r
-// fw.delayedWriter.println(" if (list == null) {");\r
-// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
-// fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");\r
-// fw.delayedWriter.println(" } else {");\r
-// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
-// fw.delayedWriter.println(" }");\r
-// fw.delayedWriter.println(" }");\r
-// }\r
-// \r
-// fw.delayedWriter.println(" return true;");\r
-// fw.delayedWriter.println(" }");\r
- \r
- }\r
\r
@Override\r
protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) { \r
fw.delayedWriter2.println(" return null;");\r
fw.delayedWriter2.println(" }");\r
}\r
- \r
- \r
- \r
- \r
+\r
@Override \r
protected void handle(SchemaObject parent, Attribute attribute) {\r
String name = attribute.getName();\r
fw.writer.println(" }");\r
fw.writer.println(" }");\r
\r
+ \r
// fw.writer.println(" @Override");\r
// fw.writer.println(" public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
// if (inhertiance.type == InheritanceType.ComplexType) {\r
\r
fw.writer.println(" }");\r
\r
-// fw.writer.println(" @Override");\r
-// fw.writer.println(" public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException{");\r
-// fw.writer.println(" "+getOntologyImport());\r
-// \r
-// if (stringWriter.getBuffer().length() > 0) {\r
-// fw.writer.write(stringWriter.toString());\r
-// }\r
-// if (inhertiance.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
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void children(ReadGraph graph, WriterElement instance, java.util.Set<org.simantics.db.Resource> result) throws XMLStreamException, DatabaseException {");\r
+ fw.writer.println(" "+getOntologyImport());\r
\r
+ if (stringWriter.getBuffer().length() > 0) {\r
+ fw.writer.write(stringWriter.toString());\r
+ }\r
+ \r
+ if (inhertiance.type == InheritanceType.ComplexType) {\r
+ fw.writer.println(" super.children(graph,instance,result);");\r
+ }\r
+ \r
+ fw.writer.println(" }");\r
+ fw.writer.println();\r
+ \r
if (stringWriter2.getBuffer().length() > 0) {\r
fw.writer.write(stringWriter2.toString());\r
}\r
import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
import org.simantics.xml.sax.configuration.AttributeComposition;\r
import org.simantics.xml.sax.configuration.Configuration;\r
import org.simantics.xml.sax.configuration.IDProvider;\r
}\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, 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 binding = getBindingFromPrimitiveType(refType);\r
- if (binding == null) {\r
- SchemaObject refElement = elementName.get(refType.getLocalPart());\r
- SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
-\r
- String className = null;\r
- String refClassName = null;\r
- if (refElement != null)\r
- className = getName(refElement);\r
- else\r
- className = getName(refComplexType);\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
+ } else {\r
+ refType = element.getElement().getRef();\r
+ if (refName == null)\r
+ refName = refType.getLocalPart();\r
+ }\r
\r
- if (refComplexType != null) {\r
- refClassName = getName(refComplexType);\r
+ String binding = getBindingFromPrimitiveType(refType);\r
+ if (binding == null) {\r
+ SchemaObject refElement = elementName.get(refType.getLocalPart());\r
+ SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
+ \r
+ String className = null;\r
+ String refClassName = null;\r
+ if (refElement != null)\r
+ className = getName(refElement);\r
+ else\r
+ className = getName(refComplexType);\r
+ \r
+ if (refComplexType != null) {\r
+ refClassName = getName(refComplexType);\r
+ } else {\r
+ refClassName = 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
+ \r
+ fw.delayedWriter.println(" if (child.getElementParser() instanceof "+refClassName+"){");\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
+ // element type specific list\r
+ fw.delayedWriter.println(" {");\r
+ fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
+ fw.delayedWriter.println(" if (list == null) {");\r
+ fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
+ fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List,list);");\r
+ fw.delayedWriter.println(" } else {");\r
+ fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
+ fw.delayedWriter.println(" }");\r
+ fw.delayedWriter.println(" }");\r
+ }\r
+ if (useOriginalList(parent, indicator,element, referenceType == RefType.Reference, refName, refType)) {\r
+ // generic list\r
+ fw.delayedWriter.println(" {");\r
+ fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");\r
+ fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\r
+ fw.delayedWriter.println(" if (list == null) {");\r
+ fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
+ fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");\r
+ fw.delayedWriter.println(" } else {");\r
+ fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
+ fw.delayedWriter.println(" }");\r
+ fw.delayedWriter.println(" }");\r
+ }\r
+ \r
+ fw.delayedWriter.println(" return true;");\r
+ fw.delayedWriter.println(" }");\r
} else {\r
- refClassName = getName(refElement);\r
+ //writer.println(commentTag+ontShort+"."+parent+".has"+ref + " <R " + ontShort+".hasElement");\r
+ fw.writer.println(" addParser(\""+ refName +"\", "+getName(parent) +"_" +refName+".class);");\r
+ \r
+ fw.delayedWriter2.println(" public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementParser {");\r
+ fw.delayedWriter2.println(" public "+ getName(parent) +"_" +refName +"(){");\r
+ fw.delayedWriter2.println(" super(\""+refName+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+refName+", "+binding+");");\r
+ fw.delayedWriter2.println(" }");\r
+ fw.delayedWriter2.println(" }");\r
}\r
+ } else {\r
+ Element attrs= element.getElement();\r
+ SchemaObject obj = getWithObj(parent, attrs);\r
\r
- if (!reference)\r
- fw.writer.println(" addParser(\""+ ref +"\", "+className+".class);");\r
- else\r
- fw.writer.println(" addParser("+className+".class);");\r
- if (!className.equals(refClassName))\r
- fw.writer.println(" addParser("+refClassName+".class);");\r
+ String className = getName(obj);\r
+ if (refName == null)\r
+ refName = attrs.getName();\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, reference, ref, refType)) {\r
- \r
+ \r
+ //if (!reference)\r
+ fw.writer.println(" addParser(\""+ refName +"\", "+className+".class);");\r
+// else\r
+// fw.writer.println(" addParser("+className+".class);");\r
+ \r
+ fw.delayedWriter.println(" if (child.getElementParser() instanceof "+className+"){");\r
+ fw.delayedWriter.println(" graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+refName + ", child.getData());");\r
+ if (useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {\r
+\r
// element type specific list\r
fw.delayedWriter.println(" {");\r
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List);");\r
+ fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
fw.delayedWriter.println(" if (list == null) {");\r
fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
- fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List,list);");\r
+ fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "List,list);");\r
fw.delayedWriter.println(" } else {");\r
fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
fw.delayedWriter.println(" }");\r
fw.delayedWriter.println(" }");\r
}\r
- if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
+ if (useOriginalList(parent, indicator,element, false, refName, new QName(obj.getName()))) {\r
// generic list\r
fw.delayedWriter.println(" {");\r
fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");\r
\r
fw.delayedWriter.println(" return true;");\r
fw.delayedWriter.println(" }");\r
- } else {\r
- //writer.println(commentTag+ontShort+"."+parent+".has"+ref + " <R " + ontShort+".hasElement");\r
- fw.writer.println(" addParser(\""+ ref +"\", "+getName(parent) +"_" +ref+".class);");\r
- \r
- fw.delayedWriter2.println(" public static class " + getName(parent) +"_" +ref+" extends org.simantics.xml.sax.base.ValueElementParser {");\r
- fw.delayedWriter2.println(" public "+ getName(parent) +"_" +ref +"(){");\r
- fw.delayedWriter2.println(" super(\""+ref+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+ref+", "+binding+");");\r
- fw.delayedWriter2.println(" }");\r
- fw.delayedWriter2.println(" }");\r
- }\r
- }\r
- \r
- @Override\r
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String ref, OpenAttrs attrs) {\r
- FileWriter fw = getWriter(parent);\r
- SchemaObject obj = getWithObj(parent, attrs);\r
- \r
- String className = getName(obj);\r
-\r
- if (!reference)\r
- fw.writer.println(" addParser(\""+ ref +"\", "+className+".class);");\r
- else\r
- fw.writer.println(" addParser("+className+".class);");\r
- \r
- fw.delayedWriter.println(" if (child.getElementParser() instanceof "+className+"){");\r
- fw.delayedWriter.println(" graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
- if (useElementList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
-\r
- // element type specific list\r
- fw.delayedWriter.println(" {");\r
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List);");\r
- fw.delayedWriter.println(" if (list == null) {");\r
- fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
- fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List,list);");\r
- fw.delayedWriter.println(" } else {");\r
- fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
- fw.delayedWriter.println(" }");\r
- fw.delayedWriter.println(" }");\r
- }\r
- if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
- // generic list\r
- fw.delayedWriter.println(" {");\r
- fw.delayedWriter.println(" XMLResource XML = XMLResource.getInstance(graph);");\r
- fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\r
- fw.delayedWriter.println(" if (list == null) {");\r
- fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
- fw.delayedWriter.println(" graph.claim(element.getData(), XML.hasOriginalElementList,list);");\r
- fw.delayedWriter.println(" } else {");\r
- fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
- fw.delayedWriter.println(" }");\r
- fw.delayedWriter.println(" }");\r
}\r
- \r
- fw.delayedWriter.println(" return true;");\r
- fw.delayedWriter.println(" }");\r
- \r
}\r
\r
@Override\r
return "AttributeGroups_";\r
}\r
\r
- @Override\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);\r
- String refName = localElement.getName();\r
- QName refType = localElement.getType();\r
- if (refType != null)\r
- handleIndicator(parent, indicator, element, false, refName, refType);\r
- else {\r
- handleElement(eObj);\r
- handleIndicator(parent, indicator, element, false, refName, localElement);\r
- }\r
- } else if (localElement.getRef() != null) {\r
- QName refType = localElement.getRef();\r
- handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType);\r
- }\r
- }\r
+// @Override\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);\r
+// String refName = localElement.getName();\r
+// QName refType = localElement.getType();\r
+// if (refType != null)\r
+// handleIndicator(parent, indicator, element, false, refName, refType);\r
+// else {\r
+// handleElement(eObj);\r
+// handleIndicator(parent, indicator, element, false, refName, localElement);\r
+// }\r
+// } else if (localElement.getRef() != null) {\r
+// QName refType = localElement.getRef();\r
+// handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType);\r
+// }\r
+// }\r
\r
@Override\r
protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {\r
if (localElement.getName() != null) {\r
QName refType = localElement.getType();\r
if (refType != null)\r
- handleIndicator(parent, indicator, e, false, name, refType);\r
+ //handleIndicator(parent, indicator, e, false, name, refType);\r
+ handleIndicator(parent, indicator, e, name, RefType.Type);\r
} else if (localElement.getRef() != null) {\r
- QName refType = localElement.getRef();\r
- handleIndicator(parent, indicator, e, true, name, refType);\r
+ //QName refType = localElement.getRef();\r
+ //handleIndicator(parent, indicator, e, true, name, refType);\r
+ handleIndicator(parent, indicator, e, name, RefType.Reference);\r
}\r
}\r
}\r
\r
\r
@Override\r
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, QName refType) {\r
- String type = getL0TypeFromPrimitiveType(refType);\r
- SchemaObject obj = null;\r
- if (type == null) {\r
- obj = getWithName(parent, refType.getLocalPart());\r
+ //protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, QName refType) {\r
+ protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {\r
+ if (refType != refType.Element) {\r
+ QName referenceType = null;\r
+ if (refType == RefType.Type) {\r
+ referenceType = element.getElement().getType();\r
+ //refName = element.getElement().getName()\r
+ SchemaObject eObj = elements.get(element.getElement());\r
+ if (refName == null)\r
+ refName = eObj.getName();\r
+ } else {\r
+ referenceType = element.getElement().getRef();\r
+ if (refName == null)\r
+ refName = referenceType.getLocalPart();\r
+ }\r
+ String type = getL0TypeFromPrimitiveType(referenceType);\r
+ SchemaObject obj = null;\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
+ } else {\r
+ writer.println(ontRoot+getName(parent)+".has"+refName + " <R XML.hasElement");\r
+ writer.println(" --> " + getType(referenceType));\r
+ }\r
\r
- writer.println(ontRoot+getName(parent)+".has"+refName + " <R " + ontRoot+ getName(obj,"has"));\r
- writer.println(" --> " + ontRoot+getName(obj));\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
+ } 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
+ }\r
+ }\r
} else {\r
- writer.println(ontRoot+getName(parent)+".has"+refName + " <R XML.hasElement");\r
- writer.println(" --> " + getType(refType));\r
- }\r
- \r
- if (useElementList(parent, indicator,element, reference, refName, refType)) {\r
+ Element attrs = element.getElement();\r
+ SchemaObject obj = getWithObj(parent, attrs);\r
+ if (refName == null)\r
+ refName = obj.getName();\r
\r
- if (type == null) {\r
+ writer.println(ontRoot+getName(parent)+".has"+refName + " <R " + ontRoot+ getName(obj,"has"));\r
+ writer.println(" --> " + ontRoot+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
- } 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
}\r
}\r
- }\r
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, OpenAttrs attrs) {\r
- SchemaObject obj = getWithObj(parent, attrs);\r
- writer.println(ontRoot+getName(parent)+".has"+refName + " <R " + ontRoot+ getName(obj,"has"));\r
- writer.println(" --> " + ontRoot+getName(obj));\r
- if (useElementList(parent, indicator,element, reference, 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
- }\r
+ \r
}\r
\r
@Override\r
handleExtensionAttributes(complexType);\r
}\r
\r
- protected abstract void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, QName refType);\r
- protected abstract void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String refName, OpenAttrs ref);\r
+ protected enum RefType{Element,Reference,Type};\r
+ \r
+ protected abstract void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType);\r
protected abstract void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any);\r
protected abstract void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements);\r
\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
+ //String refName = eObj.getName();//localElement.getName();\r
QName refType = localElement.getType();\r
if (refType != null)\r
- handleIndicator(parent, indicator, element, false, refName, refType);\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, 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
+ //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