@@ -0,0 +1,2709 @@
+package jburg.emitter;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.stringtemplate.v4.*;%0A%0A/**%0A * TemplateGroup is a facade for a STGroup that%0A * hides details of the .stg file management, supports name/value%0A * attribute pairs for convenience, and manages a map of default%0A * attributes to be supplied to all templates.%0A */%0Apublic class TemplateGroup%0A%7B%0A    public TemplateGroup(String directoryName, String templateGroupName)%0A    %7B%0A        if (directoryName != null) %7B%0A            templateGroupName = directoryName + java.io.File.separator + templateGroupName;%0A        %7D%0A        this.templates = new STGroupFile(templateGroupName);%0A    %7D%0A%0A    /**%0A     * The backing STGroup.%0A     */%0A    private STGroup templates;%0A%0A    /**%0A     * Default attributes to provide to all templates.%0A     * Specific values are up to the caller.%0A     */%0A    private Map%3CString, Object%3E defaultAttrs = new HashMap%3CString, Object%3E();%0A%0A    private Object configuration;%0A%0A    void setConfiguration(Object configuration)%0A    %7B%0A        this.configuration = configuration;%0A    %7D%0A%0A    /**%0A     * Select a template by name, with optional attributes.%0A     * The template is also given a copy of the template%0A     * group's current set of default attributes.%0A     * @param name the template's name.%0A     * @param attrValue pairs of attrName, attrValue.%0A     */%0A    public ST getTemplate(String name, Object ... attrValue)%0A    %7B%0A        Map%3CString,Object%3E templateAttrs = new HashMap%3CString, Object%3E();%0A        templateAttrs.put(%22defaults%22, this.defaultAttrs);%0A        templateAttrs.put(%22config%22, this.configuration);%0A        ST result = this.templates.getInstanceOf(name);%0A%0A        // Emulate ST3 default attributes behavior.%0A        for (String key: defaultAttrs.keySet()) %7B%0A            result.add(key, defaultAttrs.get(key));%0A        %7D%0A%0A        if (! (attrValue.length == 0 %7C%7C attrValue.length %25 2 == 0) )%0A            throw new IllegalStateException(%22Expected an even number of attr/value pairs%22);%0A%0A        for ( int i = 0; i %3C attrValue.length; i += 2 )%0A        %7B%0A            result.add(attrValue%5Bi%5D.toString(), attrValue%5Bi+1%5D);%0A        %7D%0A%0A        return result;%0A    %7D%0A%0A    /**%0A     * Register a renderer; delegates to the STGroup's registerRenderer method.%0A     */%0A    void registerRenderer(Class%3C? extends Object%3E clazz, AttributeRenderer renderer)%0A    %7B%0A        this.templates.registerRenderer(clazz, renderer);%0A    %7D%0A%0A    /**%0A     * Set a default attriburte.%0A     * @param key the attribute's name.%0A     * @param value the attribute's value.%0A     */%0A    public void setDefaultAttribute(String key, Object value)%0A    %7B%0A        this.defaultAttrs.put(key,value);%0A    %7D%0A%7D%0A%0A

Add TemplateGroup STG manager