use of org.uberfire.annotations.processors.exceptions.GenerationException in project kie-wb-common by kiegroup.
the class ExtensionRuleGenerator method generateRule.
private StringBuffer generateRule(final Messager messager, final String ruleName, final String ruleDefinitionId, final String rawTypeArgs, final String rawArgs, final String rhc) throws GenerationException {
Map<String, Object> root = new HashMap<String, Object>();
root.put("ruleId", ruleDefinitionId);
root.put("args", rawArgs);
root.put("typeArgs", rawTypeArgs);
root.put("ruleName", ruleName);
root.put("ruleHandlerClass", rhc);
// Generate code
final StringWriter sw = new StringWriter();
final BufferedWriter bw = new BufferedWriter(sw);
try {
final Template template = config.getTemplate("RuleExtension.ftl");
template.process(root, 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 ImageDefinitionGenerator method doGenerate.
@Override
public StringBuffer doGenerate(final ImageDefinition input) throws GeneratorException {
final String href = input.getHref();
final Map<String, Object> root = new HashMap<>();
root.put("className", Picture.class.getName());
root.put("href", href);
// 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 MultiPathDefinitionGenerator method doGenerate.
@Override
public StringBuffer doGenerate(final MultiPathDefinition input) throws GeneratorException {
final Map<String, Object> root = new HashMap<String, Object>();
root.put("className", MultiPath.class.getName());
root.put("pathInstanceId", SVGViewFactoryGenerator.getStaticFieldValidId(input.getId()));
// 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 SVGViewDefinitionGenerator method generate.
@Override
@SuppressWarnings("unchecked")
public StringBuffer generate(final ViewFactory viewFactory, final ViewDefinition<SVGShapeView> viewDefinition) throws GeneratorException {
StringBuffer result = null;
final String factoryName = viewFactory.getSimpleName();
final String viewId = viewDefinition.getId();
final String methodName = viewDefinition.getFactoryMethodName();
final ShapeDefinition main = viewDefinition.getMain();
if (null != main) {
final Map<String, Object> root = new HashMap<>();
// Generate the children primitives.
final List<String> childrenRaw = new LinkedList<>();
final List<PrimitiveDefinition> children = viewDefinition.getChildren();
for (final PrimitiveDefinition child : children) {
final String childId = SVGGeneratorFormatUtils.getValidInstanceId(child);
String childRaw = SVGPrimitiveGeneratorUtils.generateSvgPrimitive(childId, SVGViewDefinitionGenerator::getGenerator, child);
if (null != childRaw) {
childrenRaw.add(childRaw);
childrenRaw.add(AbstractGenerator.formatString(PRIM_CHILD_TEMPLATE, childId));
}
}
// SVG View children.
final List<String> svgChildrenRaw = new LinkedList<>();
final List<ViewRefDefinition> svgViewRefs = viewDefinition.getSVGViewRefs();
svgViewRefs.forEach(viewRef -> {
final String parent = viewRef.getParent();
final String svgName = viewRef.getFilePath();
final String viewRefId = viewRef.getViewRefId();
final boolean existReferencedView = viewFactory.getViewDefinitions().stream().anyMatch(def -> viewRefId.equals(def.getId()));
if (existReferencedView) {
final String childRaw = formatString(SVG_CHILD_TEMPLATE, parent, factoryName, viewRefId);
svgChildrenRaw.add(childRaw);
} else {
throw new RuntimeException("The view [" + viewRefId + "] references " + "another the view [" + svgName + "], but no factory method " + "for it exists in [" + viewFactory.getImplementedType() + "]");
}
});
// Look for the state shape view.
final List<ShapeDefinition> stateViews = new LinkedList<>();
SVGModelUtils.visit(viewDefinition, p -> {
if (p instanceof ShapeDefinition && SVGPrimitiveGeneratorUtils.CAN_GENERATE_PRIMITIVE_CODE.test(p)) {
final ShapeDefinition shapeDefinition = (ShapeDefinition) p;
shapeDefinition.getStateDefinition().ifPresent(s -> stateViews.add((ShapeDefinition) p));
}
});
final String stateViewIds = stateViews.isEmpty() ? "view" : stateViews.stream().map(d -> SVGGeneratorFormatUtils.getValidInstanceId(d.getId())).collect(Collectors.joining(","));
final String stateViewPolicyType = stateViews.isEmpty() ? ShapeStateDefaultHandler.RenderType.STROKE.name() : ((ShapeDefinition.ShapeStateDefinition) stateViews.get(0).getStateDefinition().get()).name();
final String stateViewPolicy = ShapeStateDefaultHandler.RenderType.class.getName().replace("$", ".") + "." + stateViewPolicyType.toUpperCase();
// Generate the main shape.
final PrimitiveDefinitionGenerator<PrimitiveDefinition<?>> mainGenerator = getGenerator(main);
final StringBuffer mainBuffer = mainGenerator.generate(main);
final LayoutDefinition mainLayoutDefinition = main.getLayoutDefinition();
final String mainLayoutRaw = SVGPrimitiveGeneratorUtils.formatLayout(mainLayoutDefinition);
// Generate the view's text styling stuff.
final StyleSheetDefinition globalStyleSheetDefinition = ((ViewDefinitionImpl) viewDefinition).getGlobalStyleSheetDefinition();
final String viewTextRaw = null != globalStyleSheetDefinition ? SVGShapeTextCodeBuilder.generate("view", viewId, globalStyleSheetDefinition) : "";
// Populate the context and generate using the template.
root.put("viewId", viewId);
root.put("name", methodName);
root.put("mainShape", mainBuffer.toString());
root.put("layout", mainLayoutRaw);
root.put("width", formatDouble(viewDefinition.getWidth()));
root.put("height", formatDouble(viewDefinition.getHeight()));
root.put("text", viewTextRaw);
root.put("stateViewIds", stateViewIds);
root.put("stateViewPolicy", stateViewPolicy);
root.put("children", childrenRaw);
root.put("svgChildren", svgChildrenRaw);
try {
result = writeTemplate(root);
} catch (final GenerationException e) {
throw new GeneratorException(e);
}
}
return result;
}
Aggregations