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; 010import org.unix4j.codegen.optset.OptionSetDefinitionLoader; 011import org.unix4j.codegen.optset.def.OptionSetDef; 012 013import fmpp.Engine; 014import freemarker.template.ObjectWrapper; 015import freemarker.template.SimpleSequence; 016import freemarker.template.TemplateModel; 017import freemarker.template.TemplateModelException; 018 019public class OptionSetDefinitionDataLoader extends ResourceDataLoader { 020 021 public OptionSetDefinitionDataLoader() { 022 super(TEMPLATE_LOADER); 023 } 024 025 @SuppressWarnings("rawtypes") 026 @Override 027 public SimpleSequence load(Engine engine, List args) throws Exception { 028 System.out.println("loading option set definitions..."); 029 System.out.println("...args: " + args); 030 final SimpleSequence result = super.load(engine, args); 031 System.out.println("loaded " + result.size() + " option set definitions."); 032 return result; 033 } 034 035 public static final ResourceBasedDataLoader TEMPLATE_LOADER = new ResourceBasedDataLoader() { 036 @Override 037 public TemplateModel load(URL resource) { 038 final CommandDef commandDef = new CommandDefinitionLoader().load(resource); 039 final OptionSetDef optionSetDef = new OptionSetDefinitionLoader().create(commandDef); 040 System.out.println(optionSetDef.toString("......")); 041 try { 042 return ObjectWrapper.DEFAULT_WRAPPER.wrap(optionSetDef); 043 } catch (TemplateModelException e) { 044 throw new RuntimeException(e); 045 } 046 } 047 }; 048 049}