changeset 32:9c54842f5e86

better names for XML importer sub-classes.
author casties
date Thu, 25 Aug 2016 11:29:47 +0200
parents 7d8ebe8ac8a2
children e52f593f9e0d
files src/main/java/org/mpi/openmind/repository/utils/OM4XmlEventReader.java src/main/java/org/mpi/openmind/scripts/CheckXmlExport.java
diffstat 2 files changed, 39 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/repository/utils/OM4XmlEventReader.java	Wed Aug 24 19:12:24 2016 +0200
+++ b/src/main/java/org/mpi/openmind/repository/utils/OM4XmlEventReader.java	Thu Aug 25 11:29:47 2016 +0200
@@ -30,8 +30,10 @@
  * The read() method reads the contents of the file into the members
  * .entities and .relations.
  * 
- * The contents are Lists of OmEntities and OmRelations also holding
- * Lists of omAttributes. 
+ * The contents are Lists of OmXmlEntities and OmXmlRelations holding
+ * Lists of omXmlAttributes.
+ * 
+ * This implementation uses XMLEventReader.
  * 
  * @author casties
  *
@@ -48,11 +50,11 @@
     InputStream xmlStream;
     
     public int numEntities;
-    public List<OmEntity> entities;
+    public List<OmXmlEntity> entities;
     private int entCnt = 0;
 
     public int numRelations;
-    public List<OmRelation> relations;
+    public List<OmXmlRelation> relations;
     private int relCnt = 0;
 
     /**
@@ -60,7 +62,7 @@
      *  
      * @author casties
      */
-    public class OmAttribute {
+    public class OmXmlAttribute {
         public Map<String, String> xmlAtts;
         public String value;
         
@@ -74,10 +76,10 @@
      *  
      * @author casties
      */
-    public class OmEntity {
+    public class OmXmlEntity {
         public Map<String, String> xmlAtts;
         public String value;
-        public List<OmAttribute> attributes;
+        public List<OmXmlAttribute> attributes;
 
         public String getId() {
             return xmlAtts.get("id");
@@ -89,10 +91,10 @@
      *  
      * @author casties
      */
-    public class OmRelation {
+    public class OmXmlRelation {
         public Map<String, String> xmlAtts;
         public String value;
-        public List<OmAttribute> attributes;
+        public List<OmXmlAttribute> attributes;
 
         public String getId() {
             return xmlAtts.get("id");
@@ -135,7 +137,7 @@
      * @return
      * @throws XMLStreamException
      */
-    private List<OmEntity> processEntities(StartElement elem, XMLEventReader reader) throws XMLStreamException {
+    private List<OmXmlEntity> processEntities(StartElement elem, XMLEventReader reader) throws XMLStreamException {
         logger.debug("loading entities...");
         // get number attribute
         Attribute numa = elem.getAttributeByName(new QName("number"));
@@ -143,7 +145,7 @@
             numEntities = Integer.parseInt(numa.getValue());
         }
         // start reading sub-elements
-        List<OmEntity> entities = new ArrayList<OmEntity>();
+        List<OmXmlEntity> entities = new ArrayList<OmXmlEntity>();
         while (reader.hasNext()) {
             XMLEvent e = reader.nextEvent();
             if (e.isStartElement()) {
@@ -175,9 +177,9 @@
      * @return
      * @throws XMLStreamException
      */
-    private OmEntity processEntity(StartElement elem, XMLEventReader reader) throws XMLStreamException {
+    private OmXmlEntity processEntity(StartElement elem, XMLEventReader reader) throws XMLStreamException {
         //logger.debug("entity");
-        OmEntity ent = new OmEntity();
+        OmXmlEntity ent = new OmXmlEntity();
         Map<String, String> xmlAtts = new HashMap<String, String>();
         @SuppressWarnings("unchecked")
         Iterator<Attribute> atts = elem.getAttributes();
@@ -187,7 +189,7 @@
         }
         ent.xmlAtts = xmlAtts;
         // start reading sub-elements
-        ent.attributes = new ArrayList<OmAttribute>();
+        ent.attributes = new ArrayList<OmXmlAttribute>();
         while (reader.hasNext()) {
             XMLEvent e = reader.nextEvent();
             if (e.isStartElement()) {
@@ -232,7 +234,7 @@
      * @return
      * @throws XMLStreamException
      */
-    private List<OmRelation> processRelations(StartElement elem, XMLEventReader reader) throws XMLStreamException {
+    private List<OmXmlRelation> processRelations(StartElement elem, XMLEventReader reader) throws XMLStreamException {
         logger.debug("loading relations...");
         // get number attribute
         Attribute numa = elem.getAttributeByName(new QName("number"));
@@ -240,7 +242,7 @@
             numRelations = Integer.parseInt(numa.getValue());
         }
         // start reading sub-elements
-        List<OmRelation> rels = new ArrayList<OmRelation>();
+        List<OmXmlRelation> rels = new ArrayList<OmXmlRelation>();
         while (reader.hasNext()) {
             XMLEvent e = reader.nextEvent();
             if (e.isStartElement()) {
@@ -273,9 +275,9 @@
      * @return
      * @throws XMLStreamException
      */
-    private OmRelation processRelation(StartElement elem, XMLEventReader reader) throws XMLStreamException {
+    private OmXmlRelation processRelation(StartElement elem, XMLEventReader reader) throws XMLStreamException {
         //logger.debug("relation");
-        OmRelation rel = new OmRelation();
+        OmXmlRelation rel = new OmXmlRelation();
         Map<String, String> xmlAtts = new HashMap<String, String>();
         @SuppressWarnings("unchecked")
         Iterator<Attribute> atts = elem.getAttributes();
@@ -285,7 +287,7 @@
         }
         rel.xmlAtts = xmlAtts;
         // start reading sub-elements
-        rel.attributes = new ArrayList<OmAttribute>();
+        rel.attributes = new ArrayList<OmXmlAttribute>();
         while (reader.hasNext()) {
             XMLEvent e = reader.nextEvent();
             if (e.isStartElement()) {
@@ -330,9 +332,9 @@
      * @return
      * @throws XMLStreamException
      */
-    private OmAttribute processAttribute(StartElement elem, XMLEventReader reader) throws XMLStreamException {
+    private OmXmlAttribute processAttribute(StartElement elem, XMLEventReader reader) throws XMLStreamException {
         //logger.debug("attribute");
-        OmAttribute oma = new OmAttribute();
+        OmXmlAttribute oma = new OmXmlAttribute();
         Map<String, String> xmlAtts = new HashMap<String, String>();
         @SuppressWarnings("unchecked")
         Iterator<Attribute> atts = elem.getAttributes();
--- a/src/main/java/org/mpi/openmind/scripts/CheckXmlExport.java	Wed Aug 24 19:12:24 2016 +0200
+++ b/src/main/java/org/mpi/openmind/scripts/CheckXmlExport.java	Thu Aug 25 11:29:47 2016 +0200
@@ -21,9 +21,9 @@
 import org.mpi.openmind.repository.services.PersistenceService;
 import org.mpi.openmind.repository.services.ServiceRegistry;
 import org.mpi.openmind.repository.utils.OM4XmlEventReader;
-import org.mpi.openmind.repository.utils.OM4XmlEventReader.OmAttribute;
-import org.mpi.openmind.repository.utils.OM4XmlEventReader.OmEntity;
-import org.mpi.openmind.repository.utils.OM4XmlEventReader.OmRelation;
+import org.mpi.openmind.repository.utils.OM4XmlEventReader.OmXmlAttribute;
+import org.mpi.openmind.repository.utils.OM4XmlEventReader.OmXmlEntity;
+import org.mpi.openmind.repository.utils.OM4XmlEventReader.OmXmlRelation;
 
 
 /**
@@ -98,18 +98,18 @@
          * create hashes by id as indices
          */
         logger.info("indexing entities...");
-        List<OmEntity> xmlEntList = xmlReader.entities;
-        List<OmRelation> xmlRelList = xmlReader.relations;
-        Map<Long, OmEntity> xmlEntMap = new HashMap<Long, OmEntity>(xmlEntList.size());
-        for (OmEntity e : xmlEntList) {
+        List<OmXmlEntity> xmlEntList = xmlReader.entities;
+        List<OmXmlRelation> xmlRelList = xmlReader.relations;
+        Map<Long, OmXmlEntity> xmlEntMap = new HashMap<Long, OmXmlEntity>(xmlEntList.size());
+        for (OmXmlEntity e : xmlEntList) {
             Long id = Long.parseLong(e.getId());
             if (xmlEntMap.put(id, e) != null) {
                 logger.error("XML entity with duplicate id: "+id);
             }
         }
         logger.info("indexing relations...");
-        Map<Long,OmRelation> xmlRelMap = new HashMap<Long, OmRelation>(xmlRelList.size());
-        for (OmRelation e : xmlRelList) {
+        Map<Long,OmXmlRelation> xmlRelMap = new HashMap<Long, OmXmlRelation>(xmlRelList.size());
+        for (OmXmlRelation e : xmlRelList) {
             Long id = Long.parseLong(e.getId());
             if (xmlRelMap.put(id, e) != null) {
                 logger.error("XML relation with duplicate id: "+id);                
@@ -143,7 +143,7 @@
                 
                 // get xml entity
                 Long id = ent.getId();
-                OmEntity xmlEnt = xmlEntMap.get(id);
+                OmXmlEntity xmlEnt = xmlEntMap.get(id);
                 if (xmlEnt == null) {
                     logger.error("OM entity not found in XML: "+id);
                     entErrCnt += 1;
@@ -165,7 +165,7 @@
         for (Relation rel : relations) {
             // get xml entity
             Long id = rel.getId();
-            OmRelation xmlRel = xmlRelMap.get(id);
+            OmXmlRelation xmlRel = xmlRelMap.get(id);
             if (xmlRel == null) {
                 logger.error("OM relation not found in XML: "+id);
                 relErrCnt += 1;
@@ -194,7 +194,7 @@
 	 * @param xmlEnt
 	 * @return
 	 */
-	private static boolean entEquals(Entity entity, OmEntity xmlEnt) {
+	private static boolean entEquals(Entity entity, OmXmlEntity xmlEnt) {
         /*
          * check XML attributes
          */
@@ -255,7 +255,7 @@
      * @param xmlRel
      * @return
      */
-    private static boolean relEquals(Relation relation, OmRelation xmlRel) {
+    private static boolean relEquals(Relation relation, OmXmlRelation xmlRel) {
         /*
          * check XML attributes
          */
@@ -324,11 +324,11 @@
      * @param xmlAtts
      * @return
      */
-    private static boolean attsEquals(List<Attribute> atts, List<OmAttribute> xmlAtts) {
+    private static boolean attsEquals(List<Attribute> atts, List<OmXmlAttribute> xmlAtts) {
         for (Attribute att : atts) {
             // get the matching attribute from the XML file
-            OmAttribute xmlAtt = null;
-            for (OmAttribute xa : xmlAtts) {
+            OmXmlAttribute xmlAtt = null;
+            for (OmXmlAttribute xa : xmlAtts) {
                 if (equalsString(att.getId(), xa.getId())) {
                     xmlAtt = xa;
                     break;