class XmlCredentialsUtil {

    public static Collection<Credentials> getCredentials(final XMLConfiguration xmlConfiguration, final String rootElement, final String urlElement, final String userNameElement, final String passwordElement, final String tokenElement, final String apiVersionElement) {
        IntegrityUtil.ensure(xmlConfiguration, "Must provide an XMLConfiguration!");
        IntegrityUtil.ensure(rootElement, "Must provide a root element!");
        IntegrityUtil.ensure(urlElement, "Must provide a url element!");
        IntegrityUtil.ensure(userNameElement, "Must provide a user name element!");
        IntegrityUtil.ensure(passwordElement, "Must provide a password element!");
        IntegrityUtil.ensure(tokenElement, "Must provide a token element!");
        IntegrityUtil.ensure(apiVersionElement, "Must provide an api version element!");

        final List<HierarchicalConfiguration> configurationList = xmlConfiguration.configurationsAt(rootElement);
        IntegrityUtil.ensure(configurationList, "No configuration found using [" + rootElement + "]");

        final List<Credentials> retVal = new ArrayList(configurationList.size());

        for (final HierarchicalConfiguration hierarchicalConfiguration : configurationList) {
            retVal.add(convertToCredentials(hierarchicalConfiguration, xmlConfiguration.getProperty(urlElement), userNameElement, passwordElement, tokenElement, xmlConfiguration.getProperty(apiVersionElement)));
        }

        return retVal;
    }

}