package org.simantics.xml.sax.base;\r
\r
import java.io.Serializable;\r
+import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
\r
import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.utils.datastructures.MapList;\r
import org.xml.sax.Attributes;\r
\r
public class ParserElement implements Serializable {\r
String uri;\r
String localName;\r
String qName;\r
- Map<String,Attribute> attributes = new HashMap<String, Attribute>();\r
- \r
+ Map<String, Attribute> attributes;\r
+ MapList<Resource, ParserElement> lists;\r
+\r
XMLElementParser elementParser;\r
XMLParser xmlParser;\r
- \r
+\r
public ParserElement(String uri, String localName, String qName, Attributes attributes) {\r
this.uri = uri;\r
this.localName = localName;\r
this.qName = qName;\r
- for (int i = 0; i < attributes.getLength(); i++) {\r
+ int attrCount = attributes.getLength();\r
+ this.attributes = new HashMap<>(attrCount);\r
+ for (int i = 0; i < attrCount; i++) {\r
this.attributes.put(attributes.getLocalName(i),new Attribute(attributes.getLocalName(i),attributes.getQName(i),attributes.getURI(i),attributes.getValue(i)));\r
}\r
}\r
this.uri = uri;\r
this.localName = localName;\r
this.qName = qName;\r
+ this.attributes = new HashMap<>(attributes.size());\r
for (Attribute a : attributes) {\r
this.attributes.put(a.localName,new Attribute(a.localName,a.qName,a.uri,a.value));\r
}\r
return xmlParser;\r
}\r
\r
+ public void registerListChild(Resource predicate, ParserElement child) {\r
+ if (lists == null)\r
+ lists = new MapList<>();\r
+ lists.add(predicate, child);\r
+ }\r
+\r
+ public void createLists(WriteGraph graph) throws DatabaseException {\r
+ if (lists == null)\r
+ return;\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ for (Resource predicate : lists.getKeys()) {\r
+ List<Resource> children = new ArrayList<>();\r
+ for (ParserElement child : lists.getValues(predicate))\r
+ children.add(child.getData());\r
+ Resource list = ListUtils.create(graph, L0.List, L0.List_Element, null, children);\r
+ graph.claim(getData(), predicate, list);\r
+ }\r
+ }\r
+\r
}
\ No newline at end of file