X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax.base%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2Fbase%2FParserElement.java;h=2ab58f773ae54d2d154b944bc3d0f89e8926ff17;hb=refs%2Fheads%2Frelease%2F1.32.1;hp=e3298e3677c8c54916bf4d80cb030f447ea29cac;hpb=dd3b2c7ecd5f4b60734f2602b16637aa8be2a263;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java index e3298e3..2ab58f7 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java @@ -1,11 +1,18 @@ package org.simantics.xml.sax.base; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.MapList; import org.xml.sax.Attributes; public class ParserElement implements Serializable { @@ -13,16 +20,19 @@ public class ParserElement implements Serializable { String uri; String localName; String qName; - Map attributes = new HashMap(); - + Map attributes; + MapList lists; + XMLElementParser elementParser; XMLParser xmlParser; - + public ParserElement(String uri, String localName, String qName, Attributes attributes) { this.uri = uri; this.localName = localName; this.qName = qName; - for (int i = 0; i < attributes.getLength(); i++) { + int attrCount = attributes.getLength(); + this.attributes = new HashMap<>(attrCount); + for (int i = 0; i < attrCount; i++) { this.attributes.put(attributes.getLocalName(i),new Attribute(attributes.getLocalName(i),attributes.getQName(i),attributes.getURI(i),attributes.getValue(i))); } } @@ -31,6 +41,7 @@ public class ParserElement implements Serializable { this.uri = uri; this.localName = localName; this.qName = qName; + this.attributes = new HashMap<>(attributes.size()); for (Attribute a : attributes) { this.attributes.put(a.localName,new Attribute(a.localName,a.qName,a.uri,a.value)); } @@ -82,4 +93,23 @@ public class ParserElement implements Serializable { return xmlParser; } + public void registerListChild(Resource predicate, ParserElement child) { + if (lists == null) + lists = new MapList<>(); + lists.add(predicate, child); + } + + public void createLists(WriteGraph graph) throws DatabaseException { + if (lists == null) + return; + Layer0 L0 = Layer0.getInstance(graph); + for (Resource predicate : lists.getKeys()) { + List children = new ArrayList<>(); + for (ParserElement child : lists.getValues(predicate)) + children.add(child.getData()); + Resource list = ListUtils.create(graph, L0.List, L0.List_Element, null, children); + graph.claim(getData(), predicate, list); + } + } + } \ No newline at end of file