Java Code Examples for org.stringtemplate.v4.ST#write()

The following examples show how to use org.stringtemplate.v4.ST#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateFeature(AutoIndentWriter writer, Repository repository, FlowType flow,
    ActorType actor) {
  final STGroupFile stFeatureGroup = new STGroupFile("templates/feature.stg");

  ST st = stFeatureGroup.getInstanceOf("feature");
  st.add("repository", repository);
  st.add("flow", flow);
  st.add("actor", actor);
  st.write(writer, errorListener);
  
  repository.getMessages().getMessage().stream()
  .filter(m -> flow.getName().equals(m.getFlow())).forEach(message -> {
    Responses responses = message.getResponses();
    if (responses != null)
      responses.getResponse().forEach(response -> generateFeatureScenario(writer, stFeatureGroup, repository, actor, message, response));
  });
}
 
Example 2
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateGroupDetail(final Path messagesDocPath, final GroupType group) throws Exception {
  final ST stGroupStart;
  stGroupStart = stGroup.getInstanceOf("groupStart");
  stGroupStart.add("groupType", group);
  final FieldType field = getField(group.getNumInGroup().getId().intValue());
  stGroupStart.add("fieldType", field);

  final ST stComponentEnd = stGroup.getInstanceOf("componentEnd");
  final List<Object> members = group.getComponentRefOrGroupRefOrFieldRef();

  final Path path = messagesDocPath.resolve(String.format("%s-%s.html", group.getName(), group.getScenario()));
  try (final STWriterWrapper writer = getWriter(path)) {
    stGroupStart.write(writer, templateErrorListener);
    generateMembers(members, writer);
    stComponentEnd.write(writer, templateErrorListener);
  }
}
 
Example 3
Source File: ImgGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
public void generateUMLStateMachine(Path messagesImgPath, PathManager fileSystemManager, StateMachineType stateMachine,
    STErrorListener errorListener) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  final NoIndentWriter writer = new NoIndentWriter(stringWriter);

  final ST stStates = stGroup.getInstanceOf("stateMachine");
  stStates.add("stateMachine", stateMachine);
  stStates.write(writer, errorListener);

  final String umlString = stringWriter.toString();

  final SourceStringReader reader = new SourceStringReader(umlString);
  final Path path = messagesImgPath.resolve(String.format("%s.png", stateMachine.getName()));
  final OutputStream out = fileSystemManager.getOutputStream(path);
  reader.generateImage(out);
  out.flush();
}
 
Example 4
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateCodeSetDetail(final Path datatypesOutputPath, final CodeSetType codeSet)
    throws Exception {
  final Path path = datatypesOutputPath.resolve(String.format("%s-%s.html", codeSet.getName(), codeSet.getScenario()));
  try (final STWriterWrapper writer = getWriter(path)) {
    final ST stCodesetStart = stGroup.getInstanceOf("codeSetStart");
    stCodesetStart.add("codeSet", codeSet);
    stCodesetStart.write(writer, templateErrorListener);

    final List<CodeType> codeList = codeSet.getCode();
    for (final CodeType code : codeList) {
      final ST stCode = stGroup.getInstanceOf("code");
      stCode.add("code", code);
      stCode.add("supported", supportedMap.get(code.getSupported()));
      stCode.write(writer, templateErrorListener);
    }

    final ST stCodesetEnd = stGroup.getInstanceOf("codeSetEnd");
    stCodesetEnd.add("codeSet", codeSet);
    stCodesetEnd.write(writer, templateErrorListener);
  }
}
 
Example 5
Source File: StateGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateTransitionsEnum(StateMachineType stateMachine, StateType state)
    throws Exception {
  String stateMachineName = stateMachine.getName();
  String stateName = state.getName();
  List<TransitionType> transitions = state.getTransition();
  if (!transitions.isEmpty()) {
    try (final STWriterWrapper writer = getWriter(
        srcPath.resolve(String.format("%s%sTransition.java", stateMachineName, stateName)))) {
      final ST stInterface = stGroup.getInstanceOf("transition_enum");
      stInterface.add("stateMachine", stateMachine);
      stInterface.add("state", state);
      stInterface.add("package", this.srcPackage);
      stInterface.write(writer, templateErrorListener);
    }
  }
}
 
Example 6
Source File: StateGenerator.java    From fix-orchestra with Apache License 2.0 6 votes vote down vote up
private void generateStateMachineClass(StateMachineType stateMachine) throws Exception {
  String name = stateMachine.getName();
  try (final STWriterWrapper writer =
      getWriter(srcPath.resolve(String.format("%sStateMachine.java", name)))) {
    final ST stInterface1 = stGroup.getInstanceOf("stateMachinePart1");
    stInterface1.add("stateMachine", stateMachine);
    stInterface1.add("package", this.srcPackage);
    stInterface1.write(writer, templateErrorListener);
    StateType initial = stateMachine.getInitial();
    generateStateCase(stateMachine, writer, initial);
    List<StateType> states = stateMachine.getState();
    for (StateType state : states) {
      generateStateCase(stateMachine, writer, state);
    }
    final ST stInterface2 = stGroup.getInstanceOf("stateMachinePart2");
    stInterface2.add("stateMachine", stateMachine);
    stInterface2.write(writer, templateErrorListener);
  }
}
 
Example 7
Source File: CodeGenerator.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void write(ST code, String fileName) {
		try {
//			long start = System.currentTimeMillis();
			Writer w = tool.getOutputFileWriter(g, fileName);
			STWriter wr = new AutoIndentWriter(w);
			wr.setLineWidth(lineWidth);
			code.write(wr);
			w.close();
//			long stop = System.currentTimeMillis();
		}
		catch (IOException ioe) {
			tool.errMgr.toolError(ErrorType.CANNOT_WRITE_FILE,
								  ioe,
								  fileName);
		}
	}
 
Example 8
Source File: StateGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateStatesEnum(StateMachineType stateMachine) throws Exception {
  String name = stateMachine.getName();
  try (
      final STWriterWrapper writer = getWriter(srcPath.resolve(String.format("%s.java", name)))) {
    final ST stInterface = stGroup.getInstanceOf("state_enum");
    stInterface.add("stateMachine", stateMachine);
    stInterface.add("package", this.srcPackage);
    stInterface.write(writer, templateErrorListener);
  }
}
 
Example 9
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateResponses(final List<ResponseType> responseList, final STWriter writer) {
  for (final ResponseType response : responseList) {
    final List<Object> responses = response.getMessageRefOrAssignOrTrigger();
    for (final Object responseRef : responses) {
      if (responseRef instanceof MessageRefType) {
        final MessageRefType messageRef = (MessageRefType) responseRef;
        final ST st = stGroup.getInstanceOf("messageResponse");
        st.add("message", messageRef.getName());
        st.add("scenario", messageRef.getScenario());
        st.add("when", response.getWhen());
        st.write(writer, templateErrorListener);
      }
    }
  }
}
 
Example 10
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateMessageDetail(final Path messagesDocPath, final Path messagesImgPath,
                                   final MessageType message) throws Exception {
  final ST stMessageStart = stGroup.getInstanceOf("messageStart");
  final ST stMessagePart2 = stGroup.getInstanceOf("messagePart2");
  final ST stMessageEnd = stGroup.getInstanceOf("messageEnd");
  stMessageStart.add("message", message);
  stMessagePart2.add("message", message);
  stMessageEnd.add("message", message);

  List<ResponseType> responses = null;
  final Responses responses2 = message.getResponses();
  if (responses2 != null) {
    responses = responses2.getResponse();
  }
  final List<Object> members = message.getStructure().getComponentRefOrGroupRefOrFieldRef();

  final Path path = messagesDocPath
      .resolve(String.format("%s-%s.html", message.getName(), message.getScenario()));
  try (final STWriterWrapper writer = getWriter(path)) {
    stMessageStart.write(writer, templateErrorListener);
    if (responses != null) {
      generateResponses(responses, writer);
    }

    stMessagePart2.write(writer, templateErrorListener);
    generateMembers(members, writer);
    stMessageEnd.write(writer, templateErrorListener);
  }

  if (responses != null) {
    final FlowType flow = getFlow(message.getFlow());
    imgGenerator.generateUMLSequence(messagesImgPath, pathManager, message, flow, responses,
        templateErrorListener);
  }
}
 
Example 11
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateActorsList(final Path messagesDocPath, final List<ActorType> actorList)
    throws Exception {
  final ST st = stGroup.getInstanceOf("actors");
  st.add("actors", actorList);
  st.add("title", "All Actors");
  final Path path = messagesDocPath.resolve("AllActors.html");
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 12
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateAllComponentsList(final Path messagesDocPath, final List<ComponentType> componentList)
    throws Exception {
  final ST st = stGroup.getInstanceOf("components");
  st.add("components", componentList);
  st.add("title", "All Components");
  final Path path = messagesDocPath.resolve("AllComponents.html");
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 13
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateAllGroupsList(final Path messagesDocPath, final List<GroupType> componentList)
    throws Exception {
  final ST st = stGroup.getInstanceOf("groups");
  st.add("groups", componentList);
  st.add("title", "All Groups");
  final Path path = messagesDocPath.resolve("AllGroups.html");
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 14
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateMessageListByCategory(final Path messagesDocPath, final CategoryType category,
                                           final List<MessageType> messageList) throws Exception {
  final ST st = stGroup.getInstanceOf("messages");
  final List<MessageType> filteredMessageList = messageList.stream()
      .filter(m -> category.getName().equals(m.getCategory())).collect(Collectors.toList());
  st.add("messages", filteredMessageList);
  st.add("title", String.format("%s Messages", category.getName()));
  final Path path = messagesDocPath.resolve(String.format("%sMessages.html", category.getName()));
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 15
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateCategories(final Path messagesDocPath, final String title,
                                final List<CategoryType> categoriesList) throws Exception {
  final ST st = stGroup.getInstanceOf("categories");
  st.add("title", title);
  st.add("categories", categoriesList);
  final Path path = messagesDocPath.resolve("MessageCategories.html");
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 16
Source File: StateGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateObjectInterface(StateMachineType stateMachine) throws Exception {
  String name = stateMachine.getName();
  try (final STWriterWrapper writer =
      getWriter(srcPath.resolve(String.format("Has%s.java", name)))) {
    final ST stInterface = stGroup.getInstanceOf("has_interface");
    stInterface.add("stateMachine", stateMachine);
    stInterface.add("package", this.srcPackage);
    stInterface.write(writer, templateErrorListener);
  }
}
 
Example 17
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateCodeSetList(final Path datatypesOutputPath, final List<CodeSetType> codeSetList)
    throws Exception {
  final ST st = stGroup.getInstanceOf("codeSets");
  st.add("codeSets", codeSetList);
  st.add("title", "All Code Sets");
  final Path path = datatypesOutputPath.resolve("AllCodeSets.html");
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 18
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateComponentDetail(final Path messagesDocPath, final ComponentType component)
    throws Exception {
  final ST stComponentStart;
  stComponentStart = stGroup.getInstanceOf("componentStart");
  stComponentStart.add("component", component);
  final ST stComponentEnd = stGroup.getInstanceOf("componentEnd");
  final List<Object> members = component.getComponentRefOrGroupRefOrFieldRef();

  final Path path = messagesDocPath.resolve(String.format("%s-%s.html", component.getName(), component.getScenario()));
  try (final STWriterWrapper writer = getWriter(path)) {
    stComponentStart.write(writer, templateErrorListener);
    generateMembers(members, writer);
    stComponentEnd.write(writer, templateErrorListener);
  }
}
 
Example 19
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateMessageListByFlow(final Path messagesDocPath, final FlowType flow,
                                       final List<MessageType> messageList) throws Exception {
  final ST st = stGroup.getInstanceOf("messages");
  final List<MessageType> filteredMessageList = messageList.stream()
      .filter(m -> flow.getName().equals(m.getFlow())).collect(Collectors.toList());
  st.add("messages", filteredMessageList);
  st.add("title", String.format("%s Messages", flow.getName()));
  final Path path = messagesDocPath.resolve(String.format("%sMessages.html", flow.getName()));
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}
 
Example 20
Source File: DocGenerator.java    From fix-orchestra with Apache License 2.0 5 votes vote down vote up
private void generateFlowsList(final Path messagesDocPath, final List<FlowType> flowList) throws Exception {
  final ST st = stGroup.getInstanceOf("flows");
  st.add("flows", flowList);
  st.add("title", "All Flows");
  final Path path = messagesDocPath.resolve("AllFlows.html");
  try (final STWriterWrapper writer = getWriter(path)) {
    st.write(writer, templateErrorListener);
  }
}