class GrammarIdentifierCentral {

    public GrammarType identifyGrammar(final GrammarDocument grammar,
            final GrammarType expectedType)
            throws UnsupportedFormatError {
        // first of all make sure, grammar is not null nor empty
        if (grammar == null) {
            throw new UnsupportedFormatError("Cannot identify a null grammar!");
        }

        // Do nothing if there is are no identifiers.
        if (identifier.isEmpty()) {
            LOGGER.warn("no registered identifier!");
            return null;
        }

        // Check the expected identifier first
        final GrammarIdentifier expectedIdentifier =
            getIdentifierByType(expectedType);
        if (expectedIdentifier != null) {
            // It is not a drama at this point if we do no not find an
            // identifier.It may be the case that the actual type is different
            // to the expected type.
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("trying to identify grammar with '"
                        + expectedIdentifier.getClass() + "'");
            }
            final GrammarType type = expectedIdentifier.identify(grammar);
            if (type != null) {
                return type;
            }
        }

        /*
         * allright let's see, if there is any identifier,
         * supporting the type
         */
        for (GrammarIdentifier current : identifier) {
            /* try to identify */
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("trying to identify grammar with '"
                        + current.getClass() + "'");
            }

            // Skip the already tested identifier
            if (current.getSupportedType() != expectedType) { 
                final GrammarType currentType = current.identify(grammar);
                if (currentType != null) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("identified grammar with type '"
                                     + currentType + "'");
                    }
    
                    return currentType;
                }
            }
        }

        LOGGER.warn("unable to identify grammar");
        return null;
    }

    public  GrammarIdentifierCentral();

}