6 public class GeneratorLibraryRepository {
9 public GeneratorLibraryRepository() {
10 factories = new HashMap();
13 public void registerLibraryFactory(String aName, Generator.GeneratorLibraryFactory aFactory) {
14 factories.put(aName, aFactory);
17 public Generator.GeneratorLibrary constructLibrary(String aName, String aParameters) throws GeneratorExc {
18 if (!factories.containsKey(aName))
19 throw new GeneratorExc("Unknown library factory: "+aName);
21 return ((Generator.GeneratorLibraryFactory) factories.get(aName)).makeLibrary(aParameters);
24 private final static String SPACE = "[\t\n\r ]*";
25 private final static String IDENTIFIER = "[a-zA-Z_][a-zA-Z0-9_]*";
26 private final static String EQUALS = "=";
27 private final static String LEFT_PARENTHESIS = "[(]";
28 private final static String RIGHT_PARENTHESIS = "[)]";
29 private final static String FACTORY_PARAMETERS = "[^)]*";
30 private final static String SEMICOLON = ";";
32 public Generator.GeneratorLibrary constructCompositeLibrary(String aSpecification) throws GeneratorExc, GeneratorFailure {
33 //main=freemarker(path=/var/www/test); test=freemarker(path=/var/www/test2)
36 String factoryParameters;
37 CompositeGeneratorLibrary result = new CompositeGeneratorLibrary();
40 SimpleParser parser = new SimpleParser(aSpecification);
43 while (!parser.isAtEnd()) {
44 identifier = parser.parse(IDENTIFIER, "library key expected");
46 parser.parse(EQUALS, "'=' expected");
48 factory = parser.parse(IDENTIFIER, "factory name expected");
50 parser.parse(LEFT_PARENTHESIS, "'(' expected");
51 factoryParameters = parser.parse(FACTORY_PARAMETERS, "parameters expected");
52 parser.parse(RIGHT_PARENTHESIS, "')' expected");
54 result.addLibrary(identifier, constructLibrary(factory, factoryParameters), first);
58 if (!parser.isAtEnd()) {
59 parser.parse(SEMICOLON, "; expected");
64 e.printStackTrace(System.out);
65 throw new GeneratorFailure("Failed to construct generator library: " + e.getMessage(), e);