Jsapi10SpokenInput implements SpokenInput, StreamableSpokenInput { public void activateGrammars( final Collection<GrammarImplementation<? extends Object>> grammars) throws BadFetchError, UnsupportedLanguageError, NoresourceError { if (recognizer == null) { throw new NoresourceError("No recognizer available!"); } boolean changedGrammar = false; 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 + "'..."); } final RuleGrammar grammar = recognizer.getRuleGrammar(name); if (!grammar.isEnabled()) { changedGrammar = true; grammar.setEnabled(true); grammar.setActivationMode(Grammar.RECOGNIZER_FOCUS); } } } if (changedGrammar) { try { recognizer.commitChanges(); } catch (GrammarException e) { throw new BadFetchError(e.getMessage(), e); } catch (EngineStateError e) { throw new BadFetchError(e.getMessage(), e); } } if (LOGGER.isDebugEnabled()) { dumpLoadedGrammars(); } } Jsapi10SpokenInput(final RecognizerModeDesc defaultDescriptor); void open(); void close(); void addListener(final SpokenInputListener inputListener); void removeListener(final SpokenInputListener inputListener); Collection<BargeInType> getSupportedBargeInTypes(); @Override GrammarImplementation<?> loadGrammar(final URI uri,
            final GrammarType type); void activateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); void deactivateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); @Override void startRecognition(
            final DataModel model,
            final SpeechRecognizerProperties speech,
            final DtmfRecognizerProperties dtmf); void stopRecognition(); void activate(); void passivate(); void connect(final ConnectionInformation connectionInformation); void disconnect(final ConnectionInformation connectionInformation); String getType(); Collection<GrammarType> getSupportedGrammarTypes(); void setSpokenInputConnectionHandler(
            final SpokenInputConnectionHandler connectionHandler); URI getUriForNextSpokenInput(); boolean isBusy(); void setStreamableSpokenInput(final StreamableSpokenInput streamable); void writeRecognizerStream(final byte[] buffer, final int offset,
            final int length);  }
@Test public void testActivateGrammars() throws Exception, JVoiceXMLEvent { final String lf = System.getProperty("line.separator"); final String grammar = "#JSGF V1.0;" + lf + "grammar test;" + lf + "public <test> = a|b|c;"; final File file = File.createTempFile("jvxmltest", ".gram"); final URI uri = writeToFile(file, grammar); final RuleGrammarImplementation impl = (RuleGrammarImplementation) recognizer .loadGrammar(uri, GrammarType.JSGF); final Collection<GrammarImplementation<?>> implementations = new java.util.ArrayList<GrammarImplementation<?>>(); implementations.add(impl); recognizer.activateGrammars(implementations); final Collection<RuleGrammar> active = recognizer.getActiveGrammars(); Assert.assertEquals(1, active.size()); Assert.assertTrue(contains("test", active)); }