1. generate class University
StoryStepSourceCode.CURRENTPOSITION);
ClassModel model = new ClassModel("org.sdmlib.test.examples.studyrightWithAssignments.model");
Clazz universityClass = model.createClazz("University").withAttribute("name", DataType.STRING);
2. generate class Student
Clazz studentClass = model.createClazz("Student").withAttribute("name", DataType.STRING)
.withAttribute("id", DataType.STRING).withAttribute("assignmentPoints", DataType.INT)
.withAttribute("motivation", DataType.INT).withAttribute("credits", DataType.INT);
3. add University --> Student association
universityClass.withBidirectional(studentClass, "students", Association.MANY, "university", Association.ONE);
code.withEnd(StoryStepSourceCode.CURRENTPOSITION);
4. add University --> Room association
Clazz roomClass = model.createClazz("Room").withAttribute("name", DataType.STRING)
.withAttribute("topic", DataType.STRING).withAttribute("credits", DataType.INT);
roomClass.withMethod("findPath", DataType.STRING, new Parameter(DataType.INT).with("motivation"));
// Association universityToRoom =
universityClass.createBidirectional(roomClass, "rooms", Association.MANY, "university", Association.ONE);
// .with(AssociationTypes.AGGREGATION);
// Association doors =
roomClass.withBidirectional(roomClass, "doors", Association.MANY, "doors", Association.MANY);
// Association studentsInRoom =
studentClass.withBidirectional(roomClass, "in", Association.ONE, "students", Association.MANY);
studentClass.withBidirectional(studentClass, "friends", Association.MANY, "friends", Association.MANY);
5. add assignments:
Clazz assignmentClass = model.createClazz("Assignment").withAttribute("content", DataType.STRING)
.withAttribute("points", DataType.INT)
.withBidirectional(roomClass, "room", Association.ONE, "assignments", Association.MANY);
studentClass.withBidirectional(assignmentClass, "done", Association.MANY, "students", Association.MANY);
6. generate class source files.
// model.generate("src/test/java"); // usually don't specify anything here, then it goes into src
code.withEnd(StoryStepSourceCode.CURRENTPOSITION);