Пример #1
0
 private UmlMethod GetMethod(String aux, UmlSequenceDiagram sequenceDiagram)
 {
     foreach (UmlClass sdClass in sequenceDiagram.UmlObjects.OfType <UmlClass> ())
     {
         foreach (UmlMethod method in sdClass.Methods)
         {
             if (method.Id.Equals(aux))
             {
                 return(method);
             }
         }
     }
     return(null);
 }
Пример #2
0
        private GeneralUseStructure FromXmi(XmlDocument document, ref String name)
        {
            UmlModel            model = new UmlModel();
            XmlNamespaceManager ns    = new XmlNamespaceManager(document.NameTable);

            ns.AddNamespace("JUDE", "http://objectclub.esm.co.jp/Jude/namespace/");
            ns.AddNamespace("UML", "org.omg.xmi.namespace.UML");
            List <UmlClass>    classes         = new List <UmlClass> ();
            List <String>      pairs           = new List <String> ();
            UmlSequenceDiagram sequenceDiagram = null;

            foreach (XmlNode classNode in document.SelectNodes("//UML:Namespace.ownedElement//UML:Class[@xmi.id]", ns))
            {
                UmlClass sdClass = new UmlClass();
                sdClass.Id   = classNode.Attributes["xmi.id"].Value;
                sdClass.Name = classNode.Attributes["name"].Value;

                foreach (XmlNode operationNode in classNode.SelectNodes("//UML:Class[@xmi.id='" + sdClass.Id + "']//UML:Operation[@xmi.id]", ns))
                {
                    UmlMethod method = new UmlMethod();
                    method.Id       = operationNode.Attributes["xmi.id"].Value;
                    method.Name     = operationNode.Attributes["name"].Value;
                    method.Abstract = Boolean.Parse(operationNode.Attributes["isAbstract"].Value);

                    #region Visibility - VERIFICAR QUAL É O CORRETO
                    foreach (XmlNode modelElementVisibilityNode in operationNode.SelectNodes("//UML:Class[@xmi.id='" + sdClass.Id + "']//UML:Operation[@xmi.id='" + method.Id + "']//UML:ModelElement.visibility", ns))
                    {
                        method.Visibility = modelElementVisibilityNode.Attributes["xmi.value"].Value;
                    }

                    foreach (XmlNode featureVisibilityNode in operationNode.SelectNodes("//UML:Class[@xmi.id='" + sdClass.Id + "']//UML:Operation[@xmi.id='" + method.Id + "']//UML:Feature.visibility", ns))
                    {
                        method.Visibility = featureVisibilityNode.Attributes["xmi.value"].Value;
                    }
                    #endregion

                    foreach (XmlNode parameterNode in operationNode.SelectNodes("//UML:Class[@xmi.id='" + sdClass.Id + "']//UML:Operation[@xmi.id='" + method.Id + "']//UML:BehavioralFeature.parameter//UML:Parameter", ns))
                    {
                        UmlMethodParam methodParam = new UmlMethodParam();
                        methodParam.Id   = parameterNode.Attributes["xmi.id"].Value;
                        methodParam.Name = parameterNode.Attributes["name"].Value;
                        methodParam.Kind = parameterNode.Attributes["kind"].Value;

                        foreach (XmlNode parameterTypeClassifierNode in parameterNode.SelectNodes("//UML:Parameter[@xmi.id='" + methodParam.Id + "']//UML:Classifier", ns))
                        {
                            String aux = parameterTypeClassifierNode.Attributes["xmi.idref"].Value;
                            methodParam.Type = GetParamType(document, ns, aux);
                        }
                        method.Params.Add(methodParam);
                    }
                    sdClass.Methods.Add(method);
                }
                classes.Add(sdClass);
            }

            XmlNodeList sequenceDiagramNodeList = document.SelectNodes("//UML:Namespace.collaboration//UML:Collaboration[@xmi.id]", ns);

            foreach (XmlNode sequenceDiagramNode in sequenceDiagramNodeList)
            {
                sequenceDiagram    = new UmlSequenceDiagram();
                sequenceDiagram.Id = sequenceDiagramNode.Attributes["xmi.id"].Value;
                model.AddDiagram(sequenceDiagram);
                String pair = "";

                foreach (XmlNode classifierRoleNode in sequenceDiagramNode.SelectNodes("//UML:ClassifierRole[@xmi.id]", ns))
                {
                    String aux = classifierRoleNode.Attributes["xmi.id"].Value;
                    pair  = classifierRoleNode.Attributes["xmi.id"].Value;
                    pair += "#";

                    foreach (XmlNode classifierRoleBaseNode in classifierRoleNode.SelectNodes("//UML:ClassifierRole[@xmi.id='" + aux + "']//UML:ClassifierRole.base//UML:Classifier[@xmi.idref]", ns))
                    {
                        pair += classifierRoleBaseNode.Attributes["xmi.idref"].Value;
                    }
                    pairs.Add(pair);
                }
            }

            foreach (UmlClass sdClass in classes)
            {
                foreach (String pair in pairs)
                {
                    String[] splitted = pair.Split('#');
                    if (sdClass.Id.Equals(splitted[1]))
                    {
                        sdClass.IdRef = splitted[0];
                        break;
                    }
                }
                foreach (UmlMethod method in sdClass.Methods)
                {
                    sequenceDiagram.UmlObjects.Add(method);
                    foreach (UmlMethodParam param in method.Params)
                    {
                        sequenceDiagram.UmlObjects.Add(param);
                    }
                }
                sequenceDiagram.UmlObjects.Add(sdClass);
            }

            foreach (UmlSequenceDiagram sequenceDiagramAux in model.Diagrams.OfType <UmlSequenceDiagram> ())
            {
                XmlNodeList messageNodeList = document.SelectNodes("//UML:Namespace.collaboration//UML:Collaboration[@xmi.id='" + sequenceDiagramAux.Id + "']//UML:Message[@xmi.id]", ns);
                foreach (XmlNode messageNode in messageNodeList)
                {
                    UmlMessage message  = new UmlMessage();
                    String     storedID = "";
                    message.Id   = messageNode.Attributes["xmi.id"].Value;
                    message.Name = messageNode.Attributes["name"].Value;

                    foreach (XmlNode taggedValuesNode in messageNode.SelectNodes("//UML:Message[@xmi.id='" + message.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue", ns))
                    {
                        String tagName  = (taggedValuesNode.Attributes["tag"].Value).ToUpper();
                        String tagValue = HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value);
                        message.SetTaggedValue(tagName, tagValue);
                    }

                    foreach (XmlNode senderNode in messageNode.SelectNodes("//UML:Message[@xmi.id='" + message.Id + "']//UML:Message.sender//UML:ClassifierRole[@xmi.idref]", ns))
                    {
                        message.Sender = (from c in sequenceDiagramAux.UmlObjects.OfType <UmlClass> () where c.IdRef.Equals(senderNode.Attributes["xmi.idref"].Value) select c).FirstOrDefault();
                        break;
                    }

                    foreach (XmlNode receiverNode in messageNode.SelectNodes("//UML:Message[@xmi.id='" + message.Id + "']//UML:Message.receiver//UML:ClassifierRole[@xmi.idref]", ns))
                    {
                        message.Receiver = (from c in sequenceDiagramAux.UmlObjects.OfType <UmlClass> () where c.IdRef.Equals(receiverNode.Attributes["xmi.idref"].Value) select c).FirstOrDefault();
                        break;
                    }

                    foreach (XmlNode actionNode in messageNode.SelectNodes("//UML:Message[@xmi.id='" + message.Id + "']//UML:Message.action//UML:Action[@xmi.id]", ns))
                    {
                        storedID = "";
                        try {
                            storedID           = actionNode.Attributes["xmi.id"].Value;
                            message.ActionType = Convert.ToInt32(actionNode.Attributes["actionType"].Value);
                        } catch {
                        }
                        foreach (XmlNode operationNode in actionNode.SelectNodes("//UML:Action[@xmi.id='" + storedID + "']//UML:Operation", ns))
                        {
                            String aux = operationNode.Attributes["xmi.idref"].Value;
                            message.Method = GetMethod(aux, sequenceDiagram);
                        }
                    }

                    foreach (XmlNode judeMessagePresentation in document.SelectNodes("//JUDE:MessagePresentation[@index]", ns))
                    {
                        String idAux = judeMessagePresentation.Attributes["xmi.id"].Value;
                        foreach (XmlNode umlMessageNode in judeMessagePresentation.SelectNodes("//JUDE:MessagePresentation[@xmi.id='" + idAux + "']//JUDE:UPresentation.semanticModel//UML:Message[@xmi.idref='" + message.Id + "']", ns))
                        {
                            String aux2 = "";
                            try {
                                aux2 = judeMessagePresentation.Attributes["index"].Value;
                            } catch {
                            }
                            decimal index = decimal.Parse(aux2, new CultureInfo("en-US"));
                            message.Index = Convert.ToDouble(index);
                            break;
                        }
                    }
                    sequenceDiagramAux.UmlObjects.Add(message);
                }
            }
            return(model);
        }
Пример #3
0
        private DirectedGraph SequenceDiagramToGraph(UmlSequenceDiagram sequenceDiagram)
        {
            DirectedGraph graph  = new DirectedGraph(sequenceDiagram.Name);
            Boolean       isRoot = false;

            foreach (UmlMessage message in sequenceDiagram.UmlObjects.OfType <UmlMessage> ())
            {
                if (message.ActionType.Equals(2))
                {
                    //continue;
                }
                Node sender   = (from Node node in graph.Nodes where node.Name.Equals(message.Sender.Name) select node).FirstOrDefault();
                Node receiver = (from Node node in graph.Nodes where node.Name.Equals(message.Receiver.Name) select node).FirstOrDefault();
                if (sender == null)
                {
                    sender = new Node(message.Sender.Name, message.Sender.Id);
                    graph.Nodes.Add(sender);
                }
                if (receiver == null)
                {
                    receiver = new Node(message.Receiver.Name, message.Receiver.Id);
                    graph.Nodes.Add(receiver);
                }

                try {
                    isRoot = message.Index.Equals(1.0);
                } catch {
                }

                if (isRoot)
                {
                    graph.RootNode = sender;
                }

                int  i    = 1;
                Edge edge = new Edge();
                edge.NodeA = sender;
                edge.NodeB = receiver;

                foreach (KeyValuePair <String, String> tag in message.TaggedValues)
                {
                    edge.SetTaggedValue(tag.Key, tag.Value);
                }

                edge.SetTaggedValue("ACTIONTYPE", message.ActionType.ToString());
                edge.SetTaggedValue("INDEX", message.Index.ToString());

                if (!message.ActionType.Equals(2))
                {
                    edge.SetTaggedValue("METHOD", message.Method.Name);
                    edge.SetTaggedValue("METHODABSTRACT", message.Method.Abstract.ToString());

                    foreach (UmlMethodParam methodParam in message.Method.Params)
                    {
                        if (!message.ActionType.Equals(0))
                        {
                            if (methodParam.Kind.Equals("return"))
                            {
                                edge.SetTaggedValue("METHODRETURN", methodParam.Type);
                            }
                        }
                        else
                        {
                            edge.SetTaggedValue("METHODRETURN", "");
                        }
                        edge.SetTaggedValue("METHODPARAM" + i, methodParam.Name);
                        edge.SetTaggedValue("METHODPARAM" + i + "KIND", methodParam.Kind);
                        edge.SetTaggedValue("METHODPARAM" + i + "TYPE", methodParam.Type);
                        i++;
                    }
                    if (!message.ActionType.Equals(2))
                    {
                        edge.SetTaggedValue("METHODPARAMQUANTITY", i.ToString());
                    }
                    else
                    {
                        edge.SetTaggedValue("METHODPARAMQUANTITY", "0");
                    }
                    edge.SetTaggedValue("METHODVISIBILITY", message.Method.Visibility);
                }
                else
                {
                    edge.SetTaggedValue("METHOD", "");
                }

                graph.Edges.Add(edge);
            }
            return(graph);
        }