void createDefinitionsIfMissing() {
    EList<EObject> contents = resource.getContents();

    if (contents.isEmpty() || !(contents.get(0) instanceof DocumentRoot)) {
      TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);

      if (domain != null) {
        final DocumentRoot docRoot = FACTORY.createDocumentRoot();
        final Definitions definitions = FACTORY.createDefinitions();
        //				definitions.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(definitions, resource);
        Collaboration collaboration = FACTORY.createCollaboration();
        //				collaboration.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(collaboration, resource);
        Participant participant = FACTORY.createParticipant();
        //				participant.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(participant, resource);
        participant.setName("Internal");
        collaboration.getParticipants().add(participant);
        definitions.getRootElements().add(collaboration);

        domain
            .getCommandStack()
            .execute(
                new RecordingCommand(domain) {
                  @Override
                  protected void doExecute() {
                    docRoot.setDefinitions(definitions);
                    resource.getContents().add(docRoot);
                  }
                });
        return;
      }
    }
  }
 public Participant addParticipant() {
   Collaboration collaboration = getOrCreateCollaboration();
   Participant participant = FACTORY.createParticipant();
   //		participant.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(participant, resource);
   collaboration.getParticipants().add(participant);
   return participant;
 }
 private void addCollaborationToRootElements(
     final List<RootElement> rootElements, final Collaboration collaboration) {
   Participant participant = FACTORY.createParticipant();
   //		participant.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(participant, resource);
   participant.setName("Internal");
   for (RootElement element : rootElements) {
     if (element instanceof Process) {
       participant.setProcessRef((Process) element);
       break;
     }
   }
   collaboration.getParticipants().add(participant);
   rootElements.add(collaboration);
 }