Exemplo n.º 1
0
 /**
  * 生成模型关联关系拓扑图数据
  *
  * @return 拓扑图数据
  */
 private String getModelRelationXml(List<ModelRelation> list) {
   Document doc = null;
   try {
     doc = XmlUtil.parseString("<Graph/>");
   } catch (DocumentException e) {
     // 此处不可能发生
     e.printStackTrace();
     return "";
   }
   IModelService ms = ServiceManager.getModelService();
   Map<String, Model> map = new HashMap<String, Model>();
   for (int i = 0; i < list.size(); i++) {
     ModelRelation mr = list.get(i);
     Model m1 = ms.getModelById(mr.getModelId());
     Model m2 = ms.getModelById(mr.getModelId2());
     map.put(m1.getId(), m1);
     map.put(m2.getId(), m2);
   }
   Model[] models = map.values().toArray(new Model[] {});
   for (int i = 0; i < models.length; i++) {
     Model m = models[i];
     Element el = doc.getRootElement().addElement("Node");
     el.addAttribute("id", m.getId());
     el.addAttribute("name", m.getName());
     el.addAttribute("nodeIcon", "" + m.getLargeIcon());
     el.addAttribute("nodeSize", "32");
   }
   for (int i = 0; i < list.size(); i++) {
     ModelRelation mr = list.get(i);
     Element el = doc.getRootElement().addElement("Edge");
     el.addAttribute("fromID", mr.getModelId());
     el.addAttribute("toID", mr.getModelId2());
     el.addAttribute("edgeLabel", getRelationDefineById(mr.getRelationId()).getName());
   }
   return XmlUtil.getXmlString(doc);
 }