--- /dev/null
+package mir.generator;
+
+import java.util.*;
+
+public class CompositeGeneratorLibrary implements Generator.GeneratorLibrary {
+ private Map generatorLibraries;
+ private Generator.GeneratorLibrary defaultLibrary = null;
+ private static String LIBRARY_QUALIFIER_SEPARATOR = "::";
+
+ public CompositeGeneratorLibrary() {
+ generatorLibraries = new HashMap();
+ }
+
+ public void addLibrary(String aQualifier, Generator.GeneratorLibrary aLibrary, boolean anIsDefault) {
+ if (anIsDefault || defaultLibrary == null) {
+ defaultLibrary = aLibrary;
+ }
+
+ generatorLibraries.put(aQualifier, aLibrary);
+ }
+
+ public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {
+ String qualifier;
+ String libraryName;
+ int position;
+ Generator.GeneratorLibrary library;
+
+ position = anIdentifier.indexOf( LIBRARY_QUALIFIER_SEPARATOR );
+ if (position>=0) {
+ libraryName = anIdentifier.substring(0, position);
+ qualifier = anIdentifier.substring(position + LIBRARY_QUALIFIER_SEPARATOR.length());
+
+ library = (Generator.GeneratorLibrary) generatorLibraries.get(libraryName);
+ if (library==null)
+ throw new GeneratorExc("CompositeGeneratorLibrary: library '"+libraryName+"' not found");
+
+ return library.makeGenerator(qualifier);
+ }
+ else {
+ if (defaultLibrary!=null)
+ return defaultLibrary.makeGenerator(anIdentifier);
+ else
+ throw new GeneratorExc("CompositeGeneratorLibrary: no default library speficied");
+ }
+ };
+}
\ No newline at end of file