--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+\r
+import javax.xml.stream.XMLOutputFactory;\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.message.ILogger;\r
+import org.simantics.message.MessageService;\r
+\r
+public class AbstractExporter {\r
+ \r
+ private Session session;\r
+ private File file;\r
+ private ILogger logger;\r
+ private Resource root;\r
+ private XMLWriter xmlWriter;\r
+ \r
+ public AbstractExporter(Session session, File file , Resource root, XMLWriter xmlWriter) {\r
+ this.session = session;\r
+ this.file = file;\r
+ this.root = root;\r
+ this.xmlWriter = xmlWriter;\r
+ }\r
+ \r
+ public AbstractExporter(Session session, File file , Resource root) {\r
+ this.session = session;\r
+ this.file = file;\r
+ this.root = root;\r
+ }\r
+ \r
+ public void setXmlWriter(XMLWriter xmlWriter) {\r
+ this.xmlWriter = xmlWriter;\r
+ }\r
+ \r
+ public void doExport() throws DatabaseException {\r
+ doExport(MessageService.getDefault()); \r
+ }\r
+ \r
+ public void doExport(ILogger logger) throws DatabaseException {\r
+ ExportRequest req = new ExportRequest();\r
+ session.syncRequest(req);\r
+ }\r
+ \r
+ \r
+ private class ExportRequest extends ReadRequest {\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ XMLStreamWriter writer = 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
+ xmlWriter.write(root, writer);\r
+ \r
+ writer.writeEndDocument();\r
+ writer.close();\r
+ } catch (IOException|XMLStreamException e) {\r
+ try {\r
+ writer.close();\r
+ } catch (XMLStreamException err) {\r
+ \r
+ }\r
+ throw new DatabaseException(e);\r
+ } \r
+ \r
+ \r
+ }\r
+ }\r
+\r
+}\r
\r
public interface IDReferenceParser extends XMLElementParser{\r
\r
- public boolean connectReferences(WriteGraph graph, Element element, Map<String,Element> map) throws DatabaseException;\r
+ public boolean connectReferences(WriteGraph graph, ParserElement element, Map<String,ParserElement> map) throws DatabaseException;\r
\r
}\r
import org.simantics.db.Resource;\r
import org.xml.sax.Attributes;\r
\r
-public class Element implements Serializable {\r
+public class ParserElement implements Serializable {\r
private static final long serialVersionUID = -5207502156942818875L;\r
String uri;\r
String localName;\r
XMLElementParser elementParser;\r
XMLParser xmlParser;\r
\r
- public Element(String uri, String localName, String qName, Attributes attributes) {\r
+ public ParserElement(String uri, String localName, String qName, Attributes attributes) {\r
this.uri = uri;\r
this.localName = localName;\r
this.qName = qName;\r
}\r
}\r
\r
- public Element(String uri, String localName, String qName, Collection<Attribute> attributes) {\r
+ public ParserElement(String uri, String localName, String qName, Collection<Attribute> attributes) {\r
this.uri = uri;\r
this.localName = localName;\r
this.qName = qName;\r
\r
public interface UnrecognizedElementParser {\r
\r
- public void configureChild(WriteGraph graph, Deque<Element> parents, Element element, Element child) throws DatabaseException;\r
+ public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException;\r
}\r
}\r
\r
@Override\r
- public Resource create(WriteGraph graph, Element element)\r
+ public Resource create(WriteGraph graph, ParserElement element)\r
throws DatabaseException {\r
Resource res = graph.newResource();\r
return res;\r
}\r
\r
@Override\r
- public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {\r
+ public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {\r
}\r
\r
@Override\r
- public boolean connectParent(WriteGraph graph, Element parent, Element element)throws DatabaseException {\r
+ public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element)throws DatabaseException {\r
graph.claim(parent.getData(), graph.getResource(relationURI), element.getData());\r
return true;\r
}\r
\r
@Override\r
- public boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException {\r
+ public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException {\r
return false;\r
}\r
\r
@Override\r
- public void configure(WriteGraph graph, Element element, String string) throws DatabaseException {\r
+ public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
if (binding == Bindings.STRING) {\r
graph.claim(element.getData(), l0.InstanceOf, l0.String);\r
--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.db.ReadGraph;\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
+ \r
+ String name;\r
+ Binding binding;\r
+ String typeURI;\r
+ \r
+ public ValueElementWriter(String name, String typeURI,Binding binding) {\r
+ this.name = name;\r
+ this.typeURI = typeURI;\r
+ this.binding = binding;\r
+ }\r
+ \r
+ @Override\r
+ public String getElementId() {\r
+ return name;\r
+ }\r
+ \r
+ @Override\r
+ public Resource getType(ReadGraph graph) throws DatabaseException {\r
+ return graph.getResource(typeURI);\r
+ }\r
+ \r
+ @Override\r
+ public void start(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ throws XMLStreamException, DatabaseException {\r
+ writer.writeStartElement(getElementId());\r
+ }\r
+ \r
+ @Override\r
+ public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ throws XMLStreamException, DatabaseException {\r
+ return Collections.EMPTY_LIST;\r
+ }\r
+ \r
+ @Override\r
+ public void end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ throws XMLStreamException, DatabaseException {\r
+ writer.writeEndElement();\r
+ }\r
+ \r
+ @Override\r
+ public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes,\r
+ XMLStreamWriter writer) throws XMLStreamException, DatabaseException {\r
+ \r
+ }\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
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+\r
+public class WriterElement {\r
+ public WriterElement parent;\r
+ public Resource instance;\r
+ public Statement statement;\r
+ public XMLElementWriter writer;\r
+ \r
+ public WriterElement(Resource instance) {\r
+ this.instance = instance;\r
+ }\r
+ \r
+ public WriterElement(WriterElement parent, Statement statement) {\r
+ this.statement = statement;\r
+ this.instance = statement.getObject();\r
+ this.parent = parent;\r
+ }\r
+ \r
+ public Resource getResource() {\r
+ return instance;\r
+ }\r
+ \r
+ public XMLElementWriter getWriter() {\r
+ return writer;\r
+ }\r
+ \r
+ public WriterElement getParent() {\r
+ return parent;\r
+ }\r
+}
\ No newline at end of file
import java.util.Map;\r
\r
public interface XMLElementNamedChildParser extends XMLElementParser{\r
- Class<? extends XMLElementParser> getParser(Map<String,XMLElementParser> parsers, Element element, Element child);\r
+ Class<? extends XMLElementParser> getParser(Map<String,XMLElementParser> parsers, ParserElement element, ParserElement child);\r
}\r
private Set<Class<? extends XMLElementParser>> parsers = new HashSet<Class<? extends XMLElementParser>>();\r
\r
@Override\r
- public Class<? extends XMLElementParser> getParser(Map<String, XMLElementParser> parsers, Element element, Element child) {\r
+ public Class<? extends XMLElementParser> getParser(Map<String, XMLElementParser> parsers, ParserElement element, ParserElement child) {\r
Class<? extends XMLElementParser> parserClass = namedParsers.get(child.qName);\r
if (parserClass != null)\r
return parserClass;\r
// }\r
\r
@Override\r
- public void configure(WriteGraph graph, Element element, String string) throws DatabaseException {\r
+ public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException {\r
\r
}\r
\r
--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public interface XMLElementNamedChildWriter extends XMLElementWriter{\r
+ \r
+ public Class<? extends XMLElementWriter> getWriter(ReadGraph graph, Map<Resource, XMLElementWriter> writers, WriterElement element) throws DatabaseException;\r
+\r
+}\r
--- /dev/null
+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 javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\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
+ private Map<Resource,Class<? extends XMLElementWriter>> typeWriters = new HashMap<Resource, Class<? extends XMLElementWriter>>();\r
+ private Map<Resource,Class<? extends XMLElementWriter>> relationWriters = new HashMap<Resource, Class<? extends XMLElementWriter>>();\r
+ private Set<Class<? extends XMLElementWriter>> writers = new HashSet<Class<? extends XMLElementWriter>>();\r
+ \r
+ \r
+ public XMLElementNamedChildWriterBase() {\r
+ \r
+ }\r
+ \r
+ public XMLElementNamedChildWriterBase(ReadGraph graph) {\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public Resource getType(ReadGraph graph) throws DatabaseException {\r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public void start(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException {\r
+ writer.writeStartElement(getElementId());\r
+ }\r
+ \r
+ @Override\r
+ public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ throws XMLStreamException, DatabaseException {\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException {\r
+ writer.writeEndElement();\r
+ }\r
+ \r
+ @Override\r
+ public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+ throws XMLStreamException, DatabaseException {\r
+ return Collections.EMPTY_LIST;\r
+ }\r
+ \r
+ @Override\r
+ public Class<? extends XMLElementWriter> getWriter(ReadGraph graph, Map<Resource, XMLElementWriter> writers, WriterElement child) throws DatabaseException{\r
+ Resource type = graph.getSingleType(child.instance);\r
+ Class<? extends XMLElementWriter> writerClass = typeWriters.get(type);\r
+ if (writerClass != null)\r
+ return writerClass;\r
+ if (child.statement != null) {\r
+ writerClass = relationWriters.get(child.statement.getPredicate());\r
+ if (writerClass != null)\r
+ return writerClass;\r
+ }\r
+ XMLElementWriter writer = writers.get(type);\r
+ if (writer == null)\r
+ return null;\r
+ writerClass = writer.getClass();\r
+ if (this.writers.contains(writerClass))\r
+ return writerClass;\r
+ for (Class<?> c : this.writers)\r
+ if (c.isAssignableFrom(writerClass))\r
+ return writerClass;\r
+ return null;\r
+ }\r
+ \r
+ public void addTypeWriter(Resource type, Class<? extends XMLElementWriter> writer) {\r
+ typeWriters.put(type, writer);\r
+ }\r
+ \r
+ public void addRelationWriter(Resource relation, Class<? extends XMLElementWriter> writer) {\r
+ relationWriters.put(relation, writer);\r
+ }\r
+ \r
+ public void addWriter(Class<? extends XMLElementWriter> writer) {\r
+ writers.add(writer);\r
+ }\r
+}\r
* @return\r
* @throws DatabaseException\r
*/\r
- public Resource create(WriteGraph graph, Element element) throws DatabaseException;\r
+ public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException;\r
/**\r
* Configures the element.\r
* \r
* @param element\r
* @throws DatabaseException\r
*/\r
- public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException;\r
+ public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException;\r
/**\r
* Configures element with characters content\r
* \r
* @param string\r
* @throws DatabaseException\r
*/\r
- public void configure(WriteGraph graph, Element element, String string) throws DatabaseException;\r
+ public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException;\r
\r
/**\r
* Adds child element. Primary method for connecting elements.\r
* @return true, if connection was done, otherwise return false.\r
* @throws DatabaseException\r
*/\r
- public abstract boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException;\r
+ public abstract boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException;\r
/**\r
* Adds element to a parent. Secondary method for connecting elements. Called only if primary method fails.\r
* @param graph\r
* @return true, if connection was done, otherwise return false.\r
* @throws DatabaseException\r
*/\r
- public abstract boolean connectParent(WriteGraph graph, Element parent, Element element) throws DatabaseException;\r
+ public abstract boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException;\r
\r
\r
//public void configureChild(WriteGraph graph, Stack<Element> parents, Element element, Element child) throws DatabaseException;\r
\r
\r
@Override\r
- public void configure(WriteGraph graph, Element element, String string) throws DatabaseException {\r
+ public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException {\r
\r
}\r
\r
--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public interface XMLElementWriter {\r
+\r
+ public java.lang.String getElementId();\r
+ public Resource getType(ReadGraph graph) throws DatabaseException;\r
+ //public int idPriority();\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 end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+ \r
+}\r
\r
public class XMLParser extends DefaultHandler implements Serializable {\r
\r
+ public static String PLUGIN_ID = "org.simantics.xml.sax.base";\r
+ \r
private static final long serialVersionUID = 7360740940824360338L;\r
private static final boolean debug = false;\r
private static String XML_SCHEMA_REF = "xmlns";\r
private ILogger logger;\r
+ private WriteGraph graph;\r
private Resource root;\r
private String schemaURI;\r
- private Deque<Element> current = new ArrayDeque<Element>();\r
+ private Deque<ParserElement> current = new ArrayDeque<ParserElement>();\r
private Map<String, XMLElementParser> parsers = new HashMap<String, XMLElementParser>();\r
- private WriteGraph graph;\r
private Map<Class<? extends XMLElementParser>, XMLElementParser> namedParsers = new HashMap<Class<? extends XMLElementParser>, XMLElementParser>();\r
- \r
private Map<String, XMLParser> subParsers = new HashMap<String, XMLParser>();\r
\r
public XMLParser() {\r
subParsers.put(parser.getSchemaURI(), parser);\r
}\r
\r
- private List<Element> idReferenceElements = new ArrayList<Element>();\r
- private void loadElement(Deque<Element> parents, Element element) throws SAXException{\r
+ private List<ParserElement> idReferenceElements = new ArrayList<ParserElement>();\r
+ private void loadElement(Deque<ParserElement> parents, ParserElement element) throws SAXException{\r
XMLElementParser parser = null;\r
- Element parent = null;\r
+ ParserElement parent = null;\r
if (parents.size() > 0) {\r
parent = parents.peek();\r
// check for assigned subparser\r
}\r
}\r
\r
- private Map<String, Element> idMap = new HashMap<String, Element>();\r
+ private Map<String, ParserElement> idMap = new HashMap<String, ParserElement>();\r
\r
- private void handleElement(Deque<Element> parents, Element element) throws SAXException{\r
+ private void handleElement(Deque<ParserElement> parents, ParserElement element) throws SAXException{\r
XMLElementParser parser = element.getElementParser();\r
if (parser != null) {\r
try {\r
parser.configure(graph, parents, element);\r
if (parents.size() > 0) {\r
- Element parent = parents.peek();\r
+ ParserElement parent = parents.peek();\r
if (parent.getElementParser() != null) {\r
if (!parent.getElementParser().connectChild(graph, parent, element))\r
if (!parser.connectParent(graph, parent, element)) {\r
}\r
String id = parser.getID();\r
if (id != null) {\r
- Element existing = idMap.put(id, element);\r
+ ParserElement existing = idMap.put(id, element);\r
if (existing != null) {\r
// report error + use id priorities to select the kept element.\r
boolean useExt = existing.elementParser.idPriority() > element.elementParser.idPriority();\r
throw new SAXException(e);\r
}\r
} else {\r
- Element parent = parents.peek();\r
+ ParserElement parent = parents.peek();\r
if (parent != null) { \r
parser = parent.getElementParser();\r
if (parser != null && parser instanceof UnrecognizedElementParser) {\r
}\r
}\r
\r
- private void handleCharacters(Element element, String string) throws SAXException{\r
+ private void handleCharacters(ParserElement element, String string) throws SAXException{\r
XMLElementParser parser = element.getElementParser();\r
if (parser != null) {\r
try {\r
}\r
}\r
\r
- private static String PLUGIN_ID = "org.simantics.xml.sax.base";\r
+ \r
\r
public void done() throws SAXException{\r
try {\r
- for (Element e : idReferenceElements) {\r
+ for (ParserElement e : idReferenceElements) {\r
IDReferenceParser parser = (IDReferenceParser)parsers.get(e.qName);\r
if (!parser.connectReferences(graph, e, idMap)) {\r
String err ="Could not resolve ID references for " + e.getQName() + " " + e.getUri();\r
\r
@Override\r
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {\r
- Element e = new Element(uri,localName,name,attributes);\r
+ ParserElement e = new ParserElement(uri,localName,name,attributes);\r
\r
loadElement(current,e);\r
current.push(e);\r
@Override\r
public void endElement(String uri, String localName, String name)\r
throws SAXException {\r
- Element e = null;\r
+ ParserElement e = null;\r
if (!current.isEmpty()) {\r
e = current.pop();\r
}\r
--- /dev/null
+package org.simantics.xml.sax.base;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.message.ILogger;\r
+import org.simantics.xml.sax.ontology.XMLResource;\r
+\r
+public class XMLWriter {\r
+ \r
+ private ReadGraph graph;\r
+ private Map<String, XMLWriter> subWriters = new HashMap<String, XMLWriter>();\r
+ private Map<Class<? extends XMLElementWriter>, XMLElementWriter> namedWriters = new HashMap<Class<? extends XMLElementWriter>, XMLElementWriter>();\r
+ private Map<Resource,XMLElementWriter> writers = new HashMap<>();\r
+ private String schemaURI;\r
+ \r
+ private ILogger logger;\r
+ \r
+ public ReadGraph getGraph() {\r
+ return graph;\r
+ }\r
+ \r
+ public void setGraph(ReadGraph graph) {\r
+ this.graph = graph;\r
+ for (XMLWriter p : subWriters.values())\r
+ p.setGraph(graph);\r
+ }\r
+ \r
+ public String getSchemaURI() {\r
+ return schemaURI;\r
+ }\r
+ \r
+ public void setSchemaURI(String schemaURI) {\r
+ this.schemaURI = schemaURI;\r
+ }\r
+ \r
+ public void add(XMLElementWriter writer) throws DatabaseException {\r
+ Resource type = writer.getType(graph);\r
+ if (type != null)\r
+ writers.put(type, writer);\r
+ namedWriters.put(writer.getClass(), writer);\r
+ }\r
+ \r
+ public void add(XMLWriter writer) {\r
+ subWriters.put(writer.getSchemaURI(), writer);\r
+ }\r
+ \r
+ public void write(Resource root, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
+ WriterElement element = new WriterElement(root);\r
+ loadElement(element);\r
+ write(element, writer);\r
+ }\r
+ \r
+ \r
+ protected void write(WriterElement instance, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
+ XMLResource XML = XMLResource.getInstance(graph);\r
+\r
+ XMLElementWriter elementWriter = instance.writer;\r
+ elementWriter.start(graph, instance, writer);\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
+ // get all child elements\r
+ Collection<Statement> childElements = graph.getStatements(instance.instance, XML.hasElement);\r
+ // load elements, assign writers\r
+ Map<Resource,WriterElement> elementMap = new HashMap<>();\r
+ for (Statement s : childElements) {\r
+ WriterElement c = new WriterElement(instance,s);\r
+ loadElement(c);\r
+ elementMap.put(s.getObject(), c);\r
+ }\r
+ List<Resource> sorted = elementWriter.children(graph, instance, writer);\r
+ \r
+ for (Resource r : sorted) {\r
+ WriterElement child = elementMap.get(r);\r
+ write(child, writer);\r
+ }\r
+ //write the rest of the elements (in random order) \r
+ for (Statement stm : childElements) {\r
+ if (sorted.contains(stm.getObject()))\r
+ continue;\r
+ WriterElement child = elementMap.get(stm.getObject());\r
+ write(child, writer);\r
+ }\r
+ \r
+ elementWriter.end(graph, instance, 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
+ XMLElementNamedChildWriter namedParentWriter = (XMLElementNamedChildWriter)child.parent.writer;\r
+ Class<? extends XMLElementWriter> childWriterClass = namedParentWriter.getWriter(graph, writers, child);\r
+ if (childWriterClass != null) {\r
+ childWriter = this.writers.get(childWriterClass);\r
+ if (childWriter == null) {\r
+ try {\r
+ Constructor<? extends XMLElementWriter> c = childWriterClass.getConstructor(ReadGraph.class);\r
+ //childWriter = childWriterClass.newInstance();\r
+ childWriter = c.newInstance(graph);\r
+ namedWriters.put(childWriterClass, childWriter);\r
+ } catch (IllegalAccessException|InstantiationException|NoSuchMethodException|SecurityException|InvocationTargetException e) {\r
+ String err = "Error processing " + childWriterClass.getName() + " : element writers must have accessible constructor with ReadGraph parameter";\r
+ logger.log(new Status(IStatus.ERROR, XMLParser.PLUGIN_ID, err));\r
+ } \r
+ }\r
+ }\r
+ } else {\r
+ Resource type = graph.getSingleType(child.instance);\r
+ childWriter = writers.get(type);\r
+ }\r
+ if (childWriter == null) {\r
+ throw new DatabaseException("Cannot locate writer for " + NameUtils.getSafeName(graph, child.instance) + ", " + child.instance);\r
+ }\r
+ child.writer = childWriter;\r
+ \r
+ }\r
+\r
+}\r
\r
\r
// Built-in types\r
-\r
+XML.Entity <T L0.Entity\r
XML.hasAttribute <R L0.HasProperty\r
XML.hasID <R XML.hasAttribute : L0.FunctionalRelation\r
--> L0.String\r
-XML.ComplexType <T L0.Entity\r
+XML.ComplexType <T XML.Entity\r
XML.hasComplexType <R L0.IsComposedOf\r
-XML.AttributeGroup <T L0.Entity\r
-XML.Element <T L0.Entity\r
+XML.AttributeGroup <T XML.Entity\r
+XML.Element <T XML.Entity\r
XML.hasElement <R L0.IsComposedOf\r
XML.ElementList <T L0.List\r
XML.hasElementList <R L0.IsComposedOf\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 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
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
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.wizard.WizardPage;\r
import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Button;\r
import org.eclipse.swt.widgets.Composite;\r
import org.simantics.utils.ui.widgets.DirectorySelectionWidget;\r
import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;\r
private FileSelectionWidget schemaSelection;\r
private FileSelectionWidget configurationSelection;\r
private DirectorySelectionWidget pluginSelection;\r
+ \r
+ boolean createPGraph = true;\r
+ boolean createImporter = true;\r
+ boolean createExporter = true;\r
\r
@Override\r
public void createControl(Composite parent) {\r
schemaSelection.addListener(this);\r
pluginSelection.addListener(this);\r
\r
+ final Button pGraphButton = new Button(composite, SWT.CHECK);\r
+ final Button importButton = new Button(composite, SWT.CHECK);\r
+ final Button exportButton = new Button(composite, SWT.CHECK);\r
+ pGraphButton.setText("Create Ontology / .pgraph file");\r
+ importButton.setText("Create Importer");\r
+ exportButton.setText("Create Exporter");\r
+ pGraphButton.setSelection(createPGraph);\r
+ importButton.setSelection(createImporter);\r
+ exportButton.setSelection(createExporter);\r
+ pGraphButton.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ createPGraph = pGraphButton.getSelection();\r
+ }\r
+ });\r
+ importButton.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ createImporter = importButton.getSelection();\r
+ }\r
+ });\r
+ exportButton.addSelectionListener(new SelectionAdapter() {\r
+ @Override\r
+ public void widgetSelected(SelectionEvent e) {\r
+ createExporter = exportButton.getSelection();\r
+ }\r
+ });\r
+ \r
setControl(composite);\r
setPageComplete(false);\r
}\r
\r
}\r
\r
+ public boolean isCreateExporter() {\r
+ return createExporter;\r
+ }\r
+ \r
+ public boolean isCreateImporter() {\r
+ return createImporter;\r
+ }\r
+ \r
+ public boolean isCreatePGraph() {\r
+ return createPGraph;\r
+ }\r
+ \r
public String getSchemaFilename() {\r
if (schemaSelection.getFilename() == null ||schemaSelection.getFilename().length == 0)\r
return null;\r
\r
public void doConversion() throws Exception {\r
SchemaConverter converter = new SchemaConverter();\r
+ converter.setCreateExporter(inputSelectionPage.createExporter);\r
+ converter.setCreateImporter(inputSelectionPage.createImporter);\r
+ converter.setCreatePGraph(inputSelectionPage.createPGraph);\r
\r
File inputFile = new File(inputSelectionPage.getSchemaFilename());\r
File configurationFile = null;\r
</extension>\r
</complexContent>\r
</complexType>\r
+ </element>\r
+ \r
+ <element name="Rename" substitutionGroup="tns:ConversionRule">\r
+ <complexType>\r
+ <complexContent>\r
+ <extension base="tns:ConversionRule">\r
+ <sequence maxOccurs="unbounded" minOccurs="1">\r
+ <choice>\r
+ <element ref="tns:Element"></element>\r
+ <element ref="tns:ComplexType"></element>\r
+ <element ref="tns:Attribute"></element>\r
+ </choice>\r
+ </sequence>\r
+ <attribute name="Name" type="string"></attribute>\r
+ </extension>\r
+ </complexContent>\r
+ </complexType>\r
</element>
</schema>
\ No newline at end of file
-"c:\Program Files\Java\jdk1.8.0_60\bin\xjc" -d ../src configuration.xsd\r
+"c:\Program Files\Java\jdk1.8.0_112\bin\xjc" -d ../src configuration.xsd\r
--- /dev/null
+package org.simantics.xml.sax;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.io.StringWriter;\r
+import java.util.Collections;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.xml.namespace.QName;\r
+\r
+import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.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
+import org.w3._2001.xmlschema.AttributeGroup;\r
+import org.w3._2001.xmlschema.ComplexType;\r
+import org.w3._2001.xmlschema.Element;\r
+import org.w3._2001.xmlschema.LocalComplexType;\r
+import org.w3._2001.xmlschema.LocalSimpleType;\r
+import org.w3._2001.xmlschema.NamedAttributeGroup;\r
+import org.w3._2001.xmlschema.OpenAttrs;\r
+import org.w3._2001.xmlschema.Restriction;\r
+import org.w3._2001.xmlschema.Schema;\r
+import org.w3._2001.xmlschema.SimpleType;\r
+import org.w3._2001.xmlschema.TopLevelAttribute;\r
+\r
+public class ExporterGenerator extends JavaGenerator{\r
+ \r
+ public ExporterGenerator(Configuration configuration) {\r
+ super(configuration);\r
+ }\r
+\r
+ \r
+ \r
+ public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
+ this.schema = schema;\r
+ this.ontologyClassName = className;\r
+ this.converter = converter;\r
+ \r
+ \r
+ String packageParts[] = className.split("\\.");\r
+ String name = packageParts[packageParts.length-1];\r
+ \r
+ \r
+ ontShort = name.substring(0, 3).toUpperCase();\r
+ ontShort +=".";\r
+ String parserPackagePostfix = "_exp";\r
+ String importerClassPostfix = "Exporter";\r
+ String parserClassPostfix = "Writer";\r
+ elementPackageName = name+parserPackagePostfix;\r
+ \r
+ importParserDir= new File(converter.getParserDir().getAbsolutePath()+"/"+elementPackageName);\r
+ if (!importParserDir.exists())\r
+ importParserDir.mkdirs();\r
+ \r
+ handle(schema);\r
+ // Create Importer class\r
+ File importerFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+importerClassPostfix+".java");\r
+ PrintWriter mainWriter = createFile(importerFile);\r
+ mainWriter.println("package " + converter.getPluginName() +";");\r
+ mainWriter.println();\r
+ mainWriter.println("import java.io.File;");\r
+ mainWriter.println("import org.simantics.db.Resource;");\r
+ mainWriter.println("import org.simantics.db.Session;");\r
+ mainWriter.println("import org.simantics.db.exception.DatabaseException;");\r
+ mainWriter.println("import org.simantics.xml.sax.base.AbstractExporter;");\r
+ mainWriter.println();\r
+ mainWriter.println("public class " + name + importerClassPostfix+" extends AbstractExporter {");\r
+ mainWriter.println();\r
+ mainWriter.println(" public " + name + importerClassPostfix+"(Session session, File file, Resource root) throws DatabaseException {");\r
+ mainWriter.println(" super(session, file, root);");\r
+ mainWriter.println(" setXmlWriter(new "+name + parserClassPostfix+"(session));");\r
+ mainWriter.println(" }");\r
+ mainWriter.println();\r
+ mainWriter.println("}");\r
+ \r
+ mainWriter.println();\r
+ mainWriter.flush();\r
+ mainWriter.close();\r
+ \r
+ // Create Parser class\r
+ File parserFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+parserClassPostfix+".java");\r
+ mainWriter = createFile(parserFile);\r
+ mainWriter.println("package " + converter.getPluginName() +";");\r
+ mainWriter.println();\r
+ mainWriter.println("import org.simantics.xml.sax.base.XMLWriter;");\r
+ mainWriter.println("import org.simantics.db.ReadGraph;");\r
+ mainWriter.println("import org.simantics.db.Session;");\r
+ mainWriter.println("import org.simantics.db.exception.DatabaseException;");\r
+ mainWriter.println("import org.simantics.db.common.request.ReadRequest;");\r
+ mainWriter.println();\r
+ mainWriter.println("public class " + name + parserClassPostfix+" extends XMLWriter {");\r
+ mainWriter.println();\r
+ mainWriter.println(" public " + name + parserClassPostfix+"(Session session) throws DatabaseException {");\r
+ if (schema.getTargetNamespace() != null)\r
+ mainWriter.println(" setSchemaURI(\""+schema.getTargetNamespace()+"\");");\r
+ mainWriter.println(" session.syncRequest(new ReadRequest() {");\r
+ mainWriter.println(" @Override");\r
+ mainWriter.println(" public void run(ReadGraph graph) throws DatabaseException {");\r
+ mainWriter.println(" setGraph(graph);");\r
+ for (String s : ruleClassNames) {\r
+ mainWriter.println(" add(new "+s+"(graph));");\r
+ }\r
+ mainWriter.println(" }");\r
+ mainWriter.println(" });");\r
+ mainWriter.println(" }");\r
+ mainWriter.println("}");\r
+ \r
+ mainWriter.println();\r
+ mainWriter.flush();\r
+ mainWriter.close();\r
+ }\r
+ \r
+ protected void handle(TopLevelAttribute topLevelAttribute) {\r
+\r
+ }\r
+ \r
+ @Override\r
+ protected String getBaseClass() {\r
+ return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
+ }\r
+ \r
+\r
+ @Override\r
+ protected void handleComplexType(SchemaObject complexTypeObj) {\r
+ ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
+ \r
+ String name = getName(complexTypeObj);//topLevelComplexType.getName();\r
+ \r
+ String className = name;//"_"+name;\r
+ \r
+ FileWriter fw = new FileWriter();\r
+ try {\r
+ fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));\r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ writers.put(complexTypeObj, fw);\r
+ \r
+ boolean isList = false;\r
+\r
+ String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
+ \r
+ boolean inherited = false;\r
+ \r
+ QName type = getComplexTypeBase(topLevelComplexType);\r
+ if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
+ baseClass = getName(complexTypeName.get(type.getLocalPart()));\r
+ inherited = true;\r
+ }\r
+ \r
+ provider = getIDProvider(topLevelComplexType);\r
+ List<IDReference> references = getIDReferences(topLevelComplexType);\r
+ UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
+\r
+// List<String> intrerfaces = new ArrayList<String>();\r
+// if (references.size() > 0)\r
+// intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");\r
+// if (unknownChildElement != null)\r
+// intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
+ \r
+ createClassHeader(fw.writer);\r
+ writeClass(fw.writer,false, null, className, baseClass, Collections.EMPTY_LIST);\r
+ \r
+// writeIDProvider(fw.writer);\r
+ \r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public Resource getType(ReadGraph graph) throws DatabaseException {");\r
+ fw.writer.println(" "+getOntologyImport());\r
+ fw.writer.println(" return "+ontShort+name+";");\r
+ fw.writer.println(" }");\r
+ fw.writer.println();\r
+ \r
+// fw.writer.println(" @Override");\r
+// fw.writer.println(" public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
+// fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);");\r
+// fw.writer.println(" "+getOntologyImport());\r
+// if (!isList) {\r
+// fw.writer.println(" Resource res = graph.newResource();");\r
+// fw.writer.println(" graph.claim(res, L0.InstanceOf, "+ontShort+name+");");\r
+// } else {\r
+// fw.writer.println(" Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");\r
+// }\r
+// fw.writer.println(" return res;");\r
+// fw.writer.println(" }");\r
+// fw.writer.println();\r
+ \r
+// fw.writer.println(" @Override");\r
+// fw.writer.println(" public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
+// fw.writer.println(" "+getOntologyImport());\r
+// fw.writer.println(" graph.claim(parent.getData(), "+this.ontShort+getName(complexTypeObj,"has")+", element.getData());");\r
+// fw.writer.println(" return true;");\r
+// fw.writer.println(" }");\r
+// fw.writer.println();\r
+ \r
+ StringWriter stringWriter = new StringWriter();\r
+ fw.delayedWriter = new PrintWriter(stringWriter);\r
+ StringWriter stringWriter2 = new StringWriter();\r
+ fw.delayedWriter2 = new PrintWriter(stringWriter2);\r
+ \r
+ fw.writer.println(" public " + className + "(ReadGraph graph) {");\r
+ fw.writer.println(" super(graph);");\r
+ fw.writer.println(" "+getOntologyImport());\r
+ \r
+ handleComplexTypeExtension(complexTypeObj);\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
+ \r
+ if (stringWriter2.getBuffer().length() > 0) {\r
+ fw.writer.write(stringWriter2.toString());\r
+ }\r
+ \r
+ stringWriter = null;\r
+ fw.delayedWriter.close();\r
+ fw.delayedWriter=null;\r
+ stringWriter2 = null;\r
+ fw.delayedWriter2.close();\r
+ fw.delayedWriter2 = null;\r
+ \r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");\r
+ if (inherited) {\r
+ fw.writer.println(" super.attributes(graph,instance,attributes,writer);");\r
+ }\r
+ fw.writer.println(" "+getOntologyImport());\r
+ fw.writer.println(" for (Statement attribute : attributes) {");\r
+ handleComplexTypeAttributes(complexTypeObj);\r
+ handleExtensionAttributes(complexTypeObj);\r
+ fw.writer.println(" }");\r
+ fw.writer.println(" }");\r
+ \r
+// writeIDReferences(fw.writer,name, references);\r
+// writeUnknownChild(fw.writer,name,unknownChildElement);\r
+ \r
+ fw.writer.println("}");\r
+ fw.writer.println();\r
+ fw.writer.flush();\r
+ fw.writer.close();\r
+ fw.writer = null;\r
+ writers.remove(complexTypeObj);\r
+ provider = null;\r
+ }\r
+ \r
+ \r
+ \r
+ @Override\r
+ protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String ref, QName refType) {\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
+ \r
+ if (refComplexType != null) {\r
+ refClassName = getName(refComplexType);\r
+ } else {\r
+ refClassName = getName(refElement);\r
+ }\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
+ \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
+// // 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, 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
+ 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
+ // generates overriding method that allows writing any element\r
+ FileWriter fw = getWriter(parent);\r
+ fw.delayedWriter2.println(" @Override");\r
+ fw.delayedWriter2.println(" public Class<? extends org.simantics.xml.sax.base.XMLElementWriter> getWriter(ReadGraph graph, java.util.Map<Resource, org.simantics.xml.sax.base.XMLElementWriter> writers, WriterElement child) throws DatabaseException{");\r
+ fw.delayedWriter2.println(" Class<? extends org.simantics.xml.sax.base.XMLElementWriter> writerClass = super.getWriter(graph, writers, child);");\r
+ fw.delayedWriter2.println(" if (writerClass != null) return writerClass;");\r
+ fw.delayedWriter2.println(" Resource type = graph.getSingleType(child.instance);");\r
+ fw.delayedWriter2.println(" org.simantics.xml.sax.base.XMLElementWriter writer = writers.get(type);");\r
+ fw.delayedWriter2.println(" if (writer != null) return writer.getClass();");\r
+ fw.delayedWriter2.println(" return null;");\r
+ fw.delayedWriter2.println(" }");\r
+ }\r
+ \r
+ \r
+ \r
+ \r
+ @Override \r
+ protected void handle(SchemaObject parent, Attribute attribute) {\r
+ String name = attribute.getName();\r
+ QName primitiveType = attribute.getType();\r
+ SimpleType simpleType = attribute.getSimpleType();\r
+ QName ref = attribute.getRef();\r
+ \r
+ String relationName;\r
+ String attrName;\r
+ if (name != null) {\r
+ attrName = name;\r
+ relationName = ontShort+"has"+name;\r
+ if (parent != null)\r
+ relationName = ontShort+getName(parent)+"_has"+name;\r
+ }\r
+ else if (ref != null && parent != null) {\r
+ attrName = ref.getLocalPart();\r
+ relationName = ontShort+getName(parent)+"_has"+ref.getLocalPart();\r
+ \r
+ Attribute referred = getRefAttribute(ref);\r
+ if (referred != null) {\r
+ primitiveType = referred.getType();\r
+ simpleType = referred.getSimpleType();\r
+ }\r
+ \r
+ } else {\r
+ throw new RuntimeException();\r
+ }\r
+ boolean isReference = false;\r
+ if (provider!= null && provider.getAttribute().getName().equals(attrName))\r
+ isReference = true;\r
+ \r
+ FileWriter fw = getWriter(parent);\r
+ if (primitiveType != null) {\r
+ \r
+ //String binding = getBindingFromPrimitiveType(primitiveType);\r
+ TypeEntry binding = getTypeEntry(primitiveType);\r
+ \r
+ if (binding != null) {\r
+ writeAttribute(fw, attrName, relationName, binding, isReference);\r
+ return;\r
+ } else {\r
+ if (simpleType == null) {\r
+ SchemaObject simpleTypeObj = simpleTypeName.get(primitiveType.getLocalPart());\r
+ if (simpleTypeObj != null)\r
+ simpleType = simpleTypeObj.getSimpleType();\r
+ } \r
+ }\r
+ } \r
+ if (simpleType != null) {\r
+ org.w3._2001.xmlschema.List list = simpleType.getList();\r
+ if (list != null) {\r
+ TypeEntry binding = getTypeEntry(new QName(SCHEMA_NS, "string"));\r
+ writeAttribute(fw, attrName, relationName, binding, isReference);\r
+ } else {\r
+ Restriction restriction = simpleType.getRestriction();\r
+ if (restriction == null)\r
+ throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()+ ", SimpleType restriction is unset");\r
+ QName base = restriction.getBase();\r
+ \r
+ \r
+ //String binding = getBindingFromPrimitiveType(base);\r
+ TypeEntry binding = getTypeEntry(base);\r
+ writeAttribute(fw, attrName, relationName, binding, isReference);\r
+ }\r
+ } else {\r
+ // TODO : using default String attribute should be configured with rules.\r
+ //throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());\r
+ fw.writer.println(" //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");\r
+ //writeAttribute(fw, attrName, relationName, "STRING", isReference);\r
+ writeAttribute(fw, attrName, relationName, getTypeEntry("string"), isReference);\r
+ }\r
+ }\r
+ \r
+ //private void writeAttribute(FileWriter fw, String attrName, String relationName, String binding, boolean isReference) {\r
+ private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {\r
+ fw.writer.println(" {");\r
+ fw.writer.println(" if (attribute.getPredicate().equals("+relationName+")) {"); \r
+ fw.writer.println(" writer.writeAttribute(\""+attrName+"\", " + binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");\r
+ // fw.writer.println(" graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");\r
+ // if (isReference)\r
+ // fw.writer.println(" idProviderValue = a.getValue();"); \r
+ fw.writer.println(" }");\r
+ fw.writer.println(" }");\r
+ }\r
+ \r
+ @Override\r
+ protected void handleAttributes(SchemaObject simpleTypeObj) {\r
+ SchemaObject parent = simpleTypeObj.getParent();\r
+ FileWriter fw = getWriter(parent);\r
+ \r
+ SimpleType simpleType = simpleTypeObj.getSimpleType();\r
+ Restriction restriction = simpleType.getRestriction();\r
+ if (restriction == null)\r
+ throw new RuntimeException("Cannot resolve type for Element " + getName(parent));\r
+ QName base = restriction.getBase();\r
+ \r
+ \r
+ //String binding = getBindingFromPrimitiveType(base);\r
+ TypeEntry binding = getTypeEntry(base);\r
+ \r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
+ fw.writer.println(" writer.writeCharacters("+ binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");\r
+// fw.writer.println(" graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
+ fw.writer.println(" }");\r
+ }\r
+ \r
+ @Override\r
+ protected void handle(SchemaObject parent, AttributeGroup attribute) {\r
+ if (parent != null) {\r
+ FileWriter fw = getWriter(parent);\r
+ NamedAttributeGroup group = getAttributeGroup(attribute.getRef().getLocalPart());\r
+ fw.writer.println(commentTag+" AttributeGroup " + group.getName());\r
+ SchemaObject obj = new SchemaObject(parent,attribute);\r
+ for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
+ if (annotated instanceof Attribute) {\r
+ //handle("AttributeGroups_"+group.getName(),(Attribute)annotated);\r
+ handle(obj,(Attribute)annotated);\r
+ } else if (annotated instanceof AttributeGroup) {\r
+ //handle("AttributeGroups_"+group.getName(),(AttributeGroup)annotated);\r
+ handle(obj,(AttributeGroup)annotated);\r
+ }\r
+ }\r
+ fw.writer.println(commentTag+" End of AttributeGroup " + group.getName());\r
+ }\r
+ \r
+ }\r
+ \r
+ @Override\r
+ protected void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
+ FileWriter fw = getWriter(parent);\r
+ QName type = new QName(CONVERSION_NS, composition.getType());\r
+ TypeEntry typeEntry = getTypeEntry(type);\r
+ String arrayBinding = typeEntry.binding;//getBindingFromPrimitiveType(type);\r
+ String javaType = typeEntry.javaType;//getJavaTypeFromPrimitiveType(type);\r
+ String name = composition.getName();\r
+ \r
+ String relationName;\r
+ if (name != null) {\r
+ relationName = ontShort+"has"+name;\r
+ if (parent != null)\r
+ relationName = ontShort+getName(parent)+"_has"+name;\r
+ } else {\r
+ throw new RuntimeException();\r
+ }\r
+ fw.writer.println(" if (attribute.getPredicate().equals("+relationName+")) {");\r
+ fw.writer.println(" "+javaType+" value = ("+javaType+")graph.getValue(attribute.getObject(),"+arrayBinding+");");\r
+ //fw.writer.println(" writer.writeAttribute("+attrName+", graph.getValue(attribute.getObject(),"+binding.binding+").toString());");\r
+\r
+ int i = 0;\r
+ for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute())\r
+ fw.writer.println(" writer.writeAttribute(\""+a.getName()+"\","+typeEntry.getElementToString("value["+(i++)+"]")+");");\r
+ //fw.writer.println(" writer.writeAttribute(\""+a.getName()+"\",value["+(i++)+"].toString());");\r
+// fw.writer.println(" Attribute a"+(i++)+" = element.getAttribute(\"" +a.getName()+"\");");\r
+// fw.writer.print (" "+javaType + " value = new "+javaType+"{");\r
+ i = 0;\r
+ // FIXME : handle optional attributes properly.\r
+// for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute()) {\r
+// Attribute attribute = ((Attribute)attributes.getRight(a));\r
+// //QName atype = getBaseType(attribute);\r
+// QName atype = getPrimitiveType(attribute);\r
+// String defaultValue = attribute.getDefault();\r
+// if (defaultValue == null)\r
+// defaultValue = getDefaultValue(atype);\r
+// \r
+// //String binding = getBindingFromPrimitiveType(atype);\r
+// TypeEntry binding = getTypeEntry(atype);\r
+// if (i > 0)\r
+// fw.writer.print(",");\r
+// if (defaultValue != null)\r
+// fw.writer.print("a"+(i)+"!= null ? "+ getValueGetterMethod(binding,"a"+(i++)) + " : " +defaultValue);\r
+// else\r
+// fw.writer.print(getValueGetterMethod(binding,"a"+(i++)));\r
+// }\r
+// fw.writer.println("};");\r
+// fw.writer.println(" graph.claimLiteral(element.getData(),"+relationName+", value, "+arrayBinding+");");\r
+ fw.writer.println(" }");\r
+ \r
+ }\r
+ \r
+ protected String getDefaultValue(QName atype) {\r
+ Map<String,TypeEntry> types = typeMap.get(atype.getNamespaceURI());\r
+ if (types == null)\r
+ return null;\r
+ TypeEntry entry = types.get(atype.getLocalPart());\r
+ if (entry == null)\r
+ return null;\r
+ return entry.defaultValue;\r
+ }\r
+ \r
+ \r
+ @Override\r
+ protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
+\r
+ }\r
+ \r
+ \r
+ \r
+ IDProvider provider;\r
+ @Override\r
+ protected void handleElement(SchemaObject elementObj) {\r
+ Element element = elementObj.getElement();\r
+ \r
+ String name = getName(elementObj);//topLevelElement.getName();\r
+ String className = name;\r
+ \r
+ FileWriter fw = new FileWriter();\r
+ try {\r
+ fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));\r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ writers.put(elementObj, fw);\r
+ boolean isList = false;\r
+ \r
+ Inheritance inhertiance = getElementInheritance(elementObj); \r
+ \r
+ provider = getIDProvider(element);\r
+ List<IDReference> references = getIDReferences(element);\r
+ UnrecognizedChildElement unknownChildElement = getUnknown(element);\r
+\r
+// List<String> intrerfaces = new ArrayList<String>();\r
+// if (references.size() > 0)\r
+// intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");\r
+// if (unknownChildElement != null)\r
+// intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
+\r
+ createClassHeader(fw.writer);\r
+ writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, Collections.EMPTY_LIST);\r
+// writeIDProvider(fw.writer);\r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public Resource getType(ReadGraph graph) throws DatabaseException {");\r
+ fw.writer.println(" "+getOntologyImport());\r
+ fw.writer.println(" return "+ontShort+name+";");\r
+// if (!isList) {\r
+// fw.writer.println(" Resource res = graph.newResource();");\r
+// fw.writer.println(" graph.claim(res, L0.InstanceOf, "+ontShort+name+");");\r
+// } else {\r
+// fw.writer.println(" Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");\r
+// }\r
+// fw.writer.println(" return res;");\r
+ fw.writer.println(" }");\r
+ fw.writer.println();\r
+ \r
+// fw.writer.println(" @Override");\r
+// fw.writer.println(" public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
+// fw.writer.println(" "+getOntologyImport());\r
+// fw.writer.println(" graph.claim(parent.getData(), "+this.ontShort+getName(elementObj,"has")+", element.getData());");\r
+// fw.writer.println(" return true;");\r
+// fw.writer.println(" }");\r
+// fw.writer.println();\r
+ LocalComplexType complexType = element.getComplexType();\r
+ LocalSimpleType simpleType = element.getSimpleType();\r
+ \r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");\r
+ if (inhertiance.type == InheritanceType.ComplexType) {\r
+ fw.writer.println(" super.attributes(graph,instance,attributes,writer);");\r
+ }\r
+ fw.writer.println(" "+getOntologyImport());\r
+ fw.writer.println(" for (Statement attribute : attributes) {");\r
+ if (complexType != null) {\r
+ SchemaObject obj = complexTypes.get(complexType);\r
+ handleElementComplexTypeAttributes(obj);\r
+ } \r
+ fw.writer.println(" }");\r
+ fw.writer.println(" }");\r
+ \r
+// fw.writer.println(" @Override");\r
+// fw.writer.println(" public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
+// if (inhertiance.type == InheritanceType.ComplexType) {\r
+// fw.writer.println(" super.configure(graph,parents,element);");\r
+// }\r
+// fw.writer.println(" "+getOntologyImport());\r
+// \r
+// LocalComplexType complexType = element.getComplexType();\r
+// LocalSimpleType simpleType = element.getSimpleType();\r
+// \r
+// if (complexType != null) {\r
+// SchemaObject obj = complexTypes.get(complexType);\r
+// handleElementComplexTypeAttributes(obj);\r
+// } \r
+// fw.writer.println(" }");\r
+ \r
+ if (inhertiance.type == InheritanceType.AtomicType) {\r
+ fw.writer.println();\r
+// fw.writer.println(" @Override");\r
+// fw.writer.println(" public void configure(WriteGraph graph, ParserElement element, java.lang.String string) throws DatabaseException {");\r
+// fw.writer.println(" graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");\r
+// fw.writer.println(" }");\r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
+ fw.writer.println(" writer.writeCharacters("+inhertiance.atomicType.getToString("graph.getValue(instance.getResource(),"+inhertiance.atomicType.binding+")")+");");\r
+// fw.writer.println(" graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
+ fw.writer.println(" }");\r
+ }\r
+// if (simpleType != null) {\r
+// SchemaObject obj = simpleTypes.get(simpleType);\r
+// handleElementSimpleTypeAttributes(obj);\r
+// }\r
+ \r
+ \r
+ StringWriter stringWriter = new StringWriter();\r
+ fw.delayedWriter = new PrintWriter(stringWriter);\r
+ StringWriter stringWriter2 = new StringWriter();\r
+ fw.delayedWriter2 = new PrintWriter(stringWriter2);\r
+ \r
+ fw.writer.println(" public " + className + "(ReadGraph graph) {");\r
+ fw.writer.println(" super(graph);");\r
+ fw.writer.println(" "+getOntologyImport());\r
+ if (complexType != null) {\r
+ SchemaObject obj = complexTypes.get(complexType);\r
+ handleComplexTypeExtension(obj);\r
+ } else if (simpleType != null) {\r
+ \r
+ }\r
+ \r
+ fw.writer.println(" }");\r
+ \r
+// fw.writer.println(" @Override");\r
+// fw.writer.println(" public 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
+ \r
+ if (stringWriter2.getBuffer().length() > 0) {\r
+ fw.writer.write(stringWriter2.toString());\r
+ }\r
+ \r
+ stringWriter = null;\r
+ fw.delayedWriter.close();\r
+ fw.delayedWriter = null;\r
+ stringWriter2 = null;\r
+ fw.delayedWriter2.close();\r
+ fw.delayedWriter2 = null;\r
+ \r
+// writeIDReferences(fw.writer,name, references);\r
+// writeUnknownChild(fw.writer,name,unknownChildElement);\r
+\r
+ fw.writer.println("}");\r
+ fw.writer.println();\r
+ fw.writer.flush();\r
+ fw.writer.close();\r
+ fw.writer = null;\r
+ writers.remove(elementObj);\r
+ provider = null;\r
+ \r
+ ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);\r
+ }\r
+ \r
+ \r
+// private void writeIDProvider(PrintWriter writer) {\r
+// if (provider != null) {\r
+// writer.println(" java.lang.String idProviderValue = null;");\r
+// writer.println();\r
+// writer.println(" @Override");\r
+// writer.println(" public java.lang.String getID() {");\r
+// writer.println(" java.lang.String s = idProviderValue;");\r
+// writer.println(" idProviderValue = null;");\r
+// writer.println(" return s;");\r
+// writer.println(" }");\r
+// writer.println();\r
+// if (provider.getPriority() != null) {\r
+// writer.println(" @Override");\r
+// writer.println(" public int idPriority() {");\r
+// writer.println(" return " + provider.getPriority().intValue()+";");\r
+// writer.println(" }"); \r
+// }\r
+// }\r
+// }\r
+// \r
+// private void writeIDReferences(PrintWriter writer,String name, List<IDReference> references) {\r
+// if (references.size() > 0) {\r
+// writer.println(" @Override");\r
+// writer.println(" public boolean connectReferences(WriteGraph graph, ParserElement element, java.util.Map<java.lang.String, ParserElement> map) throws DatabaseException {");\r
+// writer.println(" "+getOntologyImport());\r
+// writer.println(" boolean result = true;");\r
+// for (IDReference ref : references) {\r
+// writer.println(" {");\r
+// writer.println(" Attribute a = element.getAttribute(\"" + ref.getIDSource().getName() +"\");");\r
+// writer.println(" if (a != null) {");\r
+// writer.println(" ParserElement refEle = map.get(a.value);");\r
+// writer.println(" if (refEle != null) {");\r
+// writer.println(" Resource ref = refEle.getData();");\r
+// writer.println(" graph.claim(element.getData(), "+ontShort+name+"_"+ref.getReference().getName()+", ref);");\r
+// writer.println(" } else {");\r
+// writer.println(" result = false;");\r
+// writer.println(" }");\r
+// writer.println(" }");\r
+// writer.println(" }");\r
+// }\r
+// writer.println(" return result;");\r
+// writer.println(" }");\r
+// writer.println();\r
+// }\r
+// }\r
+ \r
+// private void writeUnknownChild(PrintWriter writer,String name, UnrecognizedChildElement unknownChildElement) {\r
+// if (unknownChildElement == null)\r
+// return;\r
+// \r
+// writer.println(" @Override");\r
+// writer.println(" public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException {");\r
+// writer.println(" " + unknownChildElement.getJavaMethod());\r
+// writer.println(" }");\r
+// writer.println();\r
+// \r
+// }\r
+ \r
+ protected void createClassHeader(PrintWriter writer) {\r
+ writer.println("package " + converter.getPluginName() +"."+elementPackageName+";");\r
+ writer.println();\r
+ writer.println("import org.simantics.databoard.Bindings;");\r
+ writer.println("import org.simantics.db.Resource;");\r
+ writer.println("import org.simantics.db.ReadGraph;");\r
+ writer.println("import org.simantics.db.Statement;");\r
+ writer.println("import org.simantics.db.exception.DatabaseException;");\r
+ writer.println("import org.simantics.xml.sax.base.WriterElement;");\r
+ writer.println("import org.simantics.xml.sax.ontology.XMLResource;");\r
+ writer.println("import java.util.Collection;");\r
+ writer.println("import javax.xml.stream.XMLStreamException;");\r
+ writer.println("import javax.xml.stream.XMLStreamWriter;");\r
+// if (!isList) {\r
+// writer.println("import org.simantics.layer0.Layer0;");\r
+// } else {\r
+// writer.println("import java.util.Collections;");\r
+// writer.println("import org.simantics.db.common.utils.ListUtils;");\r
+// }\r
+ writer.println();\r
+ }\r
+ \r
+\r
+\r
+}\r
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
import org.w3._2001.xmlschema.SimpleType;\r
import org.w3._2001.xmlschema.TopLevelAttribute;\r
\r
-public class ImporterGenerator extends SchemaConversionBase{\r
+public class ImporterGenerator extends JavaGenerator{\r
\r
public ImporterGenerator(Configuration configuration) {\r
super(configuration);\r
}\r
-\r
- String commentTag = "//";\r
- \r
- Schema schema;\r
- String ontologyClassName;\r
- SchemaConverter converter;\r
- \r
- List<String> ruleClassNames = new ArrayList<String>();\r
- \r
- String ontShort = "ONT"; \r
- \r
- File importParserDir;\r
- String elementPackageName;\r
\r
public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
this.schema = schema;\r
mainWriter.println(" super(session, file, new "+name + parserClassPostfix+"());");\r
mainWriter.println(" }");\r
mainWriter.println();\r
-// mainWriter.println(" @Override");\r
-// mainWriter.println(" public void configure(XMLParser parser) {");\r
-// for (String s : ruleClassNames) {\r
-// mainWriter.println(" parser.add(new "+s+"());");\r
-// }\r
-// mainWriter.println(" }");\r
mainWriter.println("}");\r
\r
mainWriter.println();\r
mainWriter.flush();\r
mainWriter.close();\r
}\r
- \r
- protected PrintWriter createFile(File file) throws IOException {\r
- if (!file.exists())\r
- file.createNewFile();\r
- PrintWriter writer = new PrintWriter(file);\r
- for (String s : converter.getHeader()) {\r
- writer.println(commentTag + " " + s); \r
- }\r
- writer.println();\r
- return writer;\r
- }\r
- \r
-// protected String getValueGetter(String binding,String name) {\r
-// if (binding == null)\r
-// return name+".getValue()";\r
-// if ("STRING".equals(binding))\r
-// return name+".getValue()";\r
-// if ("BOOLEAN".equals(binding))\r
-// return "Boolean.parseBoolean("+name+".getValue())";\r
-// if ("INTEGER".equals(binding))\r
-// return "Integer.parseInt("+name+".getValue())";\r
-// if ("DOUBLE".equals(binding))\r
-// return "Double.parseDouble("+name+".getValue())";\r
-// if ("FLOAT".equals(binding))\r
-// return "Float.parseFloat("+name+".getValue())";\r
-// return name+".getValue()";\r
-// }\r
-// protected String getValueGetter(String binding) {\r
-// if (binding == null)\r
-// return "value";\r
-// if ("STRING".equals(binding))\r
-// return "value";\r
-// if ("BOOLEAN".equals(binding))\r
-// return "Boolean.parseBoolean(value)";\r
-// if ("INTEGER".equals(binding))\r
-// return "Integer.parseInt(value)";\r
-// if ("DOUBLE".equals(binding))\r
-// return "Double.parseDouble(value)";\r
-// if ("FLOAT".equals(binding))\r
-// return "Float.parseFloat(value)";\r
-// return "value";\r
-// }\r
- protected String getValueGetterMethod(TypeEntry binding,String name) {\r
- if (binding == null)\r
- return name+".getValue()";\r
- return binding.getValueGetterMethod(name);\r
- }\r
- \r
- protected String getValueGetter(TypeEntry binding,String name) {\r
- if (binding == null)\r
- return name;\r
- return binding.getValueGetter(name);\r
- }\r
- protected String getValueGetter(TypeEntry binding) {\r
- if (binding == null)\r
- return "value";\r
- return binding.getValueGetter();\r
- }\r
- \r
+\r
protected void handle(TopLevelAttribute topLevelAttribute) {\r
\r
}\r
\r
-\r
- \r
- public static String getComplexTypePrefix() {\r
- return "ComplexTypes_";\r
- } \r
\r
- public static String getAttributeGroupPrefix() {\r
- return "AttributeGroups_";\r
- }\r
- \r
- private Map<SchemaObject, FileWriter> writers = new HashMap<SchemaObject, ImporterGenerator.FileWriter>();\r
@Override\r
protected void handleComplexType(SchemaObject complexTypeObj) {\r
ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
writeIDProvider(fw.writer);\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public Resource create(WriteGraph graph, Element element) throws DatabaseException{");\r
+ fw.writer.println(" public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);");\r
fw.writer.println(" "+getOntologyImport());\r
if (!isList) {\r
fw.writer.println();\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public boolean connectParent(WriteGraph graph, Element parent, Element element) throws DatabaseException{");\r
+ fw.writer.println(" public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
fw.writer.println(" "+getOntologyImport());\r
fw.writer.println(" graph.claim(parent.getData(), "+this.ontShort+getName(complexTypeObj,"has")+", element.getData());");\r
fw.writer.println(" return true;");\r
fw.writer.println(" }");\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException{");\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.delayedWriter2 = null;\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {");\r
+ fw.writer.println(" public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
if (inherited) {\r
fw.writer.println(" super.configure(graph,parents,element);");\r
}\r
provider = null;\r
}\r
\r
- @Override\r
- protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {\r
- if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {\r
- for (SchemaElement e : elements) {\r
- handle(parent, indicator, e);\r
- }\r
- } else if (indicator.getType() == SchemaElement.ElementType.CHOICE) {\r
- String name = getChoiceName(elements);\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
- } else if (localElement.getRef() != null) {\r
- QName refType = localElement.getRef();\r
- handleIndicator(parent, indicator, e, true, name, refType);\r
- }\r
- }\r
- }\r
- \r
- }\r
- \r
@Override\r
protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String ref, QName refType) {\r
FileWriter fw = getWriter(parent);\r
if (binding == null) {\r
SchemaObject refElement = elementName.get(refType.getLocalPart());\r
SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
-// String className = refType.getLocalPart();\r
-// if (!isElementRef(refType.getLocalPart())) { \r
-// className = "_"+className;\r
-// }\r
-// \r
-// String refClassName = refType.getLocalPart();\r
-// if (isComplexTypeRef(refClassName)) {\r
-// refClassName = "_"+refClassName;\r
-// }\r
+\r
String className = null;\r
String refClassName = null;\r
if (refElement != null)\r
if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
// generic list\r
fw.delayedWriter.println(" {");\r
- //fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+"XML_hasOriginalElementList);");\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(),"+ontShort+"XML_hasOriginalElementList,list);");\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
FileWriter fw = getWriter(parent);\r
SchemaObject obj = getWithObj(parent, attrs);\r
\r
-// String className = refType.getLocalPart();\r
-// if (!isElementRef(refType.getLocalPart())) { \r
-// className = "_"+className;\r
-// }\r
-// \r
-// String refClassName = refType.getLocalPart();\r
-// if (isComplexTypeRef(refClassName)) {\r
-// refClassName = "_"+refClassName;\r
-// }\r
String className = getName(obj);\r
- \r
- \r
+\r
if (!reference)\r
fw.writer.println(" addParser(\""+ ref +"\", "+className+".class);");\r
else\r
if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
// generic list\r
fw.delayedWriter.println(" {");\r
- //fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+"XML_hasOriginalElementList);");\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(),"+ontShort+"XML_hasOriginalElementList,list);");\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
\r
@Override\r
protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) { \r
+ // generates overriding method that allows parsing any element\r
FileWriter fw = getWriter(parent);\r
fw.delayedWriter2.println(" @Override");\r
- fw.delayedWriter2.println(" public Class<? extends org.simantics.xml.sax.base.XMLElementParser> getParser(java.util.Map<java.lang.String,org.simantics.xml.sax.base.XMLElementParser> parsers, Element element, Element child) {");\r
+ fw.delayedWriter2.println(" public Class<? extends org.simantics.xml.sax.base.XMLElementParser> getParser(java.util.Map<java.lang.String,org.simantics.xml.sax.base.XMLElementParser> parsers, ParserElement element, ParserElement child) {");\r
fw.delayedWriter2.println(" Class<? extends org.simantics.xml.sax.base.XMLElementParser> parserClass = super.getParser(parsers, element, child);");\r
fw.delayedWriter2.println(" if (parserClass != null) return parserClass;");\r
fw.delayedWriter2.println(" org.simantics.xml.sax.base.XMLElementParser parser = parsers.get(child.getQName());");\r
fw.delayedWriter2.println(" return null;");\r
fw.delayedWriter2.println(" }");\r
}\r
- \r
- private FileWriter getWriter(SchemaObject obj) {\r
- SchemaObject s = obj;\r
- while (s != null) {\r
- FileWriter fw = writers.get(s);\r
- if (fw != null)\r
- return fw;\r
- s = s.getParent();\r
- }\r
- return null;\r
- }\r
- \r
- \r
+\r
@Override \r
protected void handle(SchemaObject parent, Attribute attribute) {\r
String name = attribute.getName();\r
//String binding = getBindingFromPrimitiveType(base);\r
TypeEntry binding = getTypeEntry(base);\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public void configure(WriteGraph graph, Element element, java.lang.String value) throws DatabaseException {");\r
+ fw.writer.println(" public void configure(WriteGraph graph, ParserElement element, java.lang.String value) throws DatabaseException {");\r
//fw.writer.println(" graph.claimValue(element.getData(),"+getValueGetter(binding)+", Bindings."+binding+");");\r
fw.writer.println(" graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
fw.writer.println(" }");\r
protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
\r
}\r
- \r
- \r
+\r
\r
IDProvider provider;\r
@Override\r
writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, intrerfaces);\r
writeIDProvider(fw.writer);\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public Resource create(WriteGraph graph, Element element) throws DatabaseException{");\r
+ fw.writer.println(" public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
fw.writer.println(" Layer0 L0 = Layer0.getInstance(graph);");\r
fw.writer.println(" "+getOntologyImport());\r
if (!isList) {\r
fw.writer.println();\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public boolean connectParent(WriteGraph graph, Element parent, Element element) throws DatabaseException{");\r
+ fw.writer.println(" public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
fw.writer.println(" "+getOntologyImport());\r
fw.writer.println(" graph.claim(parent.getData(), "+this.ontShort+getName(elementObj,"has")+", element.getData());");\r
fw.writer.println(" return true;");\r
fw.writer.println();\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {");\r
+ fw.writer.println(" public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
if (inhertiance.type == InheritanceType.ComplexType) {\r
fw.writer.println(" super.configure(graph,parents,element);");\r
}\r
if (inhertiance.type == InheritanceType.AtomicType) {\r
fw.writer.println();\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public void configure(WriteGraph graph, Element element, java.lang.String string) throws DatabaseException {");\r
+ fw.writer.println(" public void configure(WriteGraph graph, ParserElement element, java.lang.String string) throws DatabaseException {");\r
fw.writer.println(" graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");\r
fw.writer.println(" }");\r
}\r
- if (simpleType != null) {\r
- SchemaObject obj = simpleTypes.get(simpleType);\r
- handleElementSimpleTypeAttributes(obj);\r
- }\r
+// if (simpleType != null) {\r
+// SchemaObject obj = simpleTypes.get(simpleType);\r
+// handleElementSimpleTypeAttributes(obj);\r
+// }\r
\r
\r
StringWriter stringWriter = new StringWriter();\r
fw.writer.println(" }");\r
\r
fw.writer.println(" @Override");\r
- fw.writer.println(" public boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException{");\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
\r
ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);\r
}\r
- \r
- private enum InheritanceType{ComplexType,AtomicType,None};\r
- \r
- private class Inheritance {\r
- public String baseClass;\r
- public InheritanceType type;\r
- public TypeEntry atomicType;\r
- \r
- public Inheritance() {\r
- baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
- type = InheritanceType.None;\r
- }\r
- }\r
- \r
- private Inheritance getElementInheritance(SchemaObject topLevelElementObj) {\r
- Element topLevelElement = topLevelElementObj.getElement();\r
- Inheritance inheritance = new Inheritance();\r
- if (topLevelElement.getType() != null) {\r
- QName type = topLevelElement.getType();\r
- if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
- SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
-// if (obj == null)\r
-// obj = simpleTypeName.get(type.getLocalPart());\r
- if (obj != null) {\r
- inheritance.baseClass = getName(obj);\r
- inheritance.type = InheritanceType.ComplexType;\r
- }\r
- } else {\r
- TypeEntry entry = getTypeEntry(type);\r
- if (entry != null) {\r
- inheritance.type = InheritanceType.AtomicType;\r
- inheritance.atomicType = entry;\r
- }\r
- }\r
- }\r
- if (inheritance.type == InheritanceType.None) {\r
- QName type = getElementBase(topLevelElement);\r
- if (type != null) {\r
- if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
- SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
- inheritance.baseClass = getName(obj);\r
- inheritance.type = InheritanceType.ComplexType;\r
- } else {\r
- TypeEntry entry = getTypeEntry(type);\r
- if (entry != null) {\r
- inheritance.type = InheritanceType.AtomicType;\r
- inheritance.atomicType = entry;\r
- }\r
- }\r
- }\r
- }\r
- if (inheritance.type == InheritanceType.None) {\r
- QName type = topLevelElement.getSubstitutionGroup();\r
- if (type != null) {\r
- if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
- SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
- inheritance.baseClass = getName(obj);\r
- inheritance.type = InheritanceType.ComplexType;\r
- } else {\r
- TypeEntry entry = getTypeEntry(type);\r
- if (entry != null) {\r
- inheritance.type = InheritanceType.AtomicType;\r
- inheritance.atomicType = entry;\r
- }\r
- }\r
- }\r
- }\r
- \r
- return inheritance;\r
- }\r
- \r
- private void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List<String> interfaces) {\r
- writer.println("@SuppressWarnings(\"unused\")");\r
- writer.print("public " +(abst ? "abstract " : "") + "class " + className + " extends "+baseClass);\r
- if (interfaces.size() > 0) {\r
- writer.print(" implements ");\r
- for (int i = 0; i < interfaces.size(); i++) {\r
- writer.print(interfaces.get(i));\r
- if (i < interfaces.size() -1 )\r
- writer.print(",");\r
- }\r
- }\r
- writer.println("{");\r
- writer.println();\r
- writer.println(" @Override");\r
- writer.println(" public java.lang.String getElementId() {");\r
- if (name != null)\r
- writer.println(" return \""+name+"\";");\r
- else // complex types cannot be parsed directly with name/id reference.\r
- writer.println(" return null;");\r
- writer.println(" }");\r
- writer.println();\r
- }\r
+\r
\r
private void writeIDProvider(PrintWriter writer) {\r
if (provider != null) {\r
private void writeIDReferences(PrintWriter writer,String name, List<IDReference> references) {\r
if (references.size() > 0) {\r
writer.println(" @Override");\r
- writer.println(" public boolean connectReferences(WriteGraph graph, Element element, java.util.Map<java.lang.String, Element> map) throws DatabaseException {");\r
+ writer.println(" public boolean connectReferences(WriteGraph graph, ParserElement element, java.util.Map<java.lang.String, ParserElement> map) throws DatabaseException {");\r
writer.println(" "+getOntologyImport());\r
writer.println(" boolean result = true;");\r
for (IDReference ref : references) {\r
writer.println(" {");\r
writer.println(" Attribute a = element.getAttribute(\"" + ref.getIDSource().getName() +"\");");\r
writer.println(" if (a != null) {");\r
- writer.println(" Element refEle = map.get(a.value);");\r
+ writer.println(" ParserElement refEle = map.get(a.value);");\r
writer.println(" if (refEle != null) {");\r
writer.println(" Resource ref = refEle.getData();");\r
writer.println(" graph.claim(element.getData(), "+ontShort+name+"_"+ref.getReference().getName()+", ref);");\r
return;\r
\r
writer.println(" @Override");\r
- writer.println(" public void configureChild(WriteGraph graph, Deque<Element> parents, Element element, Element child) throws DatabaseException {");\r
+ writer.println(" public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException {");\r
writer.println(" " + unknownChildElement.getJavaMethod());\r
writer.println(" }");\r
writer.println();\r
\r
}\r
\r
+ @Override\r
+ protected String getBaseClass() {\r
+ return "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
+ }\r
+ \r
protected void createClassHeader(PrintWriter writer, boolean isList) {\r
writer.println("package " + converter.getPluginName() +"."+elementPackageName+";");\r
writer.println();\r
writer.println("import org.simantics.db.WriteGraph;");\r
writer.println("import org.simantics.db.exception.DatabaseException;");\r
writer.println("import org.simantics.xml.sax.base.Attribute;");\r
- writer.println("import org.simantics.xml.sax.base.Element;");\r
+ writer.println("import org.simantics.xml.sax.base.ParserElement;");\r
writer.println("import org.simantics.xml.sax.ontology.XMLResource;");\r
if (!isList) {\r
writer.println("import org.simantics.layer0.Layer0;");\r
writer.println();\r
}\r
\r
- private String getOntologyImport() {\r
- return this.ontologyClassName+" " +ontShort.substring(0, 3)+" = "+this.ontologyClassName+".getInstance(graph);";\r
- }\r
- \r
- \r
- private static class FileWriter {\r
- public PrintWriter writer;\r
- \r
- public PrintWriter delayedWriter;\r
- public PrintWriter delayedWriter2;\r
- }\r
- \r
- public static String getName(SchemaObject obj) {\r
- if (obj.getParent() == null) {\r
- switch (obj.getType()) {\r
- case COMPLEX_TYPE:\r
- return getComplexTypePrefix()+obj.getName();\r
- case ELEMENT:\r
- return obj.getName();\r
- case ATTRIBUTE_GROUP:\r
- return getAttributeGroupPrefix()+obj.getName();\r
- case SIMPLE_TYPE:\r
- return obj.getName();\r
- }\r
- } else {\r
- SchemaObject o = obj;\r
- SchemaObject prev = null;\r
- String name = "";\r
- while (o != null){\r
- if (o.getName() != null)\r
- name = o.getName()+"_"+name;\r
- prev = o;\r
- o = o.getParent();\r
- if (prev.getObj() instanceof AttributeGroupRef)\r
- o = null;\r
- }\r
- name = name.substring(0, name.length()-1);\r
- switch (prev.getType()) {\r
- case COMPLEX_TYPE:\r
- return getComplexTypePrefix()+name;\r
- case ELEMENT:\r
- return name;\r
- case ATTRIBUTE_GROUP:\r
- return getAttributeGroupPrefix()+name;\r
- case SIMPLE_TYPE:\r
- return name;\r
- }\r
- }\r
- throw new RuntimeException();\r
- \r
- }\r
- \r
- public static String getName(SchemaObject obj, String rel) {\r
- if (obj.getParent() == null) {\r
- switch (obj.getType()) {\r
- case COMPLEX_TYPE:\r
- return getComplexTypePrefix()+rel+obj.getName();\r
- case ELEMENT:\r
- return rel+obj.getName();\r
- case ATTRIBUTE_GROUP:\r
- return getAttributeGroupPrefix()+rel+obj.getName();\r
- case SIMPLE_TYPE:\r
- return rel+obj.getName();\r
- }\r
- } else {\r
- SchemaObject o = obj;\r
- SchemaObject prev = null;\r
- String name = "";\r
- while (o != null){\r
- if (o.getName() != null)\r
- name = o.getName()+"_"+name;\r
- prev = o;\r
- o = o.getParent();\r
- }\r
- name = name.substring(0, name.length()-1);\r
- switch (prev.getType()) {\r
- case COMPLEX_TYPE:\r
- return getComplexTypePrefix()+rel+name;\r
- case ELEMENT:\r
- return rel+name;\r
- case ATTRIBUTE_GROUP:\r
- return getAttributeGroupPrefix()+rel+name;\r
- case SIMPLE_TYPE:\r
- return rel+name;\r
- }\r
- }\r
- throw new RuntimeException();\r
- \r
- }\r
}\r
--- /dev/null
+package org.simantics.xml.sax;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.xml.namespace.QName;\r
+\r
+import org.simantics.xml.sax.configuration.Configuration;\r
+import org.w3._2001.xmlschema.AttributeGroupRef;\r
+import org.w3._2001.xmlschema.Element;\r
+import org.w3._2001.xmlschema.Schema;\r
+\r
+public abstract class JavaGenerator extends SchemaConversionBase{\r
+\r
+ String commentTag = "//";\r
+ \r
+ Schema schema;\r
+ String ontologyClassName;\r
+ SchemaConverter converter;\r
+ \r
+ List<String> ruleClassNames = new ArrayList<String>();\r
+ \r
+ String ontShort = "ONT"; \r
+ \r
+ File importParserDir;\r
+ String elementPackageName;\r
+ \r
+ Map<SchemaObject, FileWriter> writers = new HashMap<SchemaObject, ImporterGenerator.FileWriter>();\r
+ \r
+ public JavaGenerator(Configuration configuration) {\r
+ super(configuration);\r
+ }\r
+ \r
+ \r
+ protected PrintWriter createFile(File file) throws IOException {\r
+ if (!file.exists())\r
+ file.createNewFile();\r
+ PrintWriter writer = new PrintWriter(file);\r
+ for (String s : converter.getHeader()) {\r
+ writer.println(commentTag + " " + s); \r
+ }\r
+ writer.println();\r
+ return writer;\r
+ }\r
+ \r
+ protected String getValueGetterMethod(TypeEntry binding,String name) {\r
+ if (binding == null)\r
+ return name+".getValue()";\r
+ return binding.getValueGetterMethod(name);\r
+ }\r
+ \r
+ protected String getValueGetter(TypeEntry binding,String name) {\r
+ if (binding == null)\r
+ return name;\r
+ return binding.getValueGetter(name);\r
+ }\r
+ protected String getValueGetter(TypeEntry binding) {\r
+ if (binding == null)\r
+ return "value";\r
+ return binding.getValueGetter();\r
+ }\r
+ \r
+ public static String getComplexTypePrefix() {\r
+ return "ComplexTypes_";\r
+ } \r
+ \r
+ public static String getAttributeGroupPrefix() {\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
+ \r
+ @Override\r
+ protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {\r
+ if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {\r
+ for (SchemaElement e : elements) {\r
+ handle(parent, indicator, e);\r
+ }\r
+ } else if (indicator.getType() == SchemaElement.ElementType.CHOICE) {\r
+ String name = getChoiceName(elements);\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
+ } else if (localElement.getRef() != null) {\r
+ QName refType = localElement.getRef();\r
+ handleIndicator(parent, indicator, e, true, name, refType);\r
+ }\r
+ }\r
+ }\r
+ \r
+ }\r
+ \r
+ protected String getOntologyImport() {\r
+ return this.ontologyClassName+" " +ontShort.substring(0, 3)+" = "+this.ontologyClassName+".getInstance(graph);";\r
+ }\r
+ \r
+ protected static class FileWriter {\r
+ public PrintWriter writer;\r
+ \r
+ public PrintWriter delayedWriter;\r
+ public PrintWriter delayedWriter2;\r
+ }\r
+ \r
+ protected FileWriter getWriter(SchemaObject obj) {\r
+ SchemaObject s = obj;\r
+ while (s != null) {\r
+ FileWriter fw = writers.get(s);\r
+ if (fw != null)\r
+ return fw;\r
+ s = s.getParent();\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ \r
+ public static String getName(SchemaObject obj) {\r
+ if (obj.getParent() == null) {\r
+ switch (obj.getType()) {\r
+ case COMPLEX_TYPE:\r
+ return getComplexTypePrefix()+obj.getName();\r
+ case ELEMENT:\r
+ return obj.getName();\r
+ case ATTRIBUTE_GROUP:\r
+ return getAttributeGroupPrefix()+obj.getName();\r
+ case SIMPLE_TYPE:\r
+ return obj.getName();\r
+ }\r
+ } else {\r
+ SchemaObject o = obj;\r
+ SchemaObject prev = null;\r
+ String name = "";\r
+ while (o != null){\r
+ if (o.getName() != null)\r
+ name = o.getName()+"_"+name;\r
+ prev = o;\r
+ o = o.getParent();\r
+ if (prev.getObj() instanceof AttributeGroupRef)\r
+ o = null;\r
+ }\r
+ name = name.substring(0, name.length()-1);\r
+ switch (prev.getType()) {\r
+ case COMPLEX_TYPE:\r
+ return getComplexTypePrefix()+name;\r
+ case ELEMENT:\r
+ return name;\r
+ case ATTRIBUTE_GROUP:\r
+ return getAttributeGroupPrefix()+name;\r
+ case SIMPLE_TYPE:\r
+ return name;\r
+ }\r
+ }\r
+ throw new RuntimeException();\r
+ \r
+ }\r
+ \r
+ public static String getName(SchemaObject obj, String rel) {\r
+ if (obj.getParent() == null) {\r
+ switch (obj.getType()) {\r
+ case COMPLEX_TYPE:\r
+ return getComplexTypePrefix()+rel+obj.getName();\r
+ case ELEMENT:\r
+ return rel+obj.getName();\r
+ case ATTRIBUTE_GROUP:\r
+ return getAttributeGroupPrefix()+rel+obj.getName();\r
+ case SIMPLE_TYPE:\r
+ return rel+obj.getName();\r
+ }\r
+ } else {\r
+ SchemaObject o = obj;\r
+ SchemaObject prev = null;\r
+ String name = "";\r
+ while (o != null){\r
+ if (o.getName() != null)\r
+ name = o.getName()+"_"+name;\r
+ prev = o;\r
+ o = o.getParent();\r
+ }\r
+ name = name.substring(0, name.length()-1);\r
+ switch (prev.getType()) {\r
+ case COMPLEX_TYPE:\r
+ return getComplexTypePrefix()+rel+name;\r
+ case ELEMENT:\r
+ return rel+name;\r
+ case ATTRIBUTE_GROUP:\r
+ return getAttributeGroupPrefix()+rel+name;\r
+ case SIMPLE_TYPE:\r
+ return rel+name;\r
+ }\r
+ }\r
+ throw new RuntimeException();\r
+ }\r
+ \r
+ protected enum InheritanceType{ComplexType,AtomicType,None};\r
+ \r
+ protected class Inheritance {\r
+ public String baseClass;\r
+ public InheritanceType type;\r
+ public TypeEntry atomicType;\r
+ \r
+ public Inheritance(String baseClass) {\r
+ this.baseClass = baseClass;\r
+ this.type = InheritanceType.None;\r
+ }\r
+ }\r
+ \r
+ protected void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List<String> interfaces) {\r
+ writer.println("@SuppressWarnings(\"unused\")");\r
+ writer.print("public " +(abst ? "abstract " : "") + "class " + className + " extends "+baseClass);\r
+ if (interfaces.size() > 0) {\r
+ writer.print(" implements ");\r
+ for (int i = 0; i < interfaces.size(); i++) {\r
+ writer.print(interfaces.get(i));\r
+ if (i < interfaces.size() -1 )\r
+ writer.print(",");\r
+ }\r
+ }\r
+ writer.println("{");\r
+ writer.println();\r
+ writer.println(" @Override");\r
+ writer.println(" public java.lang.String getElementId() {");\r
+ if (name != null)\r
+ writer.println(" return \""+name+"\";");\r
+ else // complex types cannot be parsed directly with name/id reference.\r
+ writer.println(" return null;");\r
+ writer.println(" }");\r
+ writer.println();\r
+ }\r
+ \r
+ protected abstract String getBaseClass();\r
+ \r
+ protected Inheritance getElementInheritance(SchemaObject topLevelElementObj) {\r
+ Element topLevelElement = topLevelElementObj.getElement();\r
+ Inheritance inheritance = new Inheritance(getBaseClass());\r
+ if (topLevelElement.getType() != null) {\r
+ QName type = topLevelElement.getType();\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+// if (obj == null)\r
+// obj = simpleTypeName.get(type.getLocalPart());\r
+ if (obj != null) {\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ }\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ if (inheritance.type == InheritanceType.None) {\r
+ QName type = getElementBase(topLevelElement);\r
+ if (type != null) {\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (inheritance.type == InheritanceType.None) {\r
+ QName type = topLevelElement.getSubstitutionGroup();\r
+ if (type != null) {\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ return inheritance;\r
+ } \r
+\r
+}\r
String commentTag = "//";\r
\r
Schema schema;\r
- \r
+ String ontologyName;\r
String className;\r
\r
SchemaConverter converter;\r
\r
PrintWriter writer = null;\r
\r
- public String getClassName() {\r
- return className;\r
- }\r
\r
- public void createOntology(Schema schema, SchemaConverter converter) throws FileNotFoundException {\r
+ \r
+ \r
+ \r
+ public void createOntology(Schema schema, String ontologyName, String className, SchemaConverter converter) throws FileNotFoundException {\r
this.schema = schema;\r
this.converter = converter;\r
+ this.ontologyName = ontologyName;\r
+ this.className = className;\r
\r
// for (OpenAttrs attrs : schema.getIncludeOrImportOrRedefine()) {\r
// if (attrs instanceof Annotation) {\r
}\r
\r
protected void handle(Schema schema) {\r
- String ontologyName = schema.getTargetNamespace();\r
- if (ontologyName == null) {\r
- ontologyName = converter.getSchemaFile().getName();\r
- \r
- int index = ontologyName.lastIndexOf(".");\r
- if (index > 0)\r
- ontologyName = ontologyName.substring(0, index);\r
- } \r
- if (!ontologyName.startsWith("http"))\r
- ontologyName = "http://" + ontologyName;\r
String parts[] = ontologyName.split("/");\r
String name = parts[parts.length-1];\r
ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase();\r
String version = schema.getVersion();\r
if (version == null)\r
version = "1.0";\r
- \r
- name = name.replaceAll("\\.", "_");\r
- name = name.replaceAll(" ", "_");\r
- className = converter.getPluginName() + "." + name;\r
+\r
\r
for (String s : converter.getHeader()) {\r
writer.println(commentTag + " " + s); \r
Element element = elementObj.getElement();\r
String name = getName(elementObj);//element.getName();\r
\r
-// if ("Presentation".equals(name))\r
-// System.out.println();\r
-\r
-// if (parent != null)\r
-// name = parent +"_"+name;\r
+ if ("Text".equals(name))\r
+ System.out.println();\r
\r
String type = "XML.Element";\r
Set<String> types = new LinkedHashSet<String>();\r
\r
import java.util.ArrayDeque;\r
import java.util.ArrayList;\r
-import java.util.Base64;\r
import java.util.Deque;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
import org.simantics.xml.sax.configuration.IDProvider;\r
import org.simantics.xml.sax.configuration.IDReference;\r
import org.simantics.xml.sax.configuration.OrderedChild;\r
+import org.simantics.xml.sax.configuration.Rename;\r
import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
import org.w3._2001.xmlschema.All;\r
import org.w3._2001.xmlschema.Annotated;\r
Map<String,TypeEntry> l0Types = new HashMap<String, SchemaConversionBase.TypeEntry>();\r
typeMap.put(CONVERSION_NS, l0Types);\r
\r
- schemaTypes.put("string", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
- schemaTypes.put("NMTOKEN", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
- schemaTypes.put("token", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
- schemaTypes.put("ID", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","",true));\r
- schemaTypes.put("IDREF", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
- schemaTypes.put("date", new TypeEntry("XML.Date", "org.simantics.xml.sax.base.datatypes.literal.Date.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Date", "","org.simantics.xml.sax.base.datatypes.literal.Date.parseDate(",")"));\r
- schemaTypes.put("time", new TypeEntry("XML.Time", "org.simantics.xml.sax.base.datatypes.literal.Time.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Time", "","org.simantics.xml.sax.base.datatypes.literal.Time.parseTime(",")"));\r
- schemaTypes.put("dateTime", new TypeEntry("XML.DateTime", "org.simantics.xml.sax.base.datatypes.literal.DateTime.BINDING", "org.simantics.xml.sax.base.datatypes.literal.DateTime", "","org.simantics.xml.sax.base.datatypes.literal.DateTime.parseDateTime(",")"));\r
- schemaTypes.put("anyURI", new TypeEntry("L0.URI", "Bindings.STRING", "java.lang.String", "","",""));\r
- schemaTypes.put("double", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")"));\r
- schemaTypes.put("float", new TypeEntry("L0.Float", "Bindings.FLOAT", "float", "java.lang.Float.NaN","java.lang.Float.parseFloat(",")"));\r
- schemaTypes.put("decimal", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")"));\r
- schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")"));\r
- schemaTypes.put("integer", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("int", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("short", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
- schemaTypes.put("byte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")"));\r
- schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")"));\r
- schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")"));\r
- schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")"));\r
- schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray", "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)"));\r
+ schemaTypes.put("string", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","","",""));\r
+ schemaTypes.put("NMTOKEN", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","","",""));\r
+ schemaTypes.put("token", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","","",""));\r
+ schemaTypes.put("ID", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","","","",true));\r
+ schemaTypes.put("IDREF", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","","",""));\r
+ schemaTypes.put("date", new TypeEntry("XML.Date", "org.simantics.xml.sax.base.datatypes.literal.Date.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Date", "","org.simantics.xml.sax.base.datatypes.literal.Date.parseDate(",")","(",").toString()"));\r
+ schemaTypes.put("time", new TypeEntry("XML.Time", "org.simantics.xml.sax.base.datatypes.literal.Time.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Time", "","org.simantics.xml.sax.base.datatypes.literal.Time.parseTime(",")","(",").toString()"));\r
+ schemaTypes.put("dateTime", new TypeEntry("XML.DateTime", "org.simantics.xml.sax.base.datatypes.literal.DateTime.BINDING", "org.simantics.xml.sax.base.datatypes.literal.DateTime", "","org.simantics.xml.sax.base.datatypes.literal.DateTime.parseDateTime(",")","(",").toString()"));\r
+ schemaTypes.put("anyURI", new TypeEntry("L0.URI", "Bindings.STRING", "java.lang.String", "","","","",""));\r
+ schemaTypes.put("double", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")","java.lang.Double.toString(",")"));\r
+ schemaTypes.put("float", new TypeEntry("L0.Float", "Bindings.FLOAT", "float", "java.lang.Float.NaN","java.lang.Float.parseFloat(",")","java.lang.Float.toString(",")"));\r
+ schemaTypes.put("decimal", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")","java.lang.Double.toString(",")"));\r
+ schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")","java.lang.Boolean.toString(",")"));\r
+ schemaTypes.put("integer", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("int", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("short", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+ schemaTypes.put("byte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));\r
+ schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));\r
+ schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));\r
+ schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));\r
+ 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)"));\r
\r
\r
\r
- l0Types.put("doubleArray", new TypeEntry("L0.DoubleArray", "Bindings.DOUBLE_ARRAY", "double[]", null,null,null));\r
- l0Types.put("stringArray", new TypeEntry("L0.StringArray", "Bindings.STRING_ARRAY", "string[]", null,null,null));\r
+ l0Types.put("doubleArray", new TypeEntry("L0.DoubleArray", "Bindings.DOUBLE_ARRAY", "double[]", null,null,null,"java.lang.Double.toString(",")"));\r
+ l0Types.put("stringArray", new TypeEntry("L0.StringArray", "Bindings.STRING_ARRAY", "string[]", null,null,null,"",""));\r
}\r
\r
\r
if (attrs instanceof Element) {\r
Element element = (Element)attrs;\r
SchemaObject obj = new SchemaObject(element);\r
+ obj.setRename(getRename(element));\r
stack.push(obj);\r
} else if (attrs instanceof ComplexType) {\r
ComplexType complexType = (ComplexType)attrs;\r
SchemaObject obj = new SchemaObject(complexType);\r
+ obj.setRename(getRename(complexType));\r
stack.push(obj);\r
} else if (attrs instanceof SimpleType) {\r
SimpleType simpleType = (SimpleType)attrs;\r
JAXBElement<?> element = (JAXBElement<?>)o;\r
Object elemValue = element.getValue();\r
if (elemValue instanceof Element) {\r
- stack.add(new SchemaObject(parent,(Element)elemValue));\r
+ SchemaObject obj = new SchemaObject(parent,(Element)elemValue);\r
+ obj.setRename(getRename((Element)elemValue));\r
+ stack.add(obj);\r
} else if (elemValue instanceof All) {\r
preload(parent,(All)elemValue, stack);\r
} else if (elemValue instanceof ExplicitGroup) {\r
Object elemValue = element.getValue();\r
if (elemValue instanceof LocalElement) {\r
LocalElement localElement = (LocalElement)elemValue;\r
- \r
elements.add(new SchemaElement(indicator,localElement, ElementType.ELEMENT));\r
} else if (elemValue instanceof All) {\r
alls.add(new SchemaElement(indicator,(All)elemValue, ElementType.ALL));\r
protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {\r
Element localElement = element.getElement();\r
if (localElement.getName() != null) {\r
- String refName = localElement.getName();\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
QName refType = localElement.getType();\r
if (refType != null)\r
handleIndicator(parent, indicator, element, false, refName, refType);\r
else {\r
- handleElement(elements.get(localElement));\r
+ handleElement(eObj);\r
handleIndicator(parent, indicator, element, false, refName, localElement);\r
- //FIXME:\r
}\r
} else if (localElement.getRef() != null) {\r
QName refType = localElement.getRef();\r
public UnrecognizedChildElement getUnknown(ComplexType complexType) {\r
for (JAXBElement<?> e : configuration.getConversionRule()) {\r
if (e.getValue() instanceof UnrecognizedChildElement) {\r
- UnrecognizedChildElement ref = (UnrecognizedChildElement)e.getValue();\r
- org.simantics.xml.sax.configuration.ComplexType complexType2 = ref.getComplexType();\r
+ UnrecognizedChildElement rule = (UnrecognizedChildElement)e.getValue();\r
+ org.simantics.xml.sax.configuration.ComplexType complexType2 = rule.getComplexType();\r
if (complexType2 != null) {\r
if (complexType.getName().equals(complexType2.getName()))\r
- return ref;\r
+ return rule;\r
}\r
}\r
}\r
public UnrecognizedChildElement getUnknown(Element element) {\r
for (JAXBElement<?> e : configuration.getConversionRule()) {\r
if (e.getValue() instanceof UnrecognizedChildElement) {\r
- UnrecognizedChildElement ref = (UnrecognizedChildElement)e.getValue();\r
- org.simantics.xml.sax.configuration.Element element2 = ref.getElement();\r
+ UnrecognizedChildElement rule = (UnrecognizedChildElement)e.getValue();\r
+ org.simantics.xml.sax.configuration.Element element2 = rule.getElement();\r
if (element2 != null) {\r
if (element.getName().equals(element2.getName()))\r
- return ref;\r
+ return rule;\r
}\r
}\r
}\r
return null;\r
}\r
\r
+ public Rename getRename(Attribute element) {\r
+ for (JAXBElement<?> e : configuration.getConversionRule()) {\r
+ if (e.getValue() instanceof Rename) {\r
+ Rename rule = (Rename)e.getValue();\r
+ Object ref = rule.getElementOrComplexTypeOrAttribute().get(0);\r
+ if (!(ref instanceof org.simantics.xml.sax.configuration.Attribute))\r
+ continue;\r
+ org.simantics.xml.sax.configuration.Attribute element2 = (org.simantics.xml.sax.configuration.Attribute)ref;\r
+ if (element2.getName().equals(element.getName())) {\r
+ return rule;\r
+ }\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ public Rename getRename(ComplexType element) {\r
+ for (JAXBElement<?> e : configuration.getConversionRule()) {\r
+ if (e.getValue() instanceof Rename) {\r
+ Rename rule = (Rename)e.getValue();\r
+ Object ref = rule.getElementOrComplexTypeOrAttribute().get(0);\r
+ if (!(ref instanceof org.simantics.xml.sax.configuration.ComplexType))\r
+ continue;\r
+ org.simantics.xml.sax.configuration.ComplexType element2 = (org.simantics.xml.sax.configuration.ComplexType)ref;\r
+ if (element2.getName().equals(element.getName())) {\r
+ return rule;\r
+ }\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ public Rename getRename(Element element) {\r
+ for (JAXBElement<?> e : configuration.getConversionRule()) {\r
+ if (e.getValue() instanceof Rename) {\r
+ Rename rule = (Rename)e.getValue();\r
+ Object ref = rule.getElementOrComplexTypeOrAttribute().get(0);\r
+ if (!(ref instanceof org.simantics.xml.sax.configuration.Element))\r
+ continue;\r
+ org.simantics.xml.sax.configuration.Element element2 = (org.simantics.xml.sax.configuration.Element)ref;\r
+ if (element2.getName().equals(element.getName())) {\r
+ return rule;\r
+ }\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ \r
\r
public boolean useOriginalList(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String ref, QName refType) {\r
if (parent.getName() == null)\r
boolean id;\r
String getterPrefix;\r
String getterPostfix;\r
- public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix) {\r
+ String stringPrefix;\r
+ String stringPostfix;\r
+ public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, String stringPrefix, String stringPostfix) {\r
super();\r
this.l0Type = l0Type;\r
this.binding = binding;\r
this.id = false;\r
this.getterPrefix = getterPrefix;\r
this.getterPostfix = getterPostfix;\r
- \r
+ this.stringPrefix = stringPrefix;\r
+ this.stringPostfix = stringPostfix;\r
}\r
\r
- public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, boolean id) {\r
+ public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, String stringPrefix, String stringPostfix, boolean id) {\r
super();\r
this.l0Type = l0Type;\r
this.binding = binding;\r
this.id = id;\r
this.getterPrefix = getterPrefix;\r
this.getterPostfix = getterPostfix;\r
+ this.stringPrefix = stringPrefix;\r
+ this.stringPostfix = stringPostfix;\r
}\r
\r
public String getValueGetterMethod(String name) {\r
return getValueGetter("value");\r
}\r
\r
+ public String getToString(String name) {\r
+ return stringPrefix +"("+javaType+")"+name+stringPostfix;\r
+ }\r
+ \r
+ public String getElementToString(String name) {\r
+ return stringPrefix + name+stringPostfix;\r
+ }\r
+ \r
}\r
\r
}\r
\r
private String[] header;\r
\r
+ boolean createPGraph = true;\r
+ boolean createImporter = true;\r
+ boolean createExporter = true;\r
+ \r
+ \r
+ \r
\r
public void convertSchema(File schemaFile, File conversionFile, File outputPlugin) throws JAXBException, IOException {\r
pluginName = outputPlugin.getName();\r
\r
}\r
\r
+ public void setCreateExporter(boolean createExporter) {\r
+ this.createExporter = createExporter;\r
+ }\r
+ \r
+ public void setCreateImporter(boolean createImporter) {\r
+ this.createImporter = createImporter;\r
+ }\r
+ \r
+ public void setCreatePGraph(boolean createPGraph) {\r
+ this.createPGraph = createPGraph;\r
+ }\r
+ \r
private void convert() throws JAXBException, IOException {\r
JAXBContext jc = JAXBContext.newInstance("org.w3._2001.xmlschema");\r
Unmarshaller u = jc.createUnmarshaller();\r
header[3] = "Date " + new Date().toString();\r
\r
\r
+ String ontologyName = schema.getTargetNamespace();\r
+ if (ontologyName == null) {\r
+ ontologyName = getSchemaFile().getName();\r
+ \r
+ int index = ontologyName.lastIndexOf(".");\r
+ if (index > 0)\r
+ ontologyName = ontologyName.substring(0, index);\r
+ } \r
+ if (!ontologyName.startsWith("http"))\r
+ ontologyName = "http://" + ontologyName;\r
+ String parts[] = ontologyName.split("/");\r
+ String name = parts[parts.length-1];\r
+ //String ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase();\r
+\r
+ \r
+ name = name.replaceAll("\\.", "_");\r
+ name = name.replaceAll(" ", "_");\r
+ String className = getPluginName() + "." + name;\r
+ \r
+ if (createPGraph) {\r
OntologyGenerator ontologyGenerator = new OntologyGenerator(configuration);\r
- ontologyGenerator.createOntology(schema, this);\r
+ ontologyGenerator.createOntology(schema, ontologyName, className, this);\r
+ }\r
+ if (createImporter) {\r
ImporterGenerator importerGenerator = new ImporterGenerator(configuration);\r
- importerGenerator.createParser(schema, ontologyGenerator.getClassName(), this);\r
+ importerGenerator.createParser(schema, className, this);\r
+ }\r
+ if (createExporter) {\r
+ ExporterGenerator exporterGenerator = new ExporterGenerator(configuration);\r
+ exporterGenerator.createParser(schema, className, this);\r
+ }\r
}\r
\r
public File getOntologyFile() {\r
package org.simantics.xml.sax;\r
\r
+import org.simantics.xml.sax.configuration.Rename;\r
import org.w3._2001.xmlschema.AttributeGroup;\r
import org.w3._2001.xmlschema.AttributeGroupRef;\r
import org.w3._2001.xmlschema.ComplexType;\r
private SchemaObject parent;\r
private ObjectType type;\r
private OpenAttrs obj;\r
+ private Rename rename;\r
\r
public SchemaObject(Element element) {\r
this(null,element);\r
}\r
\r
+ public void setRename(Rename rename) {\r
+ this.rename = rename;\r
+ }\r
+ \r
public SchemaObject(ComplexType complexType) {\r
this(null, complexType);\r
}\r
else\r
return ((AttributeGroupRef)obj).getRef().getLocalPart();\r
case COMPLEX_TYPE:\r
+ if (rename != null)\r
+ return rename.getName();\r
return ((ComplexType)obj).getName();\r
case ELEMENT:\r
+ if (rename != null)\r
+ return rename.getName();\r
return ((Element)obj).getName();\r
case SIMPLE_TYPE:\r
return ((SimpleType)obj).getName();\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
* <p>\r
* Objects of the following type(s) are allowed in the list\r
* {@link JAXBElement }{@code <}{@link OrderedChild }{@code >}\r
- * {@link JAXBElement }{@code <}{@link IDReference }{@code >}\r
- * {@link JAXBElement }{@code <}{@link AttributeComposition }{@code >}\r
- * {@link JAXBElement }{@code <}{@link UnrecognizedChildElement }{@code >}\r
* {@link JAXBElement }{@code <}{@link ConversionRule }{@code >}\r
+ * {@link JAXBElement }{@code <}{@link AttributeComposition }{@code >}\r
+ * {@link JAXBElement }{@code <}{@link Rename }{@code >}\r
* {@link JAXBElement }{@code <}{@link IDProvider }{@code >}\r
+ * {@link JAXBElement }{@code <}{@link IDReference }{@code >}\r
+ * {@link JAXBElement }{@code <}{@link UnrecognizedChildElement }{@code >}\r
* \r
* \r
*/\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
UnrecognizedChildElement.class,\r
OrderedChild.class,\r
AttributeComposition.class,\r
- IDReference.class\r
+ IDReference.class,\r
+ Rename.class\r
})\r
public class ConversionRule {\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
public class ObjectFactory {\r
\r
private final static QName _ComplexType_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "ComplexType");\r
+ private final static QName _Rename_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "Rename");\r
private final static QName _IDProvider_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "IDProvider");\r
private final static QName _ConversionRule_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "ConversionRule");\r
private final static QName _Attribute_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "Attribute");\r
return new ComplexType();\r
}\r
\r
+ /**\r
+ * Create an instance of {@link Rename }\r
+ * \r
+ */\r
+ public Rename createRename() {\r
+ return new Rename();\r
+ }\r
+\r
/**\r
* Create an instance of {@link JAXBElement }{@code <}{@link ComplexType }{@code >}}\r
* \r
return new JAXBElement<ComplexType>(_ComplexType_QNAME, ComplexType.class, null, value);\r
}\r
\r
+ /**\r
+ * Create an instance of {@link JAXBElement }{@code <}{@link Rename }{@code >}}\r
+ * \r
+ */\r
+ @XmlElementDecl(namespace = "http://www.simantics.org/xml/sax/configuration/", name = "Rename", substitutionHeadNamespace = "http://www.simantics.org/xml/sax/configuration/", substitutionHeadName = "ConversionRule")\r
+ public JAXBElement<Rename> createRename(Rename value) {\r
+ return new JAXBElement<Rename>(_Rename_QNAME, Rename.class, null, value);\r
+ }\r
+\r
/**\r
* Create an instance of {@link JAXBElement }{@code <}{@link IDProvider }{@code >}}\r
* \r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
--- /dev/null
+//\r
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
+// Any modifications to this file will be lost upon recompilation of the source schema. \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
+//\r
+\r
+\r
+package org.simantics.xml.sax.configuration;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlAttribute;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlElements;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+\r
+/**\r
+ * <p>Java class for anonymous complex type.\r
+ * \r
+ * <p>The following schema fragment specifies the expected content contained within this class.\r
+ * \r
+ * <pre>\r
+ * <complexType>\r
+ * <complexContent>\r
+ * <extension base="{http://www.simantics.org/xml/sax/configuration/}ConversionRule">\r
+ * <sequence maxOccurs="unbounded">\r
+ * <choice>\r
+ * <element ref="{http://www.simantics.org/xml/sax/configuration/}Element"/>\r
+ * <element ref="{http://www.simantics.org/xml/sax/configuration/}ComplexType"/>\r
+ * <element ref="{http://www.simantics.org/xml/sax/configuration/}Attribute"/>\r
+ * </choice>\r
+ * </sequence>\r
+ * <attribute name="Name" type="{http://www.w3.org/2001/XMLSchema}string" />\r
+ * </extension>\r
+ * </complexContent>\r
+ * </complexType>\r
+ * </pre>\r
+ * \r
+ * \r
+ */\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "", propOrder = {\r
+ "elementOrComplexTypeOrAttribute"\r
+})\r
+public class Rename\r
+ extends ConversionRule\r
+{\r
+\r
+ @XmlElements({\r
+ @XmlElement(name = "Element", type = Element.class),\r
+ @XmlElement(name = "ComplexType", type = ComplexType.class),\r
+ @XmlElement(name = "Attribute", type = Attribute.class)\r
+ })\r
+ protected List<Object> elementOrComplexTypeOrAttribute;\r
+ @XmlAttribute(name = "Name")\r
+ protected String name;\r
+\r
+ /**\r
+ * Gets the value of the elementOrComplexTypeOrAttribute property.\r
+ * \r
+ * <p>\r
+ * This accessor method returns a reference to the live list,\r
+ * not a snapshot. Therefore any modification you make to the\r
+ * returned list will be present inside the JAXB object.\r
+ * This is why there is not a <CODE>set</CODE> method for the elementOrComplexTypeOrAttribute property.\r
+ * \r
+ * <p>\r
+ * For example, to add a new item, do as follows:\r
+ * <pre>\r
+ * getElementOrComplexTypeOrAttribute().add(newItem);\r
+ * </pre>\r
+ * \r
+ * \r
+ * <p>\r
+ * Objects of the following type(s) are allowed in the list\r
+ * {@link Element }\r
+ * {@link ComplexType }\r
+ * {@link Attribute }\r
+ * \r
+ * \r
+ */\r
+ public List<Object> getElementOrComplexTypeOrAttribute() {\r
+ if (elementOrComplexTypeOrAttribute == null) {\r
+ elementOrComplexTypeOrAttribute = new ArrayList<Object>();\r
+ }\r
+ return this.elementOrComplexTypeOrAttribute;\r
+ }\r
+\r
+ /**\r
+ * Gets the value of the name property.\r
+ * \r
+ * @return\r
+ * possible object is\r
+ * {@link String }\r
+ * \r
+ */\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ /**\r
+ * Sets the value of the name property.\r
+ * \r
+ * @param value\r
+ * allowed object is\r
+ * {@link String }\r
+ * \r
+ */\r
+ public void setName(String value) {\r
+ this.name = value;\r
+ }\r
+\r
+}\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
\r
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
// Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
//\r
\r
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.simantics.org/xml/sax/configuration/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)\r