Skip to main content
summaryrefslogtreecommitdiffstats
blob: ea9a31e567cae358a9856554e004d4f26ebedbc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<%@jet package="org.eclipse.jet.internal.compiler.templates" 
       class="JET2TransformGenerator" 
               %>
<%@jet imports="java.util.Iterator"%>
<%@jet imports="java.util.Map"%>
<%@jet imports="org.eclipse.jet.internal.compiler.LoaderGenerationParameters"%>
<%
LoaderGenerationParameters parms = (LoaderGenerationParameters)context.getVariable("args"); //$NON-NLS-1$
Map templateMap = (Map) parms.getTemplateMap();;
%>
package <%= parms.getPackageName() %>;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.JET2TemplateLoaderExtension;
import org.eclipse.jet.JET2Template;

public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2TemplateLoaderExtension {

	private interface TemplateFactoryMethod {
		public abstract JET2Template newTemplate();
	}

	private Map pathToFactoryMap = null;
	
	private JET2TemplateLoader delegate = null;

	public <%= parms.getClassName() %>() {
		super();
	}

	public JET2Template getTemplate(String templatePath) {
	    if(pathToFactoryMap == null) {
	        pathToFactoryMap = new HashMap(<%= templateMap.size() %>);
<% for(Iterator i = templateMap.entrySet().iterator(); i.hasNext();){ 
		Map.Entry entry = (Map.Entry)i.next();
%>
		    pathToFactoryMap.put("<%= entry.getKey() %>", //$NON-NLS-1$
		        new TemplateFactoryMethod() {
		            public JET2Template newTemplate() {
                        return new <%= entry.getValue() %>();
		            }
		        });
<% } %>
        }
        TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
		return factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();
	}

    public void setDelegateLoader(JET2TemplateLoader loader) {
        this.delegate = loader;
    }
    
    public JET2TemplateLoader getDelegateLoader() {
        return delegate;
    }
}

Back to the top