OpActionFormat.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 java.util.ArrayList;
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
 */
public class OpActionFormat {

  private Identity identityFormat;
  private String actionName;
  private ArrayList<ParamDefn> paramDefns;

  public OpActionFormat() {
    paramDefns = new ArrayList<>();
  }

  public Identity getIdentityFormat() {
    return identityFormat;
  }

  public String getActionName() {
    return actionName;
  }

  public ParamDefn getParamDefn(int i) {
    return paramDefns.get(i);
  }

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

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

      switch (event.getEventType()) {
        case XMLStreamConstants.START_ELEMENT:
          startElemnt = event.asStartElement();
          if (startElemnt.getName().getLocalPart().equals(IDENTITY) && identityFormat == null) { // May have to change this but it works not for excluding the groupid identities
            identityFormat = new Identity();
            identityFormat.parse(reader);
          }
          if (startElemnt.getName().getLocalPart().equals(ACTIONNAME)) {
            actionName = reader.getElementText();
            break;
          }
          if (startElemnt.getName().getLocalPart().equals(PARAMDEFN)) {
            paramDefn = new ParamDefn();
            paramDefn.parse(reader);
            paramDefns.add(paramDefn);
          }
          break;

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

}