Beispiel #1
0
 /* (non-Javadoc)
  * @see java.lang.Object#toString()
  */
 public String toString() {
   return main.toString()
       + " "
       + name
       + ", DPT main "
       + mainNo
       + " id "
       + (dptId == null ? "-" : dptId)
       + ", "
       + priority.toString()
       + " priority";
 }
Beispiel #2
0
 /**
  * Saves this datapoint in XML format to the supplied XML writer.
  *
  * <p>
  *
  * @param w a XML writer
  * @throws KNXMLException on error saving this datapoint
  */
 public void save(final XMLWriter w) throws KNXMLException {
   /* XML layout:
    <datapoint stateBased=[true|false] name=string mainNumber=int dptID=string
    priority=string>
    knxAddress
    ...
    </datapoint>
   */
   final List att = new ArrayList();
   att.add(new Attribute(ATTR_STATEBASED, Boolean.toString(stateBased)));
   att.add(new Attribute(ATTR_NAME, name));
   att.add(new Attribute(ATTR_MAINNUMBER, Integer.toString(mainNo)));
   att.add(new Attribute(ATTR_DPTID, dptId == null ? "" : dptId));
   att.add(new Attribute(ATTR_PRIORITY, priority.toString()));
   w.writeElement(TAG_DATAPOINT, att, null);
   main.save(w);
   doSave(w);
   w.endElement();
 }
Beispiel #3
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();
 }