Ejemplo n.º 1
0
  private void addSavedConnections(
      DiagramModel diagramModel,
      Map<Resource, ArtifactFragment> instanceRes2AFMap,
      ReloRdfRepository repo) {
    Map<Resource, ArtifactRel> instanceRes2CommentRelMap = new HashMap<Resource, ArtifactRel>();

    StatementIterator connectionsIter = repo.getStatements(null, repo.rdfType, RSECore.link);
    while (connectionsIter.hasNext()) {
      try {
        Resource connRes = connectionsIter.next().getSubject();
        if (connRes == null) throw new Exception("Resource of model is NULL.");

        URI linkRes = (URI) repo.getStatement(connRes, RSECore.model, null).getObject();
        ArtifactRel artRel = PluggableTypes.getAR(linkRes);
        if (artRel instanceof NamedRel) {
          // Source and/or target of connection is a comment
          ArtifactRel.readRDF(
              diagramModel, repo, connRes, instanceRes2AFMap, instanceRes2CommentRelMap);
          continue;
        }

        // Source and target of connection are members

        // connRes is like node15vfsf791x41, which will fail the NameGuesser's
        // RJCore.isJDTWksp(res) test, resulting in a null/"" guessed name.
        // Instead, we need to query the repo for the connection's name
        // statement that was explicitly written in the saved file
        String message;
        Statement stmt = repo.getStatement(connRes, RSECore.name, null);
        if (stmt != null && stmt.getObject() != null) message = stmt.getObject().toString();
        else message = repo.queryName(connRes);
        if (message == null) logger.error("Message null for connection " + connRes);

        Value connTypeVal = repo.getStatement(connRes, RSECore.model, null).getObject();
        if (!(connTypeVal instanceof URI))
          throw new Exception(
              "Could not get type (call or return) "
                  + "for connection resource:"
                  + connRes.toString());
        URI connType = (URI) connTypeVal;

        ArtifactFragment srcAF =
            instanceRes2AFMap.get(repo.getStatement(connRes, repo.rdfSubject, null).getObject());
        ArtifactFragment tgtAF =
            instanceRes2AFMap.get(repo.getStatement(connRes, repo.rdfObject, null).getObject());
        //				if(!(srcAF instanceof MemberModel))
        //					throw new Exception("Could not get source model of connection:"+connRes.toString());
        //				if(!(tgtAF instanceof MemberModel))
        //					throw new Exception("Could not get target model of connection:"+connRes.toString());
        //
        //				MemberModel sourceModel = (MemberModel) srcAF;
        //				MemberModel targetModel = (MemberModel) tgtAF;
        //
        //				ConnectionUtil.createConnection(message, sourceModel, targetModel, connType);
        if (srcAF == null || tgtAF == null) {
          logger.error(
              "Cannot create connection. Invalid Source/target for resource: "
                  + connRes
                  + " ::"
                  + message
                  + "\nSource: "
                  + srcAF
                  + "\nTarget: "
                  + tgtAF);
        }
        ConnectionUtil.createConnection(message, srcAF, tgtAF, connType);

      } catch (Exception e) {
        logger.error("Error while creating connection\n", e);
      }
    }
    connectionsIter.close();
  }