001package com.plivo.api.xml;
002
003import javax.xml.bind.annotation.XmlAttribute;
004import javax.xml.bind.annotation.XmlRootElement;
005import javax.xml.bind.annotation.XmlValue;
006import java.util.ArrayList;
007import javax.xml.bind.annotation.XmlMixed;
008import java.util.List;
009import com.plivo.api.exceptions.PlivoXmlException;
010
011@XmlRootElement(name = "prosody")
012public class Prosody extends PlivoXml implements EmphasisNestable,
013                                                 LangNestable,
014                                                 PNestable,
015                                                 ProsodyNestable,
016                                                 SNestable,
017                                                 SpeakNestable,
018                                                 WNestable {
019
020  @XmlMixed
021  private List<Object> mixedContent = new ArrayList<Object>();
022
023  @XmlAttribute
024  private String volume;
025
026  @XmlAttribute
027  private String rate;
028
029  @XmlAttribute
030  private String pitch;
031
032  public Prosody() {
033  }
034
035  public Prosody(String content) {
036    this.mixedContent.add(content);
037  }
038
039  public Prosody(String content, String volume, String rate, String pitch) {
040    this.mixedContent.add(content);
041    if (!(volume == null || "".equals(volume))) {
042      this.volume = volume;
043    }
044    if (!(rate == null || "".equals(rate))) {
045      this.rate = rate;
046    }
047    if (!(pitch == null || "".equals(pitch))) {
048      this.pitch = pitch;
049    }
050  }
051
052  public String getVolume() {
053    return this.volume;
054  }
055
056  public String getRate() {
057    return this.rate;
058  }
059
060  public String getPitch() {
061    return pitch;
062  }
063
064  public Prosody children(Object... nestables) throws PlivoXmlException {
065    for (Object obj : nestables) {
066      if (obj instanceof ProsodyNestable || obj instanceof String) {
067        mixedContent.add(obj);
068      } else {
069        throw new PlivoXmlException("XML Validation Error: <" + obj.getClass().getSimpleName() + "> can not be nested in <prosody>");
070      }
071    }
072    return this;
073  }
074}