package org.openlcb.cdi.jdom; import org.jdom2.Attribute; import org.jdom2.Element; import org.openlcb.cdi.CdiRep; /** * Implement the CdiRep interface using * JDOM for reading the underlying XML. * * @author Bob Jacobsen Copyright 2011 * @version $Revision: -1 $ */ public class JdomCdiRep implements CdiRep { public JdomCdiRep(Element root) { this.root = root; } public static class Identification implements CdiRep.Identification { @Override public String getManufacturer() { Element c = id.getChild("manufacturer"); if (c == null) return null; return c.getText(); } @Override public String getModel() { Element c = id.getChild("model"); if (c == null) return null; return c.getText(); } @Override public String getHardwareVersion() { Element c = id.getChild("hardwareVersion"); if (c == null) return null; return c.getText(); } @Override public String getSoftwareVersion() { Element c = id.getChild("softwareVersion"); if (c == null) return null; return c.getText(); } @Override public Map getMap() { return new Map(id.getChild("map")); } Identification(Element id) { this.id = id; } Element id; } @Override public Identification getIdentification() { Element id = root.getChild("identification"); if (id == null) return null; return new Identification(id); } @Override public java.util.List getSegments() { java.util.List list = root.getChildren("segment"); java.util.ArrayList result = new java.util.ArrayList(); for (int i = 0; i getItems() { java.util.List list = new java.util.ArrayList(); if (e == null) return list; java.util.List elements = e.getChildren(); for (int i = 0; i getKeys() { java.util.ArrayList list = new java.util.ArrayList(); if (map == null) return list; java.util.List relations = map.getChildren("relation"); if (relations == null) return list; for (int i = 0; i getValues() { java.util.ArrayList list = new java.util.ArrayList(); if (map == null) return list; java.util.List relations = map.getChildren("relation"); if (relations == null) return list; for (int i = 0; i