001
002/*
003 * Copyright (C) 2011 Archie L. Cobbs. All rights reserved.
004 *
005 * $Id$
006 */
007
008package org.dellroad.jibxbindings.twilio.twiml;
009
010import org.dellroad.jibxbindings.ParseUtil;
011import org.jibx.runtime.JiBXParseException;
012
013/**
014 * Call statuses.
015 */
016public enum CallStatus {
017    QUEUED("queued", false),
018    RINGING("ringing", false),
019    IN_PROGRESS("in-progress", false),
020    COMPLETED("completed", true),
021    FAILED("failed", true),
022    BUSY("busy", true),
023    NO_ANSWER("no-answer", true),
024    CANCELED("canceled", true);
025
026    private final String xmlName;
027    private final boolean terminal;
028
029    private CallStatus(String xmlName, boolean terminal) {
030        this.xmlName = xmlName;
031        this.terminal = terminal;
032    }
033
034    /**
035     * Determine whether this represents a terminal state, i.e., the call is hung up.
036     */
037    public boolean isTerminal() {
038        return this.terminal;
039    }
040
041    @Override
042    public String toString() {
043        return this.xmlName;
044    }
045
046    public static CallStatus deserializeXML(String string) throws JiBXParseException {
047        return ParseUtil.deserializeEnumOrNull(string, CallStatus.class);
048    }
049}
050