1 27 28 package org.objectweb.speedo.generation.generator.proxy; 29 30 import java.io.FileWriter ; 31 32 import org.apache.velocity.app.Velocity; 33 import org.apache.velocity.context.Context; 34 import org.objectweb.speedo.api.SpeedoException; 35 import org.objectweb.speedo.api.SpeedoProperties; 36 import org.objectweb.speedo.generation.generator.api.SpeedoGenerationException; 37 import org.objectweb.speedo.generation.generator.lib.SpeedoGenerator; 38 import org.objectweb.speedo.metadata.SpeedoClass; 39 import org.objectweb.util.monolog.wrapper.velocity.VelocityLogger; 40 41 46 public class ProxyGenerator 47 extends SpeedoGenerator { 48 49 public final static String LOGGER_NAME 50 = SpeedoProperties.LOGGER_NAME + ".generation.generator.proxy"; 51 52 public final static String TEMPLATE_NAME = TEMPLATE_DIR + ".proxy.Proxy"; 53 54 57 public boolean init() throws SpeedoException { 58 logger = scp.loggerFactory.getLogger(LOGGER_NAME); 59 return !scp.getXmldescriptor().isEmpty(); 60 } 61 62 63 66 74 public void generate(SpeedoClass sClass, String fileName) 75 throws SpeedoException { 76 computeTemplate(TEMPLATE_NAME.replace('.', '/') + ".vm"); 77 try { 78 Context ctx = getContext(sClass); 79 FileWriter fw = new FileWriter (fileName); 80 ve.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, 81 new VelocityLogger(logger)); 82 template.merge(ctx, fw); 83 fw.flush(); 84 fw.close(); 85 } catch (Exception e) { 86 throw new SpeedoGenerationException( 87 "Error during the generation of the file " + fileName, e); 88 } 89 } 90 91 94 100 protected Context getContext(SpeedoClass jdoClass) throws SpeedoException { 101 Context ctx = super.getContext(jdoClass); 102 103 ctx.put("signatureClass", jdoClass.signature); 105 ctx.put("serialversionuid", jdoClass.VersionUID + "L"); 106 107 String pnamehints = scp.nmf.getNamingManager(jdoClass).getPNameHints( 109 jdoClass, getClassNameDef(jdoClass.jormclass)); 110 ctx.put("pnameHints", pnamehints); 111 return ctx; 112 } 113 } 114 | Popular Tags |