@Override public void generateModel(DataModel dataModel, ModelDriverListener generationListener) throws Exception { GenerationContext generationContext = new GenerationContext(dataModel); generationContext.setGenerationListener(generationListener); GenerationEngine generationEngine = GenerationEngine.getInstance(); generationEngine.generate(generationContext); }
public void generateSubTemplate(GenerationContext generationContext, String template) throws Exception { //read the template to use String templatePath = null; try { templatePath = getFullVelocityPath(generationContext.getTemplatesPath(), template); Template t = velocityEngine.getTemplate(templatePath); t.merge(generationContext.getVelocityContext(), generationContext.getCurrentOutput()); } catch (Exception e) { logger.error("An error was produced during template adf: template: " + template + ", templatePath: " + templatePath, e); } }
/** * Creates a VelocityContext and inject common variables into it. * * @param generationContext Generation context provided by user. * * @return A properly initialized VelocityContext. */ private VelocityContext buildContext(GenerationContext generationContext) { VelocityContext context = new VelocityContext(); // Add main objects to velocity context context.put("engine", this); context.put("context", generationContext); context.put("dataModel", generationContext.getDataModel()); context.put("nameTool", new GenerationTools()); generationContext.setVelocityContext(context); return context; }
public String generateSubTemplateString(GenerationContext generationContext, String template) throws Exception { StringWriter writer = new StringWriter(); // This is necessary to cover possible included sub-templates generationContext.setCurrentOutput(writer); //read the template to use String templatePath = null; try { templatePath = getFullVelocityPath(generationContext.getTemplatesPath(), template); Template t = velocityEngine.getTemplate(templatePath); t.merge(generationContext.getVelocityContext(), writer); } catch (Exception e) { logger.error("An error was produced during template adf: template: " + template + ", templatePath: " + templatePath, e); } return writer.toString(); }
String templatePath = getFullVelocityPath(generationContext.getTemplatesPath(), template); VelocityContext context = buildContext(generationContext); generationContext.setCurrentOutput(writer); t.merge(context, writer); if (generationContext.getOutputPath() != null) { File fout = new File(generationContext.getOutputPath(), filePath); fout.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(fout, false); if (generationContext.getGenerationListener() != null) { generationContext.getGenerationListener().assetGenerated(filePath, writer.toString());
private String createJavaSource(DataObject dataObject) throws Exception { GenerationContext generationContext = new GenerationContext(null); String source; GenerationEngine engine; try { engine = GenerationEngine.getInstance(); source = engine.generateJavaClassString(generationContext, dataObject); } catch (Exception e) { logger.error("Java source for dataObject: " + dataObject.getClassName() + " couldn't be created.", e); throw e; } return source; }
/** * Runs the code adf. * * @param generationContext Context information for the adf. * * @throws Exception * */ public void generate(GenerationContext generationContext) throws Exception { VelocityContext context = buildContext(generationContext); String templatesPath = generationContext.getTemplatesPath(); String initialTemplate = generationContext.getInitialTemplate(); if (logger.isDebugEnabled()) { logger.debug("Starting code adf with templatesPath: " + templatesPath + ", initialTemplate: " + initialTemplate); } // Always start by the initial template String templatePath = getFullVelocityPath(templatesPath, initialTemplate); if (logger.isDebugEnabled()) logger.debug("Initial templatePath: " + templatePath); StringWriter writer = new StringWriter(); Template t = velocityEngine.getTemplate(templatePath); t.merge(context, writer); }
ClassTypeResolver classTypeResolver) throws Exception { GenerationContext generationContext = new GenerationContext(null); GenerationEngine engine = GenerationEngine.getInstance(); GenerationTools genTools = new GenerationTools();
GenerationContext context = new GenerationContext(null); boolean updateAccessors = true; FieldSource<JavaClassSource> currentField;
GenerationContext context = new GenerationContext(null); for (org.kie.workbench.common.services.datamodeller.core.JavaClass nestedJavaClass : dataObject.getNestedClasses()) { javaClassSource.addNestedType(engine.generateNestedClassString(context,
String methodName; GenerationContext generationContext = new GenerationContext(null); GenerationEngine engine; GenerationTools genTools = new GenerationTools();
GenerationContext context = new GenerationContext(null); boolean updateAccessors = false; FieldSource<JavaClassSource> field;