private void generateCode(Writer modelCodeWriter) throws IOException, TemplateException { Map<String, Object> modelProperties = Maps.newHashMap(); List<Map<String, Object>> eventList = Lists.newLinkedList(); modelProperties.put("modelName", modelName); modelProperties.put("events", eventList); modelProperties.put("variables", variableList); for (Event event : events) { EventBuilder eventBuilder = new EventBuilder(); Event.EventState eventState = event.getEventState(); Event.Function eventFunctionMatcher = new Event.Function(eventState.getFunctionBody()); eventFunctionMatcher.process(); eventBuilder.setName(eventState.getName()); eventBuilder.setParameters(eventFunctionMatcher.getParameters()); eventBuilder.setBody(eventFunctionMatcher.getBody()); for (Map.Entry<Event, List<Edge>> targetEntry : adjacencyList.row(event).entrySet()) { List<Edge> edges = targetEntry.getValue(); for (Edge edge : edges) { eventBuilder.addEdge(edge); } } eventList.add(eventBuilder.asMap()); } Templates templatesInstance = Templates.getTemplatesInstance(); Configuration templateConfiguration = templatesInstance.getConfiguration(); Template modelTemplate = templateConfiguration.getTemplate("Simulation.java.ftl"); modelTemplate.process(modelProperties, modelCodeWriter); }