use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.
the class AbstractGenerator method writeTemplate.
protected StringBuffer writeTemplate(final Map<String, Object> ctxt, final String path) throws GenerationException {
// Generate code
final StringWriter sw = new StringWriter();
final BufferedWriter bw = new BufferedWriter(sw);
try {
final Template template = config.getTemplate(path + ".ftl");
template.process(ctxt, bw);
} catch (IOException ioe) {
throw new GenerationException(ioe);
} catch (TemplateException te) {
throw new GenerationException(te);
} finally {
try {
bw.close();
sw.close();
} catch (IOException ioe) {
throw new GenerationException(ioe);
}
}
return sw.getBuffer();
}
use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.
the class CircleDefinitionGenerator method doGenerate.
@Override
public StringBuffer doGenerate(final CircleDefinition input) throws GeneratorException {
final double radius = input.getRadius();
final Map<String, Object> root = new HashMap<String, Object>();
root.put("className", Circle.class.getName());
root.put("radius", formatDouble(radius));
// Generate the code using the given template.
try {
return writeTemplate(root);
} catch (final GenerationException e) {
throw new GeneratorException(e);
}
}
use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.
the class GroupDefinitionGenerator method generate.
@Override
public StringBuffer generate(final GroupDefinition input) throws GeneratorException {
final StringBuffer wrapped = super.generate(input);
final StringBuffer wrapper;
try {
wrapper = writeTemplate(new HashMap<>());
super.appendDraggable(wrapper, input);
super.appendListening(wrapped, input);
wrapper.append(formatString(ADD_WRAPPED, wrapped.toString()));
} catch (final GenerationException e) {
throw new GeneratorException(e);
}
return wrapper;
}
use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.
the class RectDefinitionGenerator method doGenerate.
@Override
public StringBuffer doGenerate(final RectDefinition input) throws GeneratorException {
final double width = input.getWidth();
final double height = input.getHeight();
final double radius = input.getCornerRadius();
final Map<String, Object> root = new HashMap<String, Object>();
root.put("className", Rectangle.class.getName());
root.put("width", formatDouble(width));
root.put("height", formatDouble(height));
root.put("radius", formatDouble(radius));
// Generate the code using the given template.
try {
return writeTemplate(root);
} catch (final GenerationException e) {
throw new GeneratorException(e);
}
}
use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.
the class SVGViewFactoryGenerator method generate.
@Override
public StringBuffer generate(final ViewFactory viewFactory) throws GeneratorException {
final List<StringBuffer> viewBuffers = new LinkedList<>();
final String name = viewFactory.getSimpleName();
final String pkg = viewFactory.getPackage();
final List<ViewDefinition<?>> viewDefinitions = viewFactory.getViewDefinitions();
final Map<String, String> staticFields = new LinkedHashMap<>();
viewDefinitions.stream().forEach((viewDefinition) -> {
try {
if (viewDefinition instanceof ViewDefinitionImpl) {
staticFields.putAll(((ViewDefinitionImpl) viewDefinition).getStaticFields());
}
final StringBuffer viewBuffer = generateView(viewFactory, viewDefinition);
viewBuffers.add(viewBuffer);
} catch (GeneratorException e) {
throw new RuntimeException(e);
}
});
// Generate template context.
final List<String> viewsContent = new LinkedList<>();
viewBuffers.forEach(b -> viewsContent.add(b.toString()));
Map<String, Object> root = new HashMap<>();
root.put("genClassName", this.getClass().getName());
root.put("name", name);
root.put("pkg", pkg);
root.put("implementedTypeName", viewFactory.getImplementedType());
root.put("fmethods", viewsContent);
root.put("fields", generateStaticFields(staticFields));
// Generate the code using the given template.
StringBuffer result;
try {
result = writeTemplate(root);
} catch (final GenerationException e) {
throw new GeneratorException(e);
}
return result;
}
Aggregations