private List<MemberModel> getListOfConditionalStatements( URI stmtURI, Resource modelRes, Resource instanceRes, Map<Resource, ArtifactFragment> instanceRes2AFMap, ReloRdfRepository repo) throws Exception { StatementIterator stmtIter = repo.getStatements(modelRes, stmtURI, null); List<MemberModel> retStmts = new ArrayList<MemberModel>(); while (stmtIter.hasNext()) { Value obj = stmtIter.next().getObject(); // if (!(obj instanceof Resource) || repo.getStatement((Resource)obj, RSECore.model, // null)==null) // throw new Exception("Child resource not found for parent resource: "+ // instanceRes.toString()); MemberModel model = (MemberModel) checkMapforRes(instanceRes2AFMap, obj, instanceRes); if (model != null) { if (stmtURI == RSECore.thenStmt && !(model instanceof MethodInvocationModel)) continue; else retStmts.add(model); } } return retStmts; }
private void addSavedControlFlows( ArtifactFragment parent, Resource parentRes, Map<Resource, ArtifactFragment> instanceRes2AFMap, ReloRdfRepository repo) { StatementIterator containeeIter = repo.getStatements(parentRes, RSECore.contains, null); while (containeeIter.hasNext()) { try { Value obj = containeeIter.next().getObject(); if (!(obj instanceof Resource) || repo.getStatement((Resource) obj, RSECore.model, null) == null) throw new Exception( "Child resource not found for parent resource: " + parentRes.toString()); Resource instanceRes = (Resource) obj; Resource modelRes = (Resource) repo.getStatement(instanceRes, RSECore.model, null).getObject(); Resource type = new Artifact(modelRes).queryType(repo); if (type == null) // if this is a comment try to get the type from the repo type = (Resource) repo.getStatement(modelRes, repo.rdfType, null).getObject(); if (RSECore.controlFlowType.equals(type)) addControlFlowModel( parent, instanceRes, modelRes, instanceRes2AFMap, repo, (DiagramModel) this.getModel()); } catch (Exception e) { logger.error("Error while adding saved containee.\n", e); } } refreshChildren(); }
private void addSavedContainee( ArtifactFragment parent, Resource parentRes, Map<Resource, ArtifactFragment> instanceRes2AFMap, ReloRdfRepository repo) { StatementIterator containeeIter = repo.getStatements(parentRes, RSECore.contains, null); while (containeeIter.hasNext()) { try { Value obj = containeeIter.next().getObject(); if (!(obj instanceof Resource) || repo.getStatement((Resource) obj, RSECore.model, null) == null) throw new Exception( "Child resource not found for parent resource: " + parentRes.toString()); Resource instanceRes = (Resource) obj; Resource modelRes = (Resource) repo.getStatement(instanceRes, RSECore.model, null).getObject(); Resource type = new Artifact(modelRes).queryType(repo); if (type == null) // if this is a comment try to get the type from the repo type = (Resource) repo.getStatement(modelRes, repo.rdfType, null).getObject(); boolean isUserCreated = false; if (type == null) throw new Exception( "Type is Null for model resource: " + modelRes.toString() + "\nParent Resource: " + instanceRes.toString()); else { Value val = repo.getStatement(modelRes, RSECore.userCreated, null).getObject(); if (val != null) isUserCreated = true; } if (RSECore.commentType.equals(type)) { addSavedCommentRes((DiagramModel) parent, instanceRes, instanceRes2AFMap, repo); } else if (isUserCreated) { addSavedUserCreatedNodes(parent, instanceRes, modelRes, instanceRes2AFMap, repo); } else if (RSECore.controlFlowType.equals(type)) { continue; // addControlFlowModel(parent, instanceRes, modelRes, instanceRes2AFMap, repo, // (DiagramModel) this.getModel()); } else { addSavedCodeRes(parent, instanceRes, instanceRes2AFMap, repo); } } catch (Exception e) { logger.error("Error while adding saved containee.\n", e); } } refreshChildren(); }
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(); }
private void addControlFlowModel( ArtifactFragment parent, Resource instanceRes, Resource modelRes, Map<Resource, ArtifactFragment> instanceRes2AFMap, ReloRdfRepository repo, DiagramModel diagramModel) throws Exception { Statement cfLabelStmt = repo.getStatement(modelRes, RSECore.name, null); Statement cfType = repo.getStatement(modelRes, RSECore.controlFlowName, null); ControlFlowModel cfModel = null; String cfTypeString = cfType.getObject().toString(); if (cfTypeString.equals(RSECore.ifBlock.toString())) { cfModel = new IfBlockModel(diagramModel, cfLabelStmt.getObject().toString()); ((IfBlockModel) cfModel) .addElseIfStmts( cfTypeString, getListOfConditionalStatements( RSECore.ifStmt, modelRes, instanceRes, instanceRes2AFMap, repo)); ((IfBlockModel) cfModel) .setElseStmts( getListOfConditionalStatements( RSECore.elseStmt, modelRes, instanceRes, instanceRes2AFMap, repo)); ((IfBlockModel) cfModel) .setThenStmts( getListOfConditionalStatements( RSECore.thenStmt, modelRes, instanceRes, instanceRes2AFMap, repo)); } else if (cfTypeString.equals(RSECore.loopBlock.toString())) { cfModel = new LoopBlockModel(diagramModel, cfLabelStmt.getObject().toString()); ((LoopBlockModel) cfModel) .setLoopStmts( getListOfConditionalStatements( RSECore.loopStmt, modelRes, instanceRes, instanceRes2AFMap, repo)); } else if (cfTypeString.equals(RSECore.userControlBlock.toString())) { cfModel = new UserCreatedControlFlowModel(diagramModel, cfLabelStmt.getObject().toString()); ((UserCreatedControlFlowModel) cfModel) .setStatements( getListOfConditionalStatements( RSECore.conditionalStmt, modelRes, instanceRes, instanceRes2AFMap, repo)); } if (parent instanceof DiagramModel) { diagramModel.addChildToConditionalLayer(cfModel); } else if (parent instanceof ControlFlowModel) { ((ControlFlowModel) parent).addInnerConditionalModel(cfModel); cfModel.setOuterConditionalModel((ControlFlowModel) parent); diagramModel.firePropertyChange(NodeModel.PROPERTY_CONDITIONAL_CHILDREN, null, cfModel); } StatementIterator containeeIter = repo.getStatements(modelRes, RSECore.contains, null); while (containeeIter.hasNext()) { Value obj = containeeIter.next().getObject(); if (!(obj instanceof Resource) || repo.getStatement((Resource) obj, RSECore.model, null) == null) throw new Exception( "Child resource not found for parent resource: " + instanceRes.toString()); Resource childInstanceRes = (Resource) obj; addControlFlowModel( cfModel, instanceRes, childInstanceRes, instanceRes2AFMap, repo, diagramModel); } // if(instanceModel!=null) // instanceModel.setInstanceRes(instanceRes); // else // logger.error("Could not create Instance model for resource: " + detailsRes.toString()); }