Jsapi20SpokenInput implements SpokenInput, RecognizerListener { @Override public void activateGrammars( final Collection<GrammarImplementation<? extends Object>> grammars) throws BadFetchError, UnsupportedLanguageError, NoresourceError { if (recognizer == null) { throw new NoresourceError("recognizer not available"); } for (GrammarImplementation<? extends Object> current : grammars) { if (current instanceof RuleGrammarImplementation) { final RuleGrammarImplementation ruleGrammar = (RuleGrammarImplementation) current; final String name = ruleGrammar.getName(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("activating grammar '" + name + "'..."); } activateGrammar(name, true); } } } Jsapi20SpokenInput(final RecognizerMode defaultDescriptor,
            final InputMediaLocatorFactory mediaLocatorFactory); void setMediaLocator(final URI locator); @Override void open(); @Override void close(); @Override void addListener(final SpokenInputListener inputListener); @Override void removeListener(final SpokenInputListener inputListener); @Override Collection<BargeInType> getSupportedBargeInTypes(); @Override GrammarImplementation<RuleGrammar> loadGrammar(final URI uri,
            final GrammarType grammarType); @Override void activateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); @Override void deactivateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); @Override void startRecognition(
            final DataModel model,
            final SpeechRecognizerProperties speech,
            final DtmfRecognizerProperties dtmf); @Override void stopRecognition(); @Override void activate(); @Override void passivate(); @Override void connect(final ConnectionInformation info); @Override void disconnect(final ConnectionInformation info); @Override String getType(); void setType(final String resourceType); @Override Collection<GrammarType> getSupportedGrammarTypes(); @Override boolean isBusy(); @Override void recognizerUpdate(final RecognizerEvent recognizerEvent);  }
@Test public void testActivateGrammars() throws Exception, JVoiceXMLEvent { final SrgsXmlDocument document = new SrgsXmlDocument(); final Grammar grammar = document.getGrammar(); grammar.setXmlLang(Locale.US); final Rule rule = grammar.appendChild(Rule.class); rule.setScope("public"); rule.setId("root"); grammar.setRoot(rule); rule.addText("This is a test"); final String xml = document.toString(); final File file = File.createTempFile("jvxmltest", "srgs"); final URI uri = writeToFile(file, xml); final GrammarImplementation<?> impl = input.loadGrammar(uri, GrammarType.SRGS_XML); final Collection<GrammarImplementation<?>> implementations = new java.util.ArrayList<GrammarImplementation<?>>(); implementations.add(impl); input.activateGrammars(implementations); }