001package org.unix4j.codegen; 002 003import java.net.URL; 004import java.util.List; 005 006import org.unix4j.codegen.command.CommandDefinitionLoader; 007import org.unix4j.codegen.command.def.CommandDef; 008import org.unix4j.codegen.loader.ResourceBasedDataLoader; 009import org.unix4j.codegen.loader.ResourceDataLoader; 010 011import fmpp.Engine; 012import freemarker.template.ObjectWrapper; 013import freemarker.template.SimpleSequence; 014import freemarker.template.TemplateModel; 015import freemarker.template.TemplateModelException; 016 017public class CommandDefinitionDataLoader extends ResourceDataLoader { 018 019 public CommandDefinitionDataLoader() { 020 super(TEMPLATE_LOADER); 021 } 022 023 @SuppressWarnings("rawtypes") 024 @Override 025 public SimpleSequence load(Engine engine, List args) throws Exception { 026 System.out.println("loading command definitions..."); 027 System.out.println("...args: " + args); 028 final SimpleSequence result = super.load(engine, args); 029 System.out.println("loaded " + result.size() + " command definitions."); 030 return result; 031 } 032 033 public static final ResourceBasedDataLoader TEMPLATE_LOADER = new ResourceBasedDataLoader() { 034 @Override 035 public TemplateModel load(URL resource) { 036 final CommandDef commandDef = new CommandDefinitionLoader().load(resource); 037 System.out.println(commandDef.toString("......")); 038 try { 039 return ObjectWrapper.DEFAULT_WRAPPER.wrap(commandDef); 040 } catch (TemplateModelException e) { 041 throw new RuntimeException(e); 042 } 043 } 044 }; 045 046}