package p2.webclient.system.tags;

import p2.webclient.system.controller.ControlHandler;
import p2.webclient.system.controller.WebClientEvent;

import javax.servlet.jsp.JspException;
import java.util.ListIterator;

@SuppressWarnings("serial")
public class ProcessChildrenTag extends WebClientTagSupport {
    private String f = null;
    private String g = null;

    public String getEventType() {
        return this.f;
    }

    public void setEventtype(String paramString) {
        this.f = paramString;
    }

    public String getValue() {
        return this.g;
    }

    public void setValue(String paramString) {
        this.g = paramString;
    }

    @Override
    @SuppressWarnings({"rawtypes"})
    public int doStartTag() throws JspException {
        super.doStartTag();
        String TargetId = "";
        String username = "";
        // String event = "";
        try {

            if (this.b.getEventState() == 0) {
                return 5;
            }
            WebClientEvent localWebClientEvent;

            if (this.f != null) {
                localWebClientEvent = new WebClientEvent(this.f, this.d.getId(), this.g, this.b);
            } else {
                if (this.a.getEventStatus() == 0) {
                    return 5;
                }
                localWebClientEvent = this.a;
            }
            TargetId = localWebClientEvent.getTargetId();
            username = localWebClientEvent.getSessionContext().getUserInfo().getUserName();
            // event = localWebClientEvent.getAdditionalEvent();
            ListIterator localListIterator = this.d.getChildren().listIterator();
            int i = 0;
            while (localListIterator.hasNext()) {
                ControlHandler localControlHandler;
                int j = (localControlHandler = (ControlHandler) localListIterator.next())
                        .handleEvent(localWebClientEvent);
                this.b.setEventState(j);
                if ((j == 0) || (this.b.getEventState() == 0)) {
                    this.b.setEventState(0);
                    this.a.setStatus(0);
                    localWebClientEvent.setStatus(0);
                    i = 5;
                }
                if (localWebClientEvent.getEventStatus() == 0) {
                    break;
                }
            }
            if (localWebClientEvent.getEventStatus() == 0) {
                i = 5;
            }
            this.b.setCurrentEventHandler(this.d);
            this.b.setCurrentEvent(this.a);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            TargetId = null;
            username = null;
            return 0;
        }
    }

    @Override
    public void release() {
        super.release();
        this.f = null;
        this.g = null;
    }
}
