package org.spoofax.modelware.emf;

/**
 * @author Oskar van Rest
 */
import java.util.ArrayList;
import java.util.Collection;

public class LanguageRegistry {

	private static LanguageRegistry instance = new LanguageRegistry();

	private Collection<Language> languages = new ArrayList<Language>();
	
	private LanguageRegistry() {
	}
	
	public static LanguageRegistry getInstance() {
		return instance;
	}
	
	public void add(Language language) {
		languages.add(language);
	}
	
	public Language get(String fileExtension) {
		for (Language language : languages) {
			if (language.getTextFileExtension().equals(fileExtension) || language.getDiagramFileExtension().equals(fileExtension)) {
				return language;
			}
		}
		return null;
	}
}

@@ -710,16 +710,404 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09%0A%09%09// fallback: some user may choose a file extension like .fml.diagram, in which case the language can be obtained using extensions .fml.diagram and .diagram (the actual file extension).%0A%09%09for (Language language : languages) %7B%0A%09%09%09if (language.getTextFileExtension().endsWith(fileExtension) %7C%7C language.getDiagramFileExtension().endsWith(fileExtension)) %7B%0A%09%09%09%09return language;%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%09return

support for file extensions with dots (.) in them