class GrammarLoader {

    public GrammarDocument loadGrammarDocument(
            final VoiceXmlInterpreterContext context,
            final FetchAttributes attributes, final Grammar grammar,
            final Locale language)
            throws UnsupportedFormatError, BadFetchError, SemanticError {
        try {
            if (grammar.isExternalGrammar()) {
                return loadExternalGrammar(context, attributes, grammar);
            } else {
                final Session session = context.getSession();
                final String sessionId = session.getSessionId();
                final DocumentServer server = context.getDocumentServer();
                return loadInternalGrammar(sessionId, server, grammar,
                        language);
            }
        } catch (IllegalAttributeException | URISyntaxException e) {
            throw new BadFetchError(e.getMessage(), e);
        }
    }

}