ParamDefn.java [src/config/nodes] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package config.nodes;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import static utils.Constants.*;

/**
 *
 * @author Brad May need to add more to this class if the limits matter
 */
public class ParamDefn {
  private String paramname;
  private String paramtype;

  public String getParamname() {
    return paramname;
  }

  public String getParamtype() {
    return paramtype;
  }

  public void parse(XMLEventReader reader) throws XMLStreamException {
    XMLEvent event;
    boolean done = false;
    StartElement startElement;
    EndElement endElement;

    while (reader.hasNext() && !done) {
      event = reader.nextEvent();

      switch (event.getEventType()) {
        case XMLStreamConstants.START_ELEMENT:
          startElement = event.asStartElement();
          if (startElement.getName().getLocalPart().equals(PARAMNAME)) {
            paramname = reader.getElementText();
            break; // the cursor is on a character element now so you can't check the next localName
          }

          if (startElement.getName().getLocalPart().equals(PARAMTYPE)) {
            paramtype = reader.getElementText();
          }
          break;

        case XMLStreamConstants.END_ELEMENT:
          endElement = event.asEndElement();
          if (endElement.getName().getLocalPart().equals(PARAMDEFN))
            done = true;
      }
    }
  }
}