class SrgsXmlOptionConverter implements OptionConverter {

    @Override
    public Grammar createDtmfGrammar(final Collection<Option> options) {
        if ((options == null) || options.isEmpty()) {
            return null;
        }
        try {
            final SrgsXmlDocument document = new SrgsXmlDocument();
            final Grammar grammar = document.getGrammar();
            grammar.setType(GrammarType.SRGS_XML);
            final Rule rule = grammar.appendChild(Rule.class);
            final String name = getName(ModeType.DTMF);
            rule.setId(name);
            grammar.setRoot(rule);
            final OneOf oneof = rule.appendChild(OneOf.class);
            boolean hasDtmf = false;
            for (Option option : options) {
                final String dtmf = option.getDtmf();
                if (dtmf != null) {
                    final Item item = oneof.appendChild(Item.class);
                    item.addText(dtmf);
                    hasDtmf = true;
                }
            }
            if (hasDtmf) {
                return grammar;
            } else {
                return null;
            }
        } catch (ParserConfigurationException e) {
            LOGGER.warn(e.getMessage(), e);
            return null;
        }
    }

}