Esempio n. 1
0
 /**
  * Creates a new datapoint from XML input.
  *
  * <p>If the current XML element position is no start tag, the next element tag is read. The
  * datapoint element is then expected to be the current element in the reader. It reads the start
  * tag and attributes of a datapoint element, and sets the reader to the next position.
  *
  * @param r a XML reader
  * @throws KNXMLException if the XML element is no datapoint or could not be read correctly
  */
 Datapoint(final XMLReader r) throws KNXMLException {
   if (r.getPosition() != XMLReader.START_TAG) r.read();
   final Element e = r.getCurrent();
   final int line = r.getLineNumber();
   if (r.getPosition() != XMLReader.START_TAG || !e.getName().equals(TAG_DATAPOINT))
     throw new KNXMLException("no KNX datapoint element", e != null ? e.getName() : null, line);
   stateBased = readDPType(r);
   if ((name = e.getAttribute(ATTR_NAME)) == null)
     throw new KNXMLException("missing attribute " + ATTR_NAME, null, line);
   if ((dptId = e.getAttribute(ATTR_DPTID)) == null)
     throw new KNXMLException("missing attribute " + ATTR_DPTID, null, line);
   if (dptId.length() == 0) dptId = null;
   String a = null;
   try {
     a = e.getAttribute(ATTR_MAINNUMBER);
     mainNo = Integer.decode(a).intValue();
     a = e.getAttribute(ATTR_PRIORITY);
     priority = Priority.get(a);
   } catch (final RuntimeException rte) {
     throw new KNXMLException("malformed attribute, " + rte.getMessage(), a, line);
   }
   r.read();
 }