1 23 24 package org.objectweb.jorm.generator.lib; 25 26 import org.apache.velocity.VelocityContext; 27 import org.apache.velocity.context.Context; 28 import org.objectweb.jorm.compiler.api.PExceptionCompiler; 29 import org.objectweb.jorm.compiler.api.JormCompilerParameter; 30 import org.objectweb.jorm.metainfo.api.*; 31 import org.objectweb.jorm.metainfo.api.Package; 32 import org.objectweb.jorm.api.PException; 33 import org.objectweb.jorm.util.io.api.TargetHolder; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 import java.io.File ; 37 import java.io.FileWriter ; 38 39 58 public class PNameGetterGenerator extends CommonGenerator { 59 66 public void generate(CompositeName co, 67 TargetHolder holder, 68 JormCompilerParameter cp) throws PException { 69 String packName = ((Package ) co.getParent()).getName(); 71 String fileName = co.getName() + "PNG"; 72 if (packName != null && packName.length() > 0) { 73 fileName = packName + "." + fileName; 74 fileName = fileName.replace('.', File.separatorChar); 75 } 76 logger.log(BasicLevel.DEBUG, "Generate the " + fileName + " interface"); 77 try { 78 FileWriter fw = holder.getFileWriter(fileName + ".java"); 80 Context ctx = new VelocityContext(); 81 ctx.put("compositename", co); 82 CommonHelper helper = new CommonHelper(); 83 helper.setLogger(logger); 84 ctx.put("tools", helper); 85 ctx.put("header", GEN_TEMPLATE_DIR + "Header.vm"); 86 logger.log(BasicLevel.DEBUG, "Merging for PNG"); 87 if (template == null) { 88 template = velocityEngine.getTemplate(GEN_TEMPLATE_DIR + "Png.vm"); 89 } 90 template.merge(ctx, fw); 91 logger.log(BasicLevel.DEBUG, "Merge done for PNG"); 92 fw.flush(); 93 fw.close(); 94 } catch (Exception e) { 95 logger.log(BasicLevel.ERROR, "", e); 96 throw new PExceptionCompiler(e, "Problem while generating PNameGetter."); 97 } 98 } 99 } 100 | Popular Tags |