# HG changeset patch # User casties # Date 1472117387 -7200 # Node ID 9c54842f5e8658244c149e455c21642fda1f2a98 # Parent 7d8ebe8ac8a2c7f91006d12a2adcfbe924884012 better names for XML importer sub-classes. diff -r 7d8ebe8ac8a2 -r 9c54842f5e86 src/main/java/org/mpi/openmind/repository/utils/OM4XmlEventReader.java --- 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 entities; + public List entities; private int entCnt = 0; public int numRelations; - public List relations; + public List relations; private int relCnt = 0; /** @@ -60,7 +62,7 @@ * * @author casties */ - public class OmAttribute { + public class OmXmlAttribute { public Map xmlAtts; public String value; @@ -74,10 +76,10 @@ * * @author casties */ - public class OmEntity { + public class OmXmlEntity { public Map xmlAtts; public String value; - public List attributes; + public List attributes; public String getId() { return xmlAtts.get("id"); @@ -89,10 +91,10 @@ * * @author casties */ - public class OmRelation { + public class OmXmlRelation { public Map xmlAtts; public String value; - public List attributes; + public List attributes; public String getId() { return xmlAtts.get("id"); @@ -135,7 +137,7 @@ * @return * @throws XMLStreamException */ - private List processEntities(StartElement elem, XMLEventReader reader) throws XMLStreamException { + private List 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 entities = new ArrayList(); + List entities = new ArrayList(); 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 xmlAtts = new HashMap(); @SuppressWarnings("unchecked") Iterator atts = elem.getAttributes(); @@ -187,7 +189,7 @@ } ent.xmlAtts = xmlAtts; // start reading sub-elements - ent.attributes = new ArrayList(); + ent.attributes = new ArrayList(); while (reader.hasNext()) { XMLEvent e = reader.nextEvent(); if (e.isStartElement()) { @@ -232,7 +234,7 @@ * @return * @throws XMLStreamException */ - private List processRelations(StartElement elem, XMLEventReader reader) throws XMLStreamException { + private List 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 rels = new ArrayList(); + List rels = new ArrayList(); 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 xmlAtts = new HashMap(); @SuppressWarnings("unchecked") Iterator atts = elem.getAttributes(); @@ -285,7 +287,7 @@ } rel.xmlAtts = xmlAtts; // start reading sub-elements - rel.attributes = new ArrayList(); + rel.attributes = new ArrayList(); 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 xmlAtts = new HashMap(); @SuppressWarnings("unchecked") Iterator atts = elem.getAttributes(); diff -r 7d8ebe8ac8a2 -r 9c54842f5e86 src/main/java/org/mpi/openmind/scripts/CheckXmlExport.java --- 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 xmlEntList = xmlReader.entities; - List xmlRelList = xmlReader.relations; - Map xmlEntMap = new HashMap(xmlEntList.size()); - for (OmEntity e : xmlEntList) { + List xmlEntList = xmlReader.entities; + List xmlRelList = xmlReader.relations; + Map xmlEntMap = new HashMap(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 xmlRelMap = new HashMap(xmlRelList.size()); - for (OmRelation e : xmlRelList) { + Map xmlRelMap = new HashMap(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 atts, List xmlAtts) { + private static boolean attsEquals(List atts, List 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;