Storyboard BidirectionalModelToTextTransformation

Start: We start with the usual StudyRight object model.

Step 1: Use text templates to generate a natural language description of the object model.

      Template rootTemplate = new Template()
         .withModelObject(uni)
         .with("The example University has 99 rooms and 88 students: \nroomList The students are: \nstudentList ",
            "example", University.PROPERTY_NAME,
            "99", University.PROPERTY_ROOMS + ".size",
            "88", University.PROPERTY_STUDENTS + ".size");

      Template roomTemplate = rootTemplate.createPlaceHolderAndSubTemplate()
         .withReferenceLookup(true)
         .withParent("roomList", University.PROPERTY_ROOMS)
         .with(
            " - The xy room has 42 credits. It is connected to rooms: neighbors",
            "xy", Room.PROPERTY_ROOMNO,
            "42", Room.PROPERTY_CREDITS)
         .withList("", "\n", "\n");

      Template neighborsTemplate = roomTemplate.createPlaceHolderAndSubTemplate()
         .withParent("neighbors", Room.PROPERTY_NEIGHBORS)
         .withReferenceLookup(true)
         .with(
            "name",
            "name", Room.PROPERTY_ROOMNO)
         .withList("", ", ", ".");

      Template studentTemplate = rootTemplate.createPlaceHolderAndSubTemplate()
         .withParent("studentList", University.PROPERTY_STUDENTS)
         .with(
            " - Stud has student number 1234.",
            "Stud", Student.PROPERTY_NAME,
            "1234", Student.PROPERTY_MATRNO)
         .withList("", "\n", "\n");

      storyboard.addObjectDiagram(rootTemplate);

      rootTemplate.generate();

Results in the following text:

The StudyRight University has 5 rooms and 2 students: 
 - The math room has 42 credits. It is connected to rooms: arts, sports.
 - The arts room has 23 credits. It is connected to rooms: math, sports, exam, ProgMeth.
 - The sports room has 23 credits. It is connected to rooms: math, arts, exam.
 - The exam room has 0 credits. It is connected to rooms: sports, arts, ProgMeth.
 - The ProgMeth room has 42 credits. It is connected to rooms: arts, exam.
 The students are: 
 - Tom has student number 4242.
 - Nina has student number 2323.
 

Step 2: Use templates to parse text into object model

      rootTemplate.setExpandedText(
         "The Study False University has many rooms and some students: \n" +
            " - The class diagrams room has 23 credits. It is connected to rooms: laws, business.\n" +
            " - The laws room has 24 credits. It is connected to rooms: class diagrams, business.\n" +
            " - The business room has 3 credits. It is connected to rooms: laws, class diagrams.\n " +
            "The students are: \n" +
            " - Bart has student number 111.\n" +
            " - Meggie has student number 112.\n ");

      rootTemplate.parse();