Declaration of simpleTypes as literal types.
Support for value elements with simple datatypes.
Fixed Base64 support.
Improved support for choice indicators.
Fixes for schemas without target namespace.
Generation of empty string literals for empty elements.
Change-Id: I8ae3b4fa47690c7c58df5a44eaf3191cc13f1fa2
-package org.simantics.interop.stubs;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.QueryControl;\r
-\r
-public class InteropResource {\r
- \r
- public final Resource HasDestination;\r
- public final Resource HasGeneratorID;\r
- public final Resource HasGeneratorID_Inverse;\r
- public final Resource HasImportData;\r
- public final Resource HasInputResource;\r
- public final Resource HasSource;\r
- public final Resource INodeType;\r
- public final Resource ImportDataOf;\r
- public final Resource ImportLibrary;\r
- public final Resource InteropBrowseContext;\r
- public final Resource InteropBrowseContext_InteropChildRule;\r
- public final Resource InteropBrowseContext_InteropNode;\r
- \r
- public static class URIs {\r
- public static final String HasDestination = "http://www.simantics.org/Interop-1.0/HasDestination";\r
- public static final String HasGeneratorID = "http://www.simantics.org/Interop-1.0/HasGeneratorID";\r
- public static final String HasGeneratorID_Inverse = "http://www.simantics.org/Interop-1.0/HasGeneratorID/Inverse";\r
- public static final String HasImportData = "http://www.simantics.org/Interop-1.0/HasImportData";\r
- public static final String HasInputResource = "http://www.simantics.org/Interop-1.0/HasInputResource";\r
- public static final String HasSource = "http://www.simantics.org/Interop-1.0/HasSource";\r
- public static final String INodeType = "http://www.simantics.org/Interop-1.0/INodeType";\r
- public static final String ImportDataOf = "http://www.simantics.org/Interop-1.0/ImportDataOf";\r
- public static final String ImportLibrary = "http://www.simantics.org/Interop-1.0/ImportLibrary";\r
- public static final String InteropBrowseContext = "http://www.simantics.org/Interop-1.0/InteropBrowseContext";\r
- public static final String InteropBrowseContext_InteropChildRule = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropChildRule";\r
- public static final String InteropBrowseContext_InteropNode = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropNode";\r
- }\r
- \r
- public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
- try {\r
- return graph.getResource(uri);\r
- } catch(DatabaseException e) {\r
- System.err.println(e.getMessage());\r
- return null;\r
- }\r
- }\r
- \r
- public InteropResource(ReadGraph graph) {\r
- HasDestination = getResourceOrNull(graph, URIs.HasDestination);\r
- HasGeneratorID = getResourceOrNull(graph, URIs.HasGeneratorID);\r
- HasGeneratorID_Inverse = getResourceOrNull(graph, URIs.HasGeneratorID_Inverse);\r
- HasImportData = getResourceOrNull(graph, URIs.HasImportData);\r
- HasInputResource = getResourceOrNull(graph, URIs.HasInputResource);\r
- HasSource = getResourceOrNull(graph, URIs.HasSource);\r
- INodeType = getResourceOrNull(graph, URIs.INodeType);\r
- ImportDataOf = getResourceOrNull(graph, URIs.ImportDataOf);\r
- ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary);\r
- InteropBrowseContext = getResourceOrNull(graph, URIs.InteropBrowseContext);\r
- InteropBrowseContext_InteropChildRule = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropChildRule);\r
- InteropBrowseContext_InteropNode = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropNode);\r
- }\r
- \r
- public static InteropResource getInstance(ReadGraph graph) {\r
- Session session = graph.getSession();\r
- InteropResource ret = session.peekService(InteropResource.class);\r
- if(ret == null) {\r
- QueryControl qc = graph.getService(QueryControl.class);\r
- ret = new InteropResource(qc.getIndependentGraph(graph));\r
- session.registerService(InteropResource.class, ret);\r
- }\r
- return ret;\r
- }\r
- \r
- public static InteropResource getInstance(RequestProcessor session) throws DatabaseException {\r
- InteropResource ret = session.peekService(InteropResource.class);\r
- if(ret == null) {\r
- ret = session.syncRequest(new Read<InteropResource>() {\r
- public InteropResource perform(ReadGraph graph) throws DatabaseException {\r
- QueryControl qc = graph.getService(QueryControl.class);\r
- return new InteropResource(qc.getIndependentGraph(graph));\r
- }\r
- });\r
- session.registerService(InteropResource.class, ret);\r
- }\r
- return ret;\r
- }\r
- \r
-}\r
-\r
+package org.simantics.interop.stubs;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.request.Read;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.QueryControl;
+
+public class InteropResource {
+
+ public final Resource HasDestination;
+ public final Resource HasGeneratorID;
+ public final Resource HasGeneratorID_Inverse;
+ public final Resource HasImportData;
+ public final Resource HasInputResource;
+ public final Resource HasSource;
+ public final Resource INodeType;
+ public final Resource ImportDataOf;
+ public final Resource ImportLibrary;
+ public final Resource InteropBrowseContext;
+ public final Resource InteropBrowseContext_InteropChildRule;
+ public final Resource InteropBrowseContext_InteropNode;
+
+ public static class URIs {
+ public static final String HasDestination = "http://www.simantics.org/Interop-1.0/HasDestination";
+ public static final String HasGeneratorID = "http://www.simantics.org/Interop-1.0/HasGeneratorID";
+ public static final String HasGeneratorID_Inverse = "http://www.simantics.org/Interop-1.0/HasGeneratorID/Inverse";
+ public static final String HasImportData = "http://www.simantics.org/Interop-1.0/HasImportData";
+ public static final String HasInputResource = "http://www.simantics.org/Interop-1.0/HasInputResource";
+ public static final String HasSource = "http://www.simantics.org/Interop-1.0/HasSource";
+ public static final String INodeType = "http://www.simantics.org/Interop-1.0/INodeType";
+ public static final String ImportDataOf = "http://www.simantics.org/Interop-1.0/ImportDataOf";
+ public static final String ImportLibrary = "http://www.simantics.org/Interop-1.0/ImportLibrary";
+ public static final String InteropBrowseContext = "http://www.simantics.org/Interop-1.0/InteropBrowseContext";
+ public static final String InteropBrowseContext_InteropChildRule = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropChildRule";
+ public static final String InteropBrowseContext_InteropNode = "http://www.simantics.org/Interop-1.0/InteropBrowseContext/InteropNode";
+ }
+
+ public static Resource getResourceOrNull(ReadGraph graph, String uri) {
+ try {
+ return graph.getResource(uri);
+ } catch(DatabaseException e) {
+ System.err.println(e.getMessage());
+ return null;
+ }
+ }
+
+ public InteropResource(ReadGraph graph) {
+ HasDestination = getResourceOrNull(graph, URIs.HasDestination);
+ HasGeneratorID = getResourceOrNull(graph, URIs.HasGeneratorID);
+ HasGeneratorID_Inverse = getResourceOrNull(graph, URIs.HasGeneratorID_Inverse);
+ HasImportData = getResourceOrNull(graph, URIs.HasImportData);
+ HasInputResource = getResourceOrNull(graph, URIs.HasInputResource);
+ HasSource = getResourceOrNull(graph, URIs.HasSource);
+ INodeType = getResourceOrNull(graph, URIs.INodeType);
+ ImportDataOf = getResourceOrNull(graph, URIs.ImportDataOf);
+ ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary);
+ InteropBrowseContext = getResourceOrNull(graph, URIs.InteropBrowseContext);
+ InteropBrowseContext_InteropChildRule = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropChildRule);
+ InteropBrowseContext_InteropNode = getResourceOrNull(graph, URIs.InteropBrowseContext_InteropNode);
+ }
+
+ public static InteropResource getInstance(ReadGraph graph) {
+ Session session = graph.getSession();
+ InteropResource ret = session.peekService(InteropResource.class);
+ if(ret == null) {
+ QueryControl qc = graph.getService(QueryControl.class);
+ ret = new InteropResource(qc.getIndependentGraph(graph));
+ session.registerService(InteropResource.class, ret);
+ }
+ return ret;
+ }
+
+ public static InteropResource getInstance(RequestProcessor session) throws DatabaseException {
+ InteropResource ret = session.peekService(InteropResource.class);
+ if(ret == null) {
+ ret = session.syncRequest(new Read<InteropResource>() {
+ public InteropResource perform(ReadGraph graph) throws DatabaseException {
+ QueryControl qc = graph.getService(QueryControl.class);
+ return new InteropResource(qc.getIndependentGraph(graph));
+ }
+ });
+ session.registerService(InteropResource.class, ret);
+ }
+ return ret;
+ }
+
+}
+
ArrayList<Resource> rs1 = new ArrayList<Resource>();\r
ArrayList<Resource> rs2 = new ArrayList<Resource>();\r
\r
+ @Override\r
+ public int compare(ReadGraph g, Resource o1, Resource o2, boolean local) throws DatabaseException {\r
+ if (local)\r
+ return new TypeComparator().compare(g, o1, o2);\r
+ else\r
+ return compare(g, o1, o2);\r
+ }\r
+ \r
@Override\r
public int compare(ReadGraph g, Resource o1, Resource o2) throws DatabaseException{\r
if (!compareType(g,o1, o2)) {\r
package org.simantics.xml.sax.base;\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 org.simantics.db.Resource;\r
import org.simantics.db.Statement;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
\r
-public class ValueElementWriter implements XMLElementWriter{\r
+public abstract class ValueElementWriter implements XMLElementWriter{\r
\r
String name;\r
Binding binding;\r
\r
}\r
\r
+ public abstract String decode(Object value);\r
+ \r
@Override\r
public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
throws XMLStreamException, DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
Object value = graph.getValue(instance.getResource(), binding);\r
- writer.writeCharacters(value.toString());\r
-// if (binding == Bindings.STRING) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.String);\r
-// graph.claimValue(element.getData(), string, binding);\r
-// } else if (binding == Bindings.INTEGER) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.Integer);\r
-// graph.claimValue(element.getData(), Integer.parseInt(string), binding);\r
-// } else if (binding == Bindings.FLOAT) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.Float);\r
-// graph.claimValue(element.getData(), Float.parseFloat(string), binding);\r
-// } else if (binding == Bindings.DOUBLE) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.Double);\r
-// graph.claimValue(element.getData(), Double.parseDouble(string), binding);\r
-// } else if (binding == Bindings.BOOLEAN) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.Boolean);\r
-// graph.claimValue(element.getData(), Boolean.parseBoolean(string), binding);\r
-// } else if (binding == Bindings.LONG) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.Long);\r
-// graph.claimValue(element.getData(), Long.parseLong(string), binding);\r
-// } else if (binding == Bindings.BYTE) {\r
-// graph.claim(element.getData(), l0.InstanceOf, l0.Byte);\r
-// graph.claimValue(element.getData(), Byte.parseByte(string), binding);\r
-// } else {\r
-// throw new DatabaseException("Unknown datatype " + binding);\r
-// }\r
+ writer.writeCharacters(decode(value));\r
}\r
\r
}\r
e = current.pop();\r
}\r
if (e != null) {\r
- if (charactersValue.length() > 0)\r
- handleCharacters(e, charactersValue.toString());\r
+ handleCharacters(e, charactersValue.toString());\r
handleElement(current,e);\r
}\r
if (current.isEmpty()) {\r
-package org.simantics.xml.sax.ontology;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.QueryControl;\r
-\r
-public class XMLResource {\r
- \r
- public final Resource AttributeGroup;\r
- public final Resource ComplexType;\r
- public final Resource Date;\r
- public final Resource DateTime;\r
- public final Resource Element;\r
- public final Resource ElementList;\r
- public final Resource Entity;\r
- public final Resource Time;\r
- public final Resource externalReferenceOf;\r
- public final Resource hasAttribute;\r
- public final Resource hasAttribute_Inverse;\r
- public final Resource hasComplexType;\r
- public final Resource hasComplexType_Inverse;\r
- public final Resource hasElement;\r
- public final Resource hasElementList;\r
- public final Resource hasElementList_Inverse;\r
- public final Resource hasElement_Inverse;\r
- public final Resource hasExternalReference;\r
- public final Resource hasID;\r
- public final Resource hasID_Inverse;\r
- public final Resource hasOriginalElementList;\r
- public final Resource hasOriginalElementList_Inverse;\r
- public final Resource hasReference;\r
- \r
- public static class URIs {\r
- public static final String AttributeGroup = "http://www.simantics.org/XML-1.0/AttributeGroup";\r
- public static final String ComplexType = "http://www.simantics.org/XML-1.0/ComplexType";\r
- public static final String Date = "http://www.simantics.org/XML-1.0/Date";\r
- public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime";\r
- public static final String Element = "http://www.simantics.org/XML-1.0/Element";\r
- public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList";\r
- public static final String Entity = "http://www.simantics.org/XML-1.0/Entity";\r
- public static final String Time = "http://www.simantics.org/XML-1.0/Time";\r
- public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf";\r
- public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute";\r
- public static final String hasAttribute_Inverse = "http://www.simantics.org/XML-1.0/hasAttribute/Inverse";\r
- public static final String hasComplexType = "http://www.simantics.org/XML-1.0/hasComplexType";\r
- public static final String hasComplexType_Inverse = "http://www.simantics.org/XML-1.0/hasComplexType/Inverse";\r
- public static final String hasElement = "http://www.simantics.org/XML-1.0/hasElement";\r
- public static final String hasElementList = "http://www.simantics.org/XML-1.0/hasElementList";\r
- public static final String hasElementList_Inverse = "http://www.simantics.org/XML-1.0/hasElementList/Inverse";\r
- public static final String hasElement_Inverse = "http://www.simantics.org/XML-1.0/hasElement/Inverse";\r
- public static final String hasExternalReference = "http://www.simantics.org/XML-1.0/hasExternalReference";\r
- public static final String hasID = "http://www.simantics.org/XML-1.0/hasID";\r
- public static final String hasID_Inverse = "http://www.simantics.org/XML-1.0/hasID/Inverse";\r
- public static final String hasOriginalElementList = "http://www.simantics.org/XML-1.0/hasOriginalElementList";\r
- public static final String hasOriginalElementList_Inverse = "http://www.simantics.org/XML-1.0/hasOriginalElementList/Inverse";\r
- public static final String hasReference = "http://www.simantics.org/XML-1.0/hasReference";\r
- }\r
- \r
- public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
- try {\r
- return graph.getResource(uri);\r
- } catch(DatabaseException e) {\r
- System.err.println(e.getMessage());\r
- return null;\r
- }\r
- }\r
- \r
- public XMLResource(ReadGraph graph) {\r
- AttributeGroup = getResourceOrNull(graph, URIs.AttributeGroup);\r
- ComplexType = getResourceOrNull(graph, URIs.ComplexType);\r
- Date = getResourceOrNull(graph, URIs.Date);\r
- DateTime = getResourceOrNull(graph, URIs.DateTime);\r
- Element = getResourceOrNull(graph, URIs.Element);\r
- ElementList = getResourceOrNull(graph, URIs.ElementList);\r
- Entity = getResourceOrNull(graph, URIs.Entity);\r
- Time = getResourceOrNull(graph, URIs.Time);\r
- externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf);\r
- hasAttribute = getResourceOrNull(graph, URIs.hasAttribute);\r
- hasAttribute_Inverse = getResourceOrNull(graph, URIs.hasAttribute_Inverse);\r
- hasComplexType = getResourceOrNull(graph, URIs.hasComplexType);\r
- hasComplexType_Inverse = getResourceOrNull(graph, URIs.hasComplexType_Inverse);\r
- hasElement = getResourceOrNull(graph, URIs.hasElement);\r
- hasElementList = getResourceOrNull(graph, URIs.hasElementList);\r
- hasElementList_Inverse = getResourceOrNull(graph, URIs.hasElementList_Inverse);\r
- hasElement_Inverse = getResourceOrNull(graph, URIs.hasElement_Inverse);\r
- hasExternalReference = getResourceOrNull(graph, URIs.hasExternalReference);\r
- hasID = getResourceOrNull(graph, URIs.hasID);\r
- hasID_Inverse = getResourceOrNull(graph, URIs.hasID_Inverse);\r
- hasOriginalElementList = getResourceOrNull(graph, URIs.hasOriginalElementList);\r
- hasOriginalElementList_Inverse = getResourceOrNull(graph, URIs.hasOriginalElementList_Inverse);\r
- hasReference = getResourceOrNull(graph, URIs.hasReference);\r
- }\r
- \r
- public static XMLResource getInstance(ReadGraph graph) {\r
- Session session = graph.getSession();\r
- XMLResource ret = session.peekService(XMLResource.class);\r
- if(ret == null) {\r
- QueryControl qc = graph.getService(QueryControl.class);\r
- ret = new XMLResource(qc.getIndependentGraph(graph));\r
- session.registerService(XMLResource.class, ret);\r
- }\r
- return ret;\r
- }\r
- \r
- public static XMLResource getInstance(RequestProcessor session) throws DatabaseException {\r
- XMLResource ret = session.peekService(XMLResource.class);\r
- if(ret == null) {\r
- ret = session.syncRequest(new Read<XMLResource>() {\r
- public XMLResource perform(ReadGraph graph) throws DatabaseException {\r
- QueryControl qc = graph.getService(QueryControl.class);\r
- return new XMLResource(qc.getIndependentGraph(graph));\r
- }\r
- });\r
- session.registerService(XMLResource.class, ret);\r
- }\r
- return ret;\r
- }\r
- \r
-}\r
-\r
+package org.simantics.xml.sax.ontology;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.request.Read;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.QueryControl;
+
+public class XMLResource {
+
+ public final Resource AttributeGroup;
+ public final Resource ComplexType;
+ public final Resource Date;
+ public final Resource DateTime;
+ public final Resource Element;
+ public final Resource ElementList;
+ public final Resource Entity;
+ public final Resource Time;
+ public final Resource externalReferenceOf;
+ public final Resource hasAttribute;
+ public final Resource hasAttribute_Inverse;
+ public final Resource hasComplexType;
+ public final Resource hasComplexType_Inverse;
+ public final Resource hasElement;
+ public final Resource hasElementList;
+ public final Resource hasElementList_Inverse;
+ public final Resource hasElement_Inverse;
+ public final Resource hasExternalReference;
+ public final Resource hasID;
+ public final Resource hasID_Inverse;
+ public final Resource hasOriginalElementList;
+ public final Resource hasOriginalElementList_Inverse;
+ public final Resource hasReference;
+
+ public static class URIs {
+ public static final String AttributeGroup = "http://www.simantics.org/XML-1.0/AttributeGroup";
+ public static final String ComplexType = "http://www.simantics.org/XML-1.0/ComplexType";
+ public static final String Date = "http://www.simantics.org/XML-1.0/Date";
+ public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime";
+ public static final String Element = "http://www.simantics.org/XML-1.0/Element";
+ public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList";
+ public static final String Entity = "http://www.simantics.org/XML-1.0/Entity";
+ public static final String Time = "http://www.simantics.org/XML-1.0/Time";
+ public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf";
+ public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute";
+ public static final String hasAttribute_Inverse = "http://www.simantics.org/XML-1.0/hasAttribute/Inverse";
+ public static final String hasComplexType = "http://www.simantics.org/XML-1.0/hasComplexType";
+ public static final String hasComplexType_Inverse = "http://www.simantics.org/XML-1.0/hasComplexType/Inverse";
+ public static final String hasElement = "http://www.simantics.org/XML-1.0/hasElement";
+ public static final String hasElementList = "http://www.simantics.org/XML-1.0/hasElementList";
+ public static final String hasElementList_Inverse = "http://www.simantics.org/XML-1.0/hasElementList/Inverse";
+ public static final String hasElement_Inverse = "http://www.simantics.org/XML-1.0/hasElement/Inverse";
+ public static final String hasExternalReference = "http://www.simantics.org/XML-1.0/hasExternalReference";
+ public static final String hasID = "http://www.simantics.org/XML-1.0/hasID";
+ public static final String hasID_Inverse = "http://www.simantics.org/XML-1.0/hasID/Inverse";
+ public static final String hasOriginalElementList = "http://www.simantics.org/XML-1.0/hasOriginalElementList";
+ public static final String hasOriginalElementList_Inverse = "http://www.simantics.org/XML-1.0/hasOriginalElementList/Inverse";
+ public static final String hasReference = "http://www.simantics.org/XML-1.0/hasReference";
+ }
+
+ public static Resource getResourceOrNull(ReadGraph graph, String uri) {
+ try {
+ return graph.getResource(uri);
+ } catch(DatabaseException e) {
+ System.err.println(e.getMessage());
+ return null;
+ }
+ }
+
+ public XMLResource(ReadGraph graph) {
+ AttributeGroup = getResourceOrNull(graph, URIs.AttributeGroup);
+ ComplexType = getResourceOrNull(graph, URIs.ComplexType);
+ Date = getResourceOrNull(graph, URIs.Date);
+ DateTime = getResourceOrNull(graph, URIs.DateTime);
+ Element = getResourceOrNull(graph, URIs.Element);
+ ElementList = getResourceOrNull(graph, URIs.ElementList);
+ Entity = getResourceOrNull(graph, URIs.Entity);
+ Time = getResourceOrNull(graph, URIs.Time);
+ externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf);
+ hasAttribute = getResourceOrNull(graph, URIs.hasAttribute);
+ hasAttribute_Inverse = getResourceOrNull(graph, URIs.hasAttribute_Inverse);
+ hasComplexType = getResourceOrNull(graph, URIs.hasComplexType);
+ hasComplexType_Inverse = getResourceOrNull(graph, URIs.hasComplexType_Inverse);
+ hasElement = getResourceOrNull(graph, URIs.hasElement);
+ hasElementList = getResourceOrNull(graph, URIs.hasElementList);
+ hasElementList_Inverse = getResourceOrNull(graph, URIs.hasElementList_Inverse);
+ hasElement_Inverse = getResourceOrNull(graph, URIs.hasElement_Inverse);
+ hasExternalReference = getResourceOrNull(graph, URIs.hasExternalReference);
+ hasID = getResourceOrNull(graph, URIs.hasID);
+ hasID_Inverse = getResourceOrNull(graph, URIs.hasID_Inverse);
+ hasOriginalElementList = getResourceOrNull(graph, URIs.hasOriginalElementList);
+ hasOriginalElementList_Inverse = getResourceOrNull(graph, URIs.hasOriginalElementList_Inverse);
+ hasReference = getResourceOrNull(graph, URIs.hasReference);
+ }
+
+ public static XMLResource getInstance(ReadGraph graph) {
+ Session session = graph.getSession();
+ XMLResource ret = session.peekService(XMLResource.class);
+ if(ret == null) {
+ QueryControl qc = graph.getService(QueryControl.class);
+ ret = new XMLResource(qc.getIndependentGraph(graph));
+ session.registerService(XMLResource.class, ret);
+ }
+ return ret;
+ }
+
+ public static XMLResource getInstance(RequestProcessor session) throws DatabaseException {
+ XMLResource ret = session.peekService(XMLResource.class);
+ if(ret == null) {
+ ret = session.syncRequest(new Read<XMLResource>() {
+ public XMLResource perform(ReadGraph graph) throws DatabaseException {
+ QueryControl qc = graph.getService(QueryControl.class);
+ return new XMLResource(qc.getIndependentGraph(graph));
+ }
+ });
+ session.registerService(XMLResource.class, ret);
+ }
+ return ret;
+ }
+
+}
+
}\r
\r
@Override\r
- protected void createPrimitiveIndicator(SchemaObject parent, String refName, String binding) {\r
+ protected void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName) {\r
FileWriter fw = getWriter(parent);\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
+ String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());\r
+ String typeURI = ontologyClassName != null ? ontologyClassName + ".URIs." + getName(base.getSimpleType(typeName)) : "null";\r
+ \r
+ fw.writer.println(" addRelationWriter("+ ontShort +getName(parent) + "_has"+refName+", "+getName(parent) +"_" +refName+".class);");\r
\r
fw.delayedWriter2.println(" public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementWriter {");\r
fw.delayedWriter2.println(" public "+ getName(parent) +"_" +refName +"(){");\r
- //fw.delayedWriter2.println(" super(\""+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(" super(\""+refName+"\", " + typeURI + ", " + typeEntry.binding+");");\r
+ fw.delayedWriter2.println(" }\n");\r
+ fw.delayedWriter2.println(" @Override");\r
+ fw.delayedWriter2.println(" public String decode(Object value) {");\r
+ fw.delayedWriter2.println(" return " + typeEntry.stringPrefix + "(" + typeEntry.javaType + ")value" + typeEntry.stringPostfix + ";");\r
+ fw.delayedWriter2.println(" }");\r
fw.delayedWriter2.println(" }");\r
}\r
\r
fw.writer.println(" @Override");
fw.writer.println(" public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");
if (inheritance.type == InheritanceType.ComplexType) {
- fw.writer.println(" super.configure(graph,parents,element);");
+ fw.writer.println(" super.configure(graph,parents,element);");
}
- fw.writer.println(" "+getOntologyImport());
-
+ fw.writer.println(" "+getOntologyImport());
+ fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);");
this.base.handleComplexTypeAttributes(complexTypeObj);
this.base.handleExtensionAttributes(complexTypeObj);
}
@Override
- protected void createPrimitiveIndicator(SchemaObject parent, String refName, String binding) {
+ protected void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName) {
FileWriter fw = getWriter(parent);
- fw.writer.println(" addParser(\""+ refName +"\", "+getName(parent) +"_" +refName+".class);");
+ String className = getName(parent) +"_" +refName;
+ fw.writer.println(" addParser(\"" + refName + "\", " + className + ".class);");
+ fw.delayedWriter2.println(" public static class " + className + " extends org.simantics.xml.sax.base.ValueElementParser {");
+ fw.delayedWriter2.println(" public "+ className +"(){");
+ fw.delayedWriter2.println(" super(\""+refName+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+refName+", "+typeEntry.binding+");");
+ fw.delayedWriter2.println(" }\n");
+ fw.delayedWriter2.println(" @Override");
+ fw.delayedWriter2.println(" public void configure(WriteGraph graph, ParserElement element, String value) throws DatabaseException {");
+ fw.delayedWriter2.println(" Layer0 L0 = Layer0.getInstance(graph);");
+
+ SchemaObject simpleType = base.getSimpleType(typeName);
+ String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());
+ if (ontologyClassName != null && simpleType != null)
+ fw.delayedWriter2.println(" graph.claim(element.getData(), L0.InstanceOf, " + ontologyClassName + ".getInstance(graph)." + getName(simpleType, "") + ");");
+ else {
+ if (typeEntry.l0Type.startsWith("XML"))
+ fw.delayedWriter2.println(" XMLResource XML = XMLResource.getInstance(graph);");
+ fw.delayedWriter2.println(" graph.claim(element.getData(), L0.InstanceOf, " + typeEntry.l0Type + ");");
+ }
- fw.delayedWriter2.println(" public static class " + getName(parent) +"_" +refName+" extends org.simantics.xml.sax.base.ValueElementParser {");
- fw.delayedWriter2.println(" public "+ getName(parent) +"_" +refName +"(){");
- fw.delayedWriter2.println(" super(\""+refName+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+refName+", "+binding+");");
- fw.delayedWriter2.println(" }");
+ fw.delayedWriter2.println(" graph.claimValue(element.getData(), " +getValueGetter(typeEntry) + ", " + typeEntry.binding + ");");
+ fw.delayedWriter2.println(" }");
fw.delayedWriter2.println(" }");
}
TypeEntry binding = this.base.getTypeEntry(primitiveType);
if (binding != null) {
- writeAttribute(fw, attrName, relationName, binding, isReference);
+ writeAttribute(fw, attrName, relationName, binding, isReference, primitiveType);
return;
} else {
if (simpleType == null) {
if (simpleType != null) {
org.w3._2001.xmlschema.List list = simpleType.getList();
if (list != null) {
- TypeEntry binding = this.base.getTypeEntry(new QName(SchemaConversionBase.SCHEMA_NS, "string"));
- writeAttribute(fw, attrName, relationName, binding, isReference);
+ QName typeName = new QName(SchemaConversionBase.SCHEMA_NS, "string");
+ TypeEntry binding = this.base.getTypeEntry(typeName);
+ writeAttribute(fw, attrName, relationName, binding, isReference, typeName);
} else {
// Restriction restriction = simpleType.getRestriction();
// if (restriction == null)
//String binding = getBindingFromPrimitiveType(base);
TypeEntry binding = this.base.getTypeEntry(base);
- writeAttribute(fw, attrName, relationName, binding, isReference);
+ writeAttribute(fw, attrName, relationName, binding, isReference, base);
}
} else {
// TODO : using default String attribute should be configured with rules.
//throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());
fw.writer.println(" //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");
//writeAttribute(fw, attrName, relationName, "STRING", isReference);
- writeAttribute(fw, attrName, relationName, this.base.getTypeEntry("string"), isReference);
+ writeAttribute(fw, attrName, relationName, this.base.getTypeEntry("string"), isReference, new QName(SchemaConversionBase.SCHEMA_NS, "string"));
}
}
- private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {
+ private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference, QName typeName) {
+ String ontologyClassName = converter.getOntologyClassName(typeName.getNamespaceURI());
+ String ontologyType = ontologyClassName != null ? ontologyClassName + ".getInstance(graph)." + getName(base.getSimpleType(typeName)) : binding.l0Type;
fw.writer.println(" {");
fw.writer.println(" Attribute a = element.getAttribute(\"" +attrName+"\");");
fw.writer.println(" if (a != null) {");
- fw.writer.println(" graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");
+ fw.writer.println(" graph.claimLiteral(element.getData(), " + relationName + ", " + ontologyType + ", " + getValueGetterMethod(binding,"a") + ", " + binding.binding + ");");
if (isReference)
fw.writer.println(" idProviderValue = a.getValue();");
fw.writer.println(" }");
fw.writer.println(" @Override");
fw.writer.println(" public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");
if (inheritance.type == InheritanceType.ComplexType) {
- fw.writer.println(" super.configure(graph,parents,element);");
+ fw.writer.println(" super.configure(graph,parents,element);");
}
- fw.writer.println(" "+getOntologyImport());
+ fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);");
+ fw.writer.println(" XMLResource XML = XMLResource.getInstance(graph);");
+ fw.writer.println(" "+getOntologyImport());
LocalComplexType complexType = element.getComplexType();
LocalSimpleType simpleType = element.getSimpleType();
\r
import javax.xml.namespace.QName;\r
\r
+import org.simantics.xml.sax.SchemaConversionBase.Inheritance;\r
import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
import org.simantics.xml.sax.SchemaConversionBase.TypeEntry;\r
import org.w3._2001.xmlschema.AttributeGroupRef;\r
return binding.getValueGetter();\r
}\r
\r
+ @Override\r
+ public String getSimpleTypePrefix() {\r
+ return "SimpleTypes_";\r
+ } \r
+ \r
@Override\r
public String getComplexTypePrefix() {\r
return "ComplexTypes_";\r
}\r
\r
@Override\r
- public void handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name) {\r
-\r
- for (SchemaElement e : elements) {\r
- Element localElement = e.getElement();\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, name, RefType.Type);\r
- } else if (localElement.getRef() != null) {\r
- //QName refType = localElement.getRef();\r
- //handleIndicator(parent, indicator, e, true, name, refType);\r
- handleIndicator(parent, indicator, e, name, RefType.Reference);\r
- }\r
- }\r
+ public String handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name) {\r
+ String baseRelationName = getName(parent) + ".has" + name;\r
+ \r
+// for (SchemaElement e : elements) {\r
+// Element localElement = e.getElement();\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, name, RefType.Type, baseRelationName);\r
+// } else if (localElement.getRef() != null) {\r
+// //QName refType = localElement.getRef();\r
+// //handleIndicator(parent, indicator, e, true, name, refType);\r
+// handleIndicator(parent, indicator, e, name, RefType.Reference, baseRelationName);\r
+// }\r
+// }\r
\r
+ return baseRelationName;\r
}\r
\r
protected String getOntologyImport() {\r
case ATTRIBUTE_GROUP:\r
return getAttributeGroupPrefix()+obj.getName();\r
case SIMPLE_TYPE:\r
- return obj.getName();\r
+ return getSimpleTypePrefix()+obj.getName();\r
}\r
} else {\r
SchemaObject o = obj;\r
case ATTRIBUTE_GROUP:\r
return getAttributeGroupPrefix()+name;\r
case SIMPLE_TYPE:\r
- return name;\r
+ return getSimpleTypePrefix()+name;\r
}\r
}\r
throw new RuntimeException();\r
case ATTRIBUTE_GROUP:\r
return getAttributeGroupPrefix()+rel+obj.getName();\r
case SIMPLE_TYPE:\r
- return rel+obj.getName();\r
+ return getSimpleTypePrefix()+rel+obj.getName();\r
}\r
} else {\r
SchemaObject o = obj;\r
case ATTRIBUTE_GROUP:\r
return getAttributeGroupPrefix()+rel+name;\r
case SIMPLE_TYPE:\r
- return rel+name;\r
+ return getSimpleTypePrefix()+rel+name;\r
}\r
}\r
throw new RuntimeException();\r
\r
\r
protected abstract void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName, String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList);\r
- protected abstract void createPrimitiveIndicator(SchemaObject parent, String refName, String binding);\r
+ protected abstract void createPrimitiveIndicator(SchemaObject parent, String refName, TypeEntry typeEntry, QName typeName);\r
protected abstract void createElementIndicator(SchemaObject parent, boolean useElementList, String refName, String className, boolean useOriginalList);\r
\r
@Override\r
- public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType referenceType) {\r
+ public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType referenceType, String baseRelationName) {\r
String objectName;\r
if (referenceType != RefType.Element) {\r
- QName refType;\r
+ QName refTypeName;\r
+ SchemaObject refObject = null;\r
if (referenceType == RefType.Type) {\r
- refType = element.getElement().getType();\r
+ refTypeName = element.getElement().getType();\r
if (refName == null)\r
refName = element.getElement().getName();\r
objectName = element.getElement().getName();\r
+ refObject = this.base.getComplexType(refTypeName);\r
+ if (refObject == null) this.base.getSimpleType(refTypeName);\r
} else {\r
- refType = element.getElement().getRef();\r
+ refTypeName = element.getElement().getRef();\r
if (refName == null)\r
- refName = refType.getLocalPart();\r
- objectName = refType.getLocalPart();\r
+ refName = refTypeName.getLocalPart();\r
+ objectName = refTypeName.getLocalPart();\r
+ refObject = this.base.getElement(refTypeName);\r
}\r
\r
- String binding = this.base.getBindingFromPrimitiveType(refType);\r
- if (binding == null) {\r
- SchemaObject refElement = this.base.getElement(refType);\r
- SchemaObject refComplexType = this.base.getComplexType(refType);\r
- \r
+ TypeEntry typeEntry = this.base.getTypeEntry(refTypeName);\r
+ if (typeEntry == null) {\r
// prefer element reference over complex type reference\r
String primaryClassName = null;\r
String secondaryClassName = null;\r
- if (refElement != null)\r
- primaryClassName = getName(refElement);\r
- else\r
- primaryClassName = getName(refComplexType);\r
+ if (refObject != null)\r
+ primaryClassName = getName(refObject);\r
+ else if (this.base.getSimpleType(refTypeName) != null) {\r
+ Inheritance inheritance = new Inheritance("");\r
+ this.base.getAtomicTypeInheritance(refTypeName, inheritance);\r
+ if (inheritance.atomicType != null) {\r
+ createPrimitiveIndicator(parent, refName, inheritance.atomicType, refTypeName);\r
+ return;\r
+ }\r
+ else {\r
+ throw new RuntimeException("No supported atomic type found for simple type " + refTypeName.toString());\r
+ }\r
+ }\r
+ else {\r
+ throw new RuntimeException("Type that is neither complex nor simple??");\r
+ }\r
\r
- if (refComplexType != null) {\r
- secondaryClassName = getName(refComplexType);\r
- } else {\r
- secondaryClassName = getName(refElement);\r
+ if (refObject != null) {\r
+ secondaryClassName = getName(refObject);\r
}\r
- boolean useElementList = this.base.useElementList(parent, indicator,element, referenceType == RefType.Reference, refName, refType);\r
- boolean useOriginalList = this.base.useOriginalList(parent, indicator,element, referenceType == RefType.Reference, refName, refType);\r
+ boolean useElementList = this.base.useElementList(parent, indicator,element, referenceType == RefType.Reference, refName, refTypeName);\r
+ boolean useOriginalList = this.base.useOriginalList(parent, indicator,element, referenceType == RefType.Reference, refName, refTypeName);\r
createReferenceIndicator(parent, referenceType, refName, objectName, primaryClassName, secondaryClassName, useElementList, useOriginalList);\r
} else {\r
- createPrimitiveIndicator(parent, refName, binding);\r
+ createPrimitiveIndicator(parent, refName, typeEntry, refTypeName);\r
}\r
} else {\r
Element attrs= element.getElement();\r
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.simantics.utils.datastructures.BijectionMap;
import org.simantics.xml.sax.SchemaConversionBase.Inheritance;
-import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;
import org.simantics.xml.sax.SchemaConversionBase.RefType;
import org.simantics.xml.sax.SchemaObject.ObjectType;
import org.simantics.xml.sax.configuration.AttributeComposition;
import org.w3._2001.xmlschema.LocalSimpleType;
import org.w3._2001.xmlschema.NamedAttributeGroup;
import org.w3._2001.xmlschema.NamedGroup;
-import org.w3._2001.xmlschema.Restriction;
import org.w3._2001.xmlschema.Schema;
import org.w3._2001.xmlschema.SimpleType;
writer.println();
ontRoot += ".";
+ writer.println(ontRoot+"SimpleTypes : L0.Library");
writer.println(ontRoot+"ComplexTypes : L0.Library");
writer.println(ontRoot+"AttributeGroups : L0.Library");
writer.println();
base.handle(this);
}
- protected String getType(QName qtype) {
+ protected String getType(QName qtype, String rel) {
String ontType = base.getL0TypeFromPrimitiveType(qtype);
if (ontType != null)
return ontType;
- else if (base.isComplexTypeRef(qtype.getLocalPart()))
- return ontRoot+getComplexTypePrefix()+qtype.getLocalPart();
- else if (base.isSimpleTypeRef(qtype.getLocalPart()))
- return ontRoot+qtype.getLocalPart();
- else if (base.isElementRef(qtype.getLocalPart()))
- return ontRoot+qtype.getLocalPart();
- else if (qtype.getPrefix() != null && qtype.getPrefix().length() > 0) {
- return ontRoot+qtype.getPrefix()+qtype.getLocalPart();
+ else {
+ if (base.isComplexTypeRef(qtype.getLocalPart()))
+ return getName(base.getComplexType(qtype), rel);
+ else if (base.isSimpleTypeRef(qtype.getLocalPart()))
+ return getName(base.getSimpleType(qtype), rel);
+ else if (base.isElementRef(qtype.getLocalPart()))
+ return getName(base.getElement(qtype), rel);
}
throw new RuntimeException("Reference to unknown type " + qtype.getLocalPart());
}
+ public String getSimpleTypePrefix() {
+ return "SimpleTypes.";
+ }
+
public String getComplexTypePrefix() {
return "ComplexTypes.";
}
return "AttributeGroups.";
}
- public void handleChoice(SchemaObject parent, SchemaElement indicator, java.util.List<SchemaElement> elements, String name) {
+ public String handleChoice(SchemaObject parent, SchemaElement indicator, java.util.List<SchemaElement> elements, String name) {
boolean single = true;
for (SchemaElement e : elements) {
if (e.getRestriction().many()) {
}
String relationName = getName(parent)+".has"+name;
writer.print(relationName);
-
- List<String> types = new ArrayList<String>();
- for (SchemaElement e : elements) {
- Element localElement = e.getElement();
- QName refType = null;
- String type = null;
-
- if (localElement.getName() != null) {
- refType = localElement.getType();
- type = base.getL0TypeFromPrimitiveType(refType);
- } else if (localElement.getRef() != null) {
- refType = localElement.getRef();
- type = base.getL0TypeFromPrimitiveType(refType);
- }
- if (type == null) {
- SchemaObject obj = base.getWithName(refType);
- types.add(getName(obj,"has"));
- }
- }
- if (types.size() > 0) {
- for (String type : types) {
- writer.print(" <R " + type);
- }
- } else {
- writer.print(" <R XML.hasElement");
- }
-
+ writer.print(" <R XML.hasElement");
writer.println();
- for (SchemaElement e : elements) {
- Element localElement = e.getElement();
- QName refType = null;
- String type = null;
- if (localElement.getName() != null) {
- refType = localElement.getType();
- type = getType(refType);
- } else if (localElement.getRef() != null) {
- refType = localElement.getRef();
- type = getType(refType);
- }
- if (type != null) {
- writer.println(" --> " + type);
- }
- }
if (!single) {
- writer.println(ontRoot+name+ "List <T XML.ElementList");
- if (types.size() == 0) {
- writer.println(relationName+ "List <R XML.hasElementList : L0.FunctionalRelation");
- } else {
- writer.print(relationName+ "List");
- for (String type : types) {
- writer.print(" <R " + type+"List");
- }
- writer.println(" : L0.FunctionalRelation");
- }
- writer.println(" --> " + ontRoot+name+"List");
+ String elementListType = getName(parent) + "." + name + "List";
+ writer.println(elementListType + " <T XML.ElementList");
+ writer.println(relationName + "List <R XML.hasElementList : L0.FunctionalRelation");
+ writer.println(" --> " + elementListType);
}
+
+ return relationName;
};
@Override
- public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {
- if (refType != refType.Element) {
+ public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName) {
+ if (refType != RefType.Element) {
QName referenceType = null;
if (refType == RefType.Type) {
referenceType = element.getElement().getType();
SchemaObject obj = null;
if (type == null) {
obj = base.getWithName(referenceType);
-
- writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
- writer.println(" --> " + getName(obj));
+ writer.print(getName(parent)+".has"+refName + " <R XML.hasElement <R " + getName(obj,"has"));
+ if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+ writer.println();
} else {
- writer.println(getName(parent)+".has"+refName + " <R XML.hasElement");
- writer.println(" --> " + getType(referenceType));
+ writer.print(getName(parent)+".has"+refName + " <R XML.hasElement");
+ if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+ writer.println();
+ writer.println(" --> " + getType(referenceType, ""));
}
if (base.useElementList(parent, indicator,element, refType == RefType.Reference, refName, referenceType)) {
if (refName == null)
refName = obj.getName();
- writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
+ writer.print(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
+ if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+ writer.println();
writer.println(" --> " + getName(obj));
if (base.useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {
writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");
} else if (ontType != null) {
writer.println(" --> " + ontType);
} else if (primitiveType != null) {
- writer.println(" <R "+ontRoot+"has"+primitiveType.getLocalPart());
+ writer.println(" <R " + getType(primitiveType, "has"));
}
}
org.w3._2001.xmlschema.List list = simpleType.getList();
if (list != null) {
// TODO : process restriction in lists
- String relationName = ontRoot+"has"+name;
- if (parent != null)
- relationName = getName(parent)+".has"+name;
+ String relationName = getName(simpleTypeObj, "has");
writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");
String ontType = base.getL0Type(new QName(SchemaConversionBase.SCHEMA_NS, "string"));
writer.println(" --> " + ontType);
} else {
- String relationName = ontRoot+"has"+name;
- if (parent != null)
- relationName = getName(parent)+".has"+name;
+ QName base = this.base.getSimpleTypeBase(simpleType);
+ writer.println(getName(simpleTypeObj) + " <T " + getType(base, ""));
- writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");
+ String relationName = getName(simpleTypeObj, "has");
- QName base = this.base.getSimpleTypeBase(simpleType);
- Inheritance inheritance = new Inheritance("");
- this.base.getAtomicTypeInheritance(base, inheritance);
- if (inheritance.atomicType == null)
- throw new RuntimeException("Could not locate atomic type for SimpleType " + simpleType.getName());
- writer.println(" --> " + inheritance.atomicType.l0Type);
+ writer.println(relationName+ " : L0.FunctionalRelation");
+ writer.println(" --> " + getName(simpleTypeObj));
// Restriction restriction = simpleType.getRestriction();
// if (restriction != null) {
// if (topLevelComplexType.getName().equals("Reference"))
// System.out.println();
- String relationName = getName(topLevelComplexType,"has");//ontRoot+"has"+name;
-
- writer.println(relationName+ " <R XML.hasComplexType");
- writer.println(relationName+ "List <R XML.hasElementList");
- //writer.println(" --> " + ontRoot+getComplexTypePrefix()+name);
- writer.println(" --> " + name);
- writer.println();
// String baseType = "XML.ComplexType";
//
// QName base = getComplexTypeBase(topLevelComplexType.getComplexType());
// writer.println(name+ " <T "+baseType);
- if(inheritance.type == InheritanceType.AtomicType) {
- writer.println(name+ " <T "+inheritance.baseClass + " <T "+inheritance.atomicType.l0Type);
- } else {
- writer.println(name+ " <T "+inheritance.baseClass);
- }
+ // Type definition
+ writer.println(name+ " <T " + inheritance.baseClass);
+ writer.println(name + "List <T XML.ElementList");
+
+ // Access relations
+ String relationName = getName(topLevelComplexType,"has");
+ writer.println(relationName+ " <R XML.hasComplexType");
+ writer.println(" --> " + name);
+ writer.println(relationName+ "List <R XML.hasElementList");
+ writer.println(" --> " + name + "List");
+ writer.println();
+
+ // Attributes
// if (!baseType.equals(inheritance.baseClass))
// System.out.println();
//super.handleComplexType(topLevelComplexType);
String type = "XML.Element";
Set<String> types = new LinkedHashSet<String>();
if (element.getType() != null) {
- types.add(getType(element.getType()));
+ types.add(getType(element.getType(), ""));
}
QName base = this.base.getElementBase(element);
if (base != null) {
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+obj.getName();
case SIMPLE_TYPE:
- return ontRoot+obj.getName();
+ return ontRoot+getSimpleTypePrefix()+obj.getName();
}
} else {
SchemaObject o = obj;
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+name;
case SIMPLE_TYPE:
- return ontRoot+name;
+ return ontRoot+getSimpleTypePrefix()+name;
}
}
throw new RuntimeException();
}
+ public String getName(SchemaObject parent, SchemaElement e, String rel) {
+ QName ref = e.getElement().getRef();
+ if (ref != null) {
+ return converter.getShortName(ref.getNamespaceURI()) + rel + ref.getLocalPart();
+ }
+ else {
+ return getName(parent, "") + "." + rel + e.getElement().getName();
+ }
+ }
+
public String getName(SchemaObject obj, String rel) {
if (obj.getParent() == null) {
switch (obj.getType()) {
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+rel+obj.getName();
case SIMPLE_TYPE:
- return ontRoot+rel+obj.getName();
+ return ontRoot+getSimpleTypePrefix()+rel+obj.getName();
}
} else {
SchemaObject o = obj;
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+rel+name;
case SIMPLE_TYPE:
- return ontRoot+rel+name;
+ return ontRoot+getSimpleTypePrefix()+rel+name;
}
}
throw new RuntimeException();
schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));
schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));
schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));
- schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray", "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)","new java.lang.String(",", org.simantics.databoard.util.binary.UTF8.CHARSET)"));
+ schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray", "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","java.util.Base64.getDecoder().decode(",")","java.util.Base64.getEncoder().encodeToString(",")"));
l0Types.put("doubleArray", new TypeEntry("L0.DoubleArray", "Bindings.DOUBLE_ARRAY", "double[]", null,null,null,"java.lang.Double.toString(",")"));
l0Types.put("stringArray", new TypeEntry("L0.StringArray", "Bindings.STRING_ARRAY", "string[]", null,null,null,"",""));
protected enum RefType{Element,Reference,Type};
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {
- component.handleIndicator(parent, indicator, element, refName, refType);
+ protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName) {
+ component.handleIndicator(parent, indicator, element, refName, refType, baseRelationName);
}
protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) {
component.handleIndicator(parent, indicator, any);
}
protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {
//component.handle(parent, indicator, elements);
- if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {
+ // Generate combined relation
+ String baseRelationName = null;
+ if (indicator.getType() == SchemaElement.ElementType.CHOICE) {
+ String name = getChoiceName(elements);
+ if (name != null)
+ baseRelationName = component.handleChoice(parent, indicator, elements, name);
+ }
+
+ if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || indicator.getType() == SchemaElement.ElementType.CHOICE) {
for (SchemaElement e : elements) {
- handle(parent, indicator, e);
+ handle(parent, indicator, e, baseRelationName);
}
- } else if (indicator.getType() == SchemaElement.ElementType.CHOICE) {
- String name = getChoiceName(elements);
- component.handleChoice(parent, indicator, elements, name);
}
}
}
- protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {
+ protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element, String baseRelationName) {
Element localElement = element.getElement();
if (localElement.getName() != null) {
- SchemaObject eObj = elements.get(localElement);
+ SchemaObject eObj = elements.get(localElement);
QName refType = localElement.getType();
if (refType != null)
- handleIndicator(parent, indicator, element, null, RefType.Type);
+ handleIndicator(parent, indicator, element, null, RefType.Type, baseRelationName);
else {
handleElement(eObj);
- handleIndicator(parent, indicator, element, null, RefType.Element);
- }
+ handleIndicator(parent, indicator, element, null, RefType.Element, baseRelationName);
+ }
} else if (localElement.getRef() != null) {
- handleIndicator(parent, indicator,element, null, RefType.Reference);
+ handleIndicator(parent, indicator,element, null, RefType.Reference, baseRelationName);
}
}
protected String getChoiceName(List<SchemaElement> elements) {
if (elements.size() == 1) {
- return getElementName(elements.get(0).getElement());
+ return null;
}
- List<String> names = new ArrayList<String>();
- for (SchemaElement e : elements) {
- String name = getElementName(e.getElement());
- if (name != null)
- names.add(name);
+ else if (elements.size() > 0 && elements.size() <= 3) {
+ List<String> names = new ArrayList<String>();
+ for (SchemaElement e : elements) {
+ String name = getElementName(e.getElement());
+ if (name != null)
+ names.add(name);
+ }
+ String name = "";
+ for (int i = 0; i < names.size(); i++) {
+ if (i == 0)
+ name = names.get(i);
+ else
+ name += "Or"+names.get(i);
+ }
+ return name;
}
- String name = "";
- for (int i = 0; i < names.size(); i++) {
- if (i == 0)
- name = names.get(i);
- else
- name += "Or"+names.get(i);
+ else {
+ return "SubElement";
}
- return name;
}
protected void handle(SchemaObject parent, Attribute attribute) {
\r
void handleAttributes(SchemaObject simpleTypeObj);\r
void handleAttributeComposition(SchemaObject obj, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes);\r
- void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType);\r
+ void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName);\r
void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any);\r
//void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements);\r
- void handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name);\r
+ String handleChoice(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements, String name);\r
void handle(SchemaObject parent, Attribute attribute) ;\r
void handle(SchemaObject parent, AttributeGroup attribute) ;\r
void handle(SchemaObject parent, NamedGroup attribute);\r
void handleSimpleType(SchemaObject parent, SchemaObject simpleType);\r
void handleComplexType(SchemaObject complexTypeObj);\r
void handleElement(SchemaObject complexTypeObj);\r
+ String getSimpleTypePrefix();\r
String getComplexTypePrefix(); \r
String getAttributeGroupPrefix();\r
String getName(SchemaObject obj);\r
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
import org.simantics.utils.datastructures.MapList;
import org.simantics.xml.sax.configuration.Configuration;
header[3] = "Date " + new Date().toString();
schemaNs = schema.getTargetNamespace();
+
ontologyUri = schemaNs;
if (ontologyUri == null) {
ontologyUri = getSchemaFile().getName();
int index = ontologyUri.lastIndexOf(".");
if (index > 0)
ontologyUri = ontologyUri.substring(0, index);
+ schemaNs = "";
}
ontologyUri = ontologyUri.replaceAll(" ", "_");
String parts[] = ontologyUri.split("/");
}
public boolean isPrimary() {
- return getRoot().schemaNSMap.getValues(schemaNs).indexOf(this) == 0;
+ return getRoot() == this;
+ }
+
+ public String getShortName(String namespaceURI) {
+ List<SchemaConverter> converters = getRoot().getConverter(namespaceURI);
+ for (SchemaConverter conv : converters) {
+ if (conv.shortName != null)
+ return conv.shortName;
+ }
+ return null;
+ }
+
+ public String getOntologyClassName(String namespaceURI) {
+ List<SchemaConverter> converters = getRoot().getConverter(namespaceURI);
+ for (SchemaConverter conv : converters) {
+ if (conv.className != null)
+ return conv.className;
+ }
+ return null;
}