Eclipseplugins
pAGenerateCode.java
1 package com.proalpha.pds.templates.controller;
2 
3 import com.openedge.pdt.core.template.TemplateGenerationException;
4 import com.proalpha.pds.templates.jet.IpaTemplateGenerator;
5 
6 import java.util.Map;
7 
8 import org.eclipse.core.runtime.Platform;
9 import org.osgi.framework.Bundle;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12 
13 public class pAGenerateCode {
14 
15  private static final Logger logger = LoggerFactory.getLogger(pAGenerateCode.class);
16  private static final String COM_PROALPHA_PDS_TEMPLATES = "com.proalpha.pds.templates";
17  private static final String JET_FOLDER = "jet.trunk";
18 
19  private boolean classloaded = false;
20  private IpaTemplateGenerator template = null;
21  private String templatename;
22 
23  public pAGenerateCode(String templatename) {
24  this.templatename = templatename;
25 
26  }
27 
28  public void setTemplateGenerator() {
29 
30  String templatepath;
31 
32  Bundle bundle = Platform.getBundle(COM_PROALPHA_PDS_TEMPLATES);
33  templatepath = COM_PROALPHA_PDS_TEMPLATES + "." + JET_FOLDER + "." + this.templatename;
34  logger.debug("Templatepath is: {}", templatepath);
35  try {
36  Class<?> templateClass = bundle.loadClass(templatepath);
37  this.template = (IpaTemplateGenerator) templateClass.newInstance();
38  classloaded = true;
39 
40  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
41  logger.error(e.getMessage(), e);
42  }
43 
44  }
45 
46  public String generateFile(Map<String, Object> wizardSettings) {
47 
48  if (!classloaded) {
49  this.setTemplateGenerator();
50  }
51 
52  try {
53  return this.template.generate(wizardSettings);
54  } catch (TemplateGenerationException e) {
55  logger.error(e.getMessage(), e);
56  return "";
57  }
58 
59  }
60 
61 }