class MessageSourceLoader {

    public static MessageSource loadMessageSource(ExecutionContext exContext, ResourceContainer resourceContainer, RepositoryService repository) {
        List<ResourceReference> resources = resourceContainer.getResources();

        Map<String, RepositoryResourceKey> map = new LinkedHashMap<String, RepositoryResourceKey>();
        Set<String> baseNames = new LinkedHashSet<String>();

        for (ResourceReference resRef : resources) {
            Resource genericResource = getResource(exContext, repository, resRef);
            if (!isBundle(genericResource)) {
                continue;
            }

            FileResource resource = (FileResource) genericResource;
            String fileName = resource.getName();

            map.put(fileName, new RepositoryResourceKey(resource));
            String baseName = ResourceBundleHelper.getBaseName(fileName);

            if (!baseName.isEmpty()) {
                baseNames.add(baseName);
            }
        }

        if (map.isEmpty()) {
            return null;
        } else {
            setupThreadRepositoryContext(exContext, repository);

            JasperResourceBundleMessageSource messageSource = new JasperResourceBundleMessageSource();
            messageSource.setBundleClassLoader(
                    new RepositoryResourceClassLoader(
                        Thread.currentThread().getContextClassLoader(), map, false, RepositoryUtil.getThreadRepositoryContext()));
            messageSource.setBasenames(baseNames.toArray(new String[baseNames.size()]));

            return messageSource;
        }
    }

}