コード例 #1
0
 public static UmlTransition getTransition(UmlElement act)
 {
     foreach (UmlActivityDiagram actDiagram in model2.Diagrams.OfType <UmlActivityDiagram>())
     {
         foreach (UmlTransition t in actDiagram.UmlObjects.OfType <UmlTransition>())
         {
             if (t.Source.Id.Equals(act.Id))
             {
                 return(t);
             }
         }
     }
     return(null);
 }
コード例 #2
0
        /// <summary>
        /// Remove forks and joins of diagram
        /// </summary>
        /// <param name="diagram">targeted diagram to remove fork/join nodes from</param>
        /// <param name="transitions">transitions to be searched and replaced</param>
        private static void RemoveForks(ref UmlActivityDiagram diagram, ref List <UmlTransition> transitions)
        {
            List <UmlFork> forks = (from t in transitions
                                    where t.Target is UmlFork
                                    select(UmlFork) t.Target).Distinct().ToList();

            foreach (UmlFork fork in forks)
            {
                List <UmlTransition> forkLeafs      = transitions.Where(x => x.Source.Equals(fork)).ToList();
                List <UmlTransition> newTransitions = new List <UmlTransition>();
                UmlElement           s = transitions.Where(x => x.Target.Equals(fork)).FirstOrDefault().Source;
                UmlElement           t = null;
                UmlTransition        tran;
                for (int i = 0; i < forkLeafs.Count; i++)
                {
                    t           = forkLeafs[i].Target;
                    tran        = new UmlTransition();
                    tran.Source = s;
                    tran.Target = t;
                    foreach (KeyValuePair <String, String> tag in forkLeafs[i].TaggedValues)
                    {
                        tran.TaggedValues.Add(tag.Key, tag.Value);
                    }
                    tran.TaggedValues.Add("TDPARALELLSTATE", "true");
                    newTransitions.Add(tran);
                    s = t;
                }
                UmlTransition toJoin   = transitions.Where(x => x.Source.Equals(s) && x.Target is UmlJoin).FirstOrDefault();
                UmlJoin       join     = (UmlJoin)toJoin.Target;
                UmlTransition fromJoin = transitions.Where(x => x.Source.Equals(join)).FirstOrDefault();
                tran = new UmlTransition();
                foreach (KeyValuePair <String, String> tag in fromJoin.TaggedValues)
                {
                    tran.TaggedValues.Add(tag.Key, tag.Value);
                }
                tran.Source = s;
                tran.Target = fromJoin.Target;
                newTransitions.Add(tran);

                transitions.RemoveAll(x => x.Target.Equals(fork) || x.Source.Equals(fork));
                transitions.RemoveAll(x => x.Target.Equals(join) || x.Source.Equals(join));
                diagram.UmlObjects.Remove(fork);
                diagram.UmlObjects.Remove(join);
                transitions.AddRange(newTransitions);
            }
        }
コード例 #3
0
        /// <summary>
        /// Remove decisions/merge nodes of diagram
        /// </summary>
        /// <param name="diagram">targeted diagram to remove decision/merge nodes from</param>
        /// <param name="transitions">transitions to be searched and replaced</param>
        private static void RemoveDecisions(ref UmlActivityDiagram diagram, ref List <UmlTransition> transitions)
        {
            List <UmlDecision> decs = (from t in transitions
                                       where t.Target is UmlDecision
                                       select(UmlDecision) t.Target).Distinct().ToList();

            while (decs.Count > 0)
            {
                foreach (UmlDecision decision in decs)
                {
                    List <UmlTransition> decisionProspects = transitions.Where(x => x.Source.Equals(decision)).ToList();
                    List <UmlTransition> newTransitions    = new List <UmlTransition>();
                    List <UmlTransition> Ss = transitions.Where(x => x.Target.Equals(decision)).ToList();

                    foreach (UmlTransition sT in Ss)
                    {
                        UmlElement    s = sT.Source;
                        UmlElement    t = null;
                        UmlTransition tran;

                        for (int i = 0; i < decisionProspects.Count; i++)
                        {
                            t           = decisionProspects[i].Target;
                            tran        = new UmlTransition();
                            tran.Source = s;
                            tran.Target = t;
                            foreach (KeyValuePair <string, string> tag in decisionProspects[i].TaggedValues)
                            {
                                tran.TaggedValues.Add(tag.Key, tag.Value);
                            }
                            //tran.TaggedValues.Add("TDParalellState", "true");
                            newTransitions.Add(tran);
                            //s = t;
                        }
                    }
                    transitions.RemoveAll(x => x.Target.Equals(decision) || x.Source.Equals(decision));
                    diagram.UmlObjects.Remove(decision);
                    transitions.AddRange(newTransitions);
                }

                decs = (from t in transitions
                        where t.Target is UmlDecision
                        select(UmlDecision) t.Target).Distinct().ToList();
            }
        }
コード例 #4
0
        private void OrderActDiagramTransitions(UmlActivityDiagram actDiagram)
        {
            List <UmlTransition> orderedTransitions = new List <UmlTransition>();
            UmlElement           initialNode        = actDiagram.UmlObjects.OfType <UmlInitialState>().FirstOrDefault();
            UmlTransition        initialTransition  = (actDiagram.UmlObjects.OfType <UmlTransition>().Where(x => x.Source.Equals(initialNode))).FirstOrDefault();
            UmlElement           actual             = initialTransition.Target;

            orderedTransitions.Add(initialTransition);

            for (int i = 0; i < actDiagram.UmlObjects.OfType <UmlTransition>().ToList().Count(); i++)
            {
                UmlTransition transition = (actDiagram.UmlObjects.OfType <UmlTransition>().Where(x => x.Source.Equals(orderedTransitions[i].Target))).FirstOrDefault();
                if (transition != null)
                {
                    orderedTransitions.Add(transition);
                }
            }

            actDiagram.UmlObjects.RemoveAll(IsTransition);
            actDiagram.UmlObjects.AddRange(orderedTransitions);
        }
コード例 #5
0
ファイル: UmlToFsm.cs プロジェクト: plets-x1/plets-x1
        /// <summary>
        /// Converts an activity diagram to a finite state machine.
        /// </summary>
        /// <param name="diagram">Diagram to be converted</param>
        /// <param name="model">Parent model of diagram, used to get sub-diagrams</param>
        /// <returns>a FSM of diagram</returns>
        public FiniteStateMachine ActivityDiagramToFsm(UmlActivityDiagram diagram, UmlModel model)
        {
            List <UmlTransition> transitions = diagram.UmlObjects.OfType <UmlTransition> ().ToList();
            List <UmlTransition> newTransitions;
            //FiniteStateMachine fsm = new FiniteStateMachine(diagram.Name);
            FiniteStateMachine fsm = new FiniteStateMachine();
            State   source         = null;
            State   target         = null;
            String  input          = "";
            String  output         = "";
            Boolean haveHiperlinks = true;

            while (haveHiperlinks)
            {
                newTransitions = new List <UmlTransition> ();
                foreach (UmlTransition t in transitions)
                {
                    UmlTransition aux = new UmlTransition();
                    aux = t;
                    List <UmlTransition> hyperlinkTrans = null;
                    if (t.Source.TaggedValues.ContainsKey("jude.hyperlink"))
                    {
                        hyperlinkTrans = GetTransitionsOfDiagram(model, ref aux, hyperLinkType.Source);
                    }
                    if (hyperlinkTrans != null)
                    {
                        newTransitions.AddRange(hyperlinkTrans);
                    }

                    hyperlinkTrans = null;
                    if (t.Target.TaggedValues.ContainsKey("jude.hyperlink"))
                    {
                        hyperlinkTrans = GetTransitionsOfDiagram(model, ref aux, hyperLinkType.Target);
                    }
                    if (hyperlinkTrans != null)
                    {
                        newTransitions.AddRange(hyperlinkTrans);
                    }
                }

                #region new UmlDecision ID - unsuccessful
                List <UmlDecision> ignoreList = new List <UmlDecision> ();
                foreach (UmlTransition newT in newTransitions)
                {
                    UmlElement src = newT.Source;
                    UmlElement trg = newT.Target;
                    if (src is UmlDecision)
                    {
                        if (!ignoreList.Contains(src))
                        {
                            List <UmlDecision> decs = (from t in newTransitions where t.Source.Name.Equals(src.Name) select(UmlDecision) t.Source).Distinct().ToList();
                            decs.AddRange((from t in newTransitions where t.Target.Name.Equals(src.Name) select(UmlDecision) t.Target).Distinct().ToList());

                            String decID = Guid.NewGuid().ToString();
                            foreach (UmlDecision d in decs)
                            {
                                d.Id = decID;
                            }
                            ignoreList.AddRange(decs);
                        }
                    }
                    if (trg is UmlDecision)
                    {
                        if (!ignoreList.Contains(trg))
                        {
                            List <UmlDecision> decs = (from t in newTransitions where t.Target.Name.Equals(trg.Name) select(UmlDecision) t.Target).Distinct().ToList();
                            decs.AddRange((from t in newTransitions where t.Source.Name.Equals(trg.Name) select(UmlDecision) t.Source).Distinct().ToList());

                            String decID = Guid.NewGuid().ToString();
                            foreach (UmlDecision d in decs)
                            {
                                d.Id = decID;
                            }
                            ignoreList.AddRange(decs);
                        }
                    }
                }
                #endregion

                transitions.AddRange(newTransitions);
                transitions = transitions.Distinct().ToList();

                haveHiperlinks = transitions.Where(x => x.Source.TaggedValues.ContainsKey("jude.hyperlink") || x.Target.TaggedValues.ContainsKey("jude.hyperlink")).Count() > 0;
            }

            RemoveForks(ref diagram, ref transitions);
            RemoveDecisions(ref diagram, ref transitions);

            UmlTransition        auxTran = transitions.Where(x => x.Source is UmlInitialState).FirstOrDefault();
            List <UmlTransition> auxList = new List <UmlTransition> ();
            auxList.Add(auxTran);

            for (int i = 0; i < transitions.Count; i++)
            {
                auxTran = transitions.Where(x => x.Source.Equals(auxTran.Target)).FirstOrDefault();
                if (auxTran != null)
                {
                    auxList.Add(auxTran);
                }
            }

            transitions.Clear();
            transitions.AddRange(auxList);

            foreach (UmlTransition t in transitions)
            {
                input     = t.GetTaggedValue("TDACTION");
                source    = new State(t.Source.Name);
                source.Id = t.Source.Id;

                if (input != null)
                {
                    target    = new State(t.Target.Name);
                    target.Id = t.Target.Id;
                    if ((((UmlActionState)t.Target).ParentLane != null) && !String.IsNullOrEmpty(((UmlActionState)t.Target).ParentLane.Name))
                    {
                        target.TaggedValues.Add("Lane", ((UmlActionState)t.Target).ParentLane.Name);
                    }
                    output = "";
                    if (t.GetTaggedValue("TDEXPECTEDRESULT") != null)
                    {
                        output = t.GetTaggedValue("TDEXPECTEDRESULT");
                    }

                    #region Cycles
                    bool cycleTran = false;
                    if (t.GetTaggedValue("TDCYCLETRAN") != null)
                    {
                        cycleTran = (t.GetTaggedValue("TDCYCLETRAN").Equals("true") ? true : false);
                    }
                    bool lastCycleTrans = false;
                    if (t.GetTaggedValue("TDLASTCYCLETRANS") != null)
                    {
                        //lastCycleTrans = (t.GetTaggedValue("TDCYCLETRAN").Equals("true") ? true : false);
                        lastCycleTrans = (t.GetTaggedValue("TDLASTCYCLETRANS").Equals("true") ? true : false);
                    }
                    Transition trans = new Transition(source, target, input, output, cycleTran, lastCycleTrans);
                    if (t.GetTaggedValue("TDLASTCYCLETRANS") != null)
                    {
                        trans.TaggedValues.Add("TDCYCLETRAN", t.GetTaggedValue("TDCYCLETRAN"));
                    }
                    #endregion

                    foreach (KeyValuePair <String, String> pair in t.TaggedValues)
                    {
                        trans.TaggedValues.Add(pair.Key, pair.Value);
                    }
                    //trans.TaggedValues.Add("TDACTION", t.GetTaggedValue("TDACTION"));
                    //trans.TaggedValues.Add("TDEXPECTEDRESULT", t.GetTaggedValue("TDEXPECTEDRESULT") + "");

                    fsm.AddTransition(trans);
                }

                if (t.Target is UmlFinalState)
                {
                    fsm.CheckAsFinal(source);
                }
            }
            fsm = WipeOutOutermost(diagram, fsm);
            fsm.InitialState = GetFsmInitialState(fsm);
            fsm.Name         = diagram.Name;

            return(fsm);
        }
コード例 #6
0
ファイル: UmlToFsm.cs プロジェクト: plets-x1/plets-x1
        /// <summary>
        /// Get all transitions of the desired diagram adjusting the initial and final insertion points using <paramref name="t"/>
        /// </summary>
        /// <param name="model">The model where the diagram is</param>
        /// <param name="t">the transation with hyperlink</param>
        /// <param name="tp">the side where the hyperlink is (source or target)</param>
        /// <returns>a list of the transitions</returns>
        private List <UmlTransition> GetTransitionsOfDiagram(UmlModel model, ref UmlTransition t, hyperLinkType tp)
        {
            List <UmlTransition> subTransitions;
            UmlElement           s;
            String hyperlink = "";
            int    c         = 0;

            if (tp == hyperLinkType.Source)
            {
                if (t.Source.TaggedValues.ContainsKey("cycles"))
                {
                    c = Convert.ToInt32(t.Source.GetTaggedValue("cycles"));
                }
                hyperlink = t.Source.TaggedValues["jude.hyperlink"];
            }
            else
            {
                if (t.Target.TaggedValues.ContainsKey("cycles"))
                {
                    c = Convert.ToInt32(t.Target.GetTaggedValue("cycles"));
                }
                hyperlink = t.Target.TaggedValues["jude.hyperlink"];
            }

            UmlActivityDiagram subDiagram = model.Diagrams.OfType <UmlActivityDiagram> ()
                                            .Where(y => y.Name.Equals(hyperlink))
                                            .FirstOrDefault();

            if (subDiagram == null)
            {
                throw new Exception("Could not find any Activity Diagram named " + hyperlink);
            }

            subTransitions = subDiagram.UmlObjects.OfType <UmlTransition> ().ToList();
            List <UmlTransition> fs = null;
            UmlTransition        f  = null;

            if (tp == hyperLinkType.Source)
            {
                fs = subTransitions.Where(x => x.Target is UmlFinalState).ToList();
                f  = fs.ElementAt(0);
            }
            else
            {
                f = subTransitions.Single(x => x.Source is UmlInitialState);
            }

            if (f != null)
            {
                if (tp == hyperLinkType.Source)
                {
                    s = f.Source;
                    for (int i = 1; i < fs.Count; i++)
                    {
                        UmlTransition temp = fs.ElementAt(i);
                        temp.Target = t.Target;
                        foreach (KeyValuePair <string, string> tag in t.TaggedValues)
                        {
                            if (!temp.TaggedValues.ContainsKey(tag.Key))
                            {
                                temp.TaggedValues.Add(tag.Key, tag.Value);
                            }
                        }
                    }
                }
                else
                {
                    s = f.Target;
                }
                foreach (KeyValuePair <string, string> tag in f.TaggedValues)
                {
                    if (!t.TaggedValues.ContainsKey(tag.Key))
                    {
                        t.TaggedValues.Add(tag.Key, tag.Value);
                    }
                }
                //subTransitions.Remove(f);
            }
            else
            if (tp == hyperLinkType.Source)
            {
                s = subDiagram.UmlObjects.OfType <UmlFinalState> ().FirstOrDefault();
            }
            else
            {
                s = subDiagram.UmlObjects.OfType <UmlInitialState> ().FirstOrDefault();
            }

            UmlTransition initialT = subTransitions.SingleOrDefault(x => x.Source is UmlInitialState);

            subTransitions.RemoveAll(x => x.Target is UmlFinalState);
            subTransitions.RemoveAll(x => x.Source is UmlInitialState);
            if (tp == hyperLinkType.Source)
            {
                t.Source = s;
            }
            else
            {
                t.Target = s;
            }

            #region cycles

            List <UmlTransition> hyperlinkTrans2 = new List <UmlTransition> ();
            if (c > 1)
            {
                List <UmlTransition> temp            = subTransitions;
                UmlElement           firstFirstState = null;
                UmlElement           prevLastState   = null;
                UmlElement           lastSate        = null;
                UmlTransition        lastTran        = null;
                for (int i = 0; i < c; i++)
                {
                    UmlElement currFirstState = null;
                    foreach (UmlTransition trans in temp)
                    {
                        UmlTransition cycleTran = new UmlTransition();
                        UmlElement    src       = (UmlElement)Activator.CreateInstance(trans.Source.GetType());
                        UmlElement    targ      = (UmlElement)Activator.CreateInstance(trans.Target.GetType());
                        if (i != 0)
                        {
                            src.Name  = trans.Source.Name + "_" + i;
                            targ.Name = trans.Target.Name + "_" + i;
                        }
                        else
                        {
                            src.Name  = trans.Source.Name;
                            targ.Name = trans.Target.Name;
                        }
                        src.Id = trans.Source.Id;
                        //src.Id = Guid.NewGuid().ToString();
                        //targ.Name = trans.Target.Name + "_" + i;
                        targ.Id = trans.Target.Id;
                        //targ.Id = Guid.NewGuid().ToString();
                        foreach (KeyValuePair <String, String> tag in trans.TaggedValues)
                        {
                            cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i);
                        }
                        cycleTran.SetTaggedValue("TDCYCLETRAN", "true");
                        cycleTran.Source = src;
                        cycleTran.Target = targ;
                        hyperlinkTrans2.Add(cycleTran);
                        lastTran = cycleTran;
                        if (currFirstState == null)
                        {
                            currFirstState = src;
                        }
                        lastSate = targ;
                    }
                    if (prevLastState != null)
                    {
                        UmlTransition cycleTran = new UmlTransition();
                        if (initialT != null)
                        {
                            foreach (KeyValuePair <String, String> tag in initialT.TaggedValues)
                            {
                                // cycleTran.SetTaggedValue(tag.Key, tag.Value + ". Iteration " + i);
                                cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i);
                            }
                            cycleTran.SetTaggedValue("TDCYCLETRAN", "true");
                            cycleTran.SetTaggedValue("TDLASTCYCLETRANS", "true");
                        }

                        cycleTran.Source = prevLastState;
                        cycleTran.Target = currFirstState;
                        if (cycleTran.TaggedValues.Count > 0)
                        {
                            hyperlinkTrans2.Add(cycleTran);
                            lastTran = cycleTran;
                        }
                    }
                    if (currFirstState != null)
                    {
                        if (firstFirstState == null)
                        {
                            firstFirstState = currFirstState;
                        }
                    }
                    prevLastState = lastSate;
                }

                if (tp == hyperLinkType.Source)
                {
                    t.Source = lastSate;
                    t.SetTaggedValue("TDLASTCYCLETRANS", "true");
                }
                else
                {
                    t.Target = firstFirstState;
                }
                t.SetTaggedValue("TDCYCLETRAN", "true");
                subTransitions = hyperlinkTrans2;
            }
            #endregion

            return(subTransitions);
        }
コード例 #7
0
        private UmlModel FromXmi(XmlDocument doc, ref String name)
        {
            UmlModel    model      = null;
            XmlNodeList modelQuery = doc.SelectNodes("//Objects.UmlModel");

            foreach (XmlNode modelNode in modelQuery)
            {
                model      = new UmlModel();
                model.Id   = modelNode.Attributes["id"].Value;
                model.Name = modelNode.Attributes["name"].Value;
                name       = model.Name;
            }

            #region UseCaseDiagram
            XmlNodeList ucDiagramQuery = doc.SelectNodes("//Diagrams.UmlUseCaseDiagram");
            foreach (XmlNode ucDiagram in ucDiagramQuery)
            {
                UmlUseCaseDiagram umlUseCaseDiagram = new UmlUseCaseDiagram();
                umlUseCaseDiagram.Name = ucDiagram.Attributes["name"].Value;
                umlUseCaseDiagram.Id   = ucDiagram.Attributes["id"].Value;
                #region Actor
                foreach (XmlNode actorNode in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlActor"))
                {
                    UmlActor element = new UmlActor();
                    element.Id   = actorNode.Attributes["id"].Value;
                    element.Name = actorNode.Attributes["name"].Value;

                    foreach (XmlNode tag in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlActor[@id='" + element.Id + "']//TAG"))
                    {
                        String key   = tag.Attributes["tagName"].Value.ToUpper();
                        String value = tag.Attributes["tagValue"].Value;
                        element.SetTaggedValue(key, value);
                    }
                    umlUseCaseDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region UseCase
                foreach (XmlNode ucNode in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlUseCase"))
                {
                    UmlUseCase element = new UmlUseCase();
                    element.Id   = ucNode.Attributes["id"].Value;
                    element.Name = ucNode.Attributes["name"].Value;
                    umlUseCaseDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Association
                foreach (XmlNode associationNode in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlAssociation"))
                {
                    UmlAssociation element = new UmlAssociation();
                    element.Id = associationNode.Attributes["id"].Value;
                    UmlElement end1 = SearchUseCaseDiagramElement(associationNode.Attributes["end1Id"].Value, umlUseCaseDiagram);
                    UmlElement end2 = SearchUseCaseDiagramElement(associationNode.Attributes["end2Id"].Value, umlUseCaseDiagram);
                    element.End1 = end1;
                    element.End2 = end2;
                    umlUseCaseDiagram.UmlObjects.Add(element);
                }
                #endregion
                model.AddDiagram(umlUseCaseDiagram);
            }
            #endregion
            #region ActivityDiagram
            XmlNodeList actDiagramQuery = doc.SelectNodes("//Diagrams.UmlActivityDiagram");
            foreach (XmlNode actDiagram in actDiagramQuery)
            {
                UmlActivityDiagram umlActivityDiagram = new UmlActivityDiagram(actDiagram.Attributes["name"].Value);
                umlActivityDiagram.Id = actDiagram.Attributes["id"].Value;
                #region State Initial
                foreach (XmlNode initialNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlInitialState"))
                {
                    UmlInitialState element = new UmlInitialState();
                    element.Id   = initialNode.Attributes["id"].Value;
                    element.Name = initialNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Action State
                foreach (XmlNode actionStateNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlActionState"))
                {
                    UmlActionState element = new UmlActionState();
                    element.Id   = actionStateNode.Attributes["id"].Value;
                    element.Name = actionStateNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region State Final
                foreach (XmlNode finalNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlFinalState"))
                {
                    UmlFinalState element = new UmlFinalState();
                    element.Id   = finalNode.Attributes["id"].Value;
                    element.Name = finalNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Fork
                foreach (XmlNode forkNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlFork"))
                {
                    UmlFork element = new UmlFork();
                    element.Id   = forkNode.Attributes["id"].Value;
                    element.Name = forkNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Join
                foreach (XmlNode joinNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlJoin"))
                {
                    UmlJoin element = new UmlJoin();
                    element.Id   = joinNode.Attributes["id"].Value;
                    element.Name = joinNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Decision
                foreach (XmlNode decisionNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlDecision"))
                {
                    UmlDecision element = new UmlDecision();
                    element.Id   = decisionNode.Attributes["id"].Value;
                    element.Name = decisionNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Transition
                foreach (XmlNode transitionNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlTransition"))
                {
                    UmlTransition  element   = new UmlTransition();
                    UmlActionState actSource = SearchActivityDiagramElement(transitionNode.Attributes["stateSourceId"].Value, umlActivityDiagram);
                    UmlActionState actTarget = SearchActivityDiagramElement(transitionNode.Attributes["stateTargetId"].Value, umlActivityDiagram);
                    element.Id     = transitionNode.Attributes["id"].Value;
                    element.Source = actSource;
                    element.Target = actTarget;
                    //Get TAG
                    foreach (XmlNode tag in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlTransition[@id='" + element.Id + "']//TAG"))
                    {
                        String key   = tag.Attributes["tagName"].Value.ToUpper();
                        String value = tag.Attributes["tagValue"].Value;
                        element.SetTaggedValue(key, value);
                    }
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                model.AddDiagram(umlActivityDiagram);
            }
            #endregion
            return(model);
        }
コード例 #8
0
        public UmlModel FromXmi(XmlDocument doc, ref String name)
        {
            UmlModel model = new UmlModel("");
            //uml and astah namespaces
            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);

            nsManager.AddNamespace("JUDE", "http://objectclub.esm.co.jp/Jude/namespace/");
            nsManager.AddNamespace("UML", "org.omg.xmi.namespace.UML");

            XmlNodeList mod = doc.SelectNodes("//UML:Model[@xmi.id]", nsManager);

            foreach (XmlNode node in mod)
            {
                name = node.Attributes["name"].Value;
                break;
            }
            //importing activity diagrams into model.
            XmlNodeList nodesWithActivityDiagrams = doc.SelectNodes("//UML:ActivityGraph[@xmi.id]", nsManager);

            #region Activity Diagram
            if (nodesWithActivityDiagrams.Count != 0)
            {
                foreach (XmlNode node in nodesWithActivityDiagrams)
                {
                    UmlActivityDiagram actDiagram = new UmlActivityDiagram(node.Attributes["name"].Value);
                    actDiagram.Id   = node.Attributes["xmi.id"].Value;
                    actDiagram.Name = node.Attributes["name"].Value;
                    model.AddDiagram(actDiagram);

                    #region Pseudostate
                    foreach (XmlNode pseudoNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Pseudostate[@xmi.id]", nsManager))
                    {
                        UmlElement element = null;

                        if (pseudoNode.Attributes["kind"].Value.Equals("initial"))
                        {
                            element = new UmlInitialState();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("fork"))
                        {
                            element = new UmlFork();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("junction"))
                        {
                            element = new UmlDecision();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("join"))
                        {
                            element = new UmlJoin();
                        }

                        element.Name = pseudoNode.Attributes["name"].Value;
                        element.Id   = pseudoNode.Attributes["xmi.id"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in pseudoNode.SelectNodes("//UML:Pseudostate[@xmi.id='" + element.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            //element.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                            element.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(element);
                    }
                    #endregion
                    #region ActionState
                    foreach (XmlNode stateNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:ActionState[@xmi.id]", nsManager))
                    {
                        UmlElement state = new UmlActionState();
                        state.Id   = stateNode.Attributes["xmi.id"].Value;
                        state.Name = stateNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in stateNode.SelectNodes("//UML:ActionState[@xmi.id='" + state.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string nameToken    = "type%3Dmodel%2Cname%3D";
                                string commentToken = "%2Cpath%3D%2Ccomment%3D";
                                int    i1           = taggedValuesNode.Attributes["value"].Value.IndexOf(nameToken) + (nameToken.Length);
                                int    i2           = taggedValuesNode.Attributes["value"].Value.IndexOf(commentToken);
                                String aux_value    = taggedValuesNode.Attributes["value"].Value.Substring(i1, i2 - commentToken.Length + 1);
                                String aux_value2   = taggedValuesNode.Attributes["value"].Value.Substring(i2 + commentToken.Length);

                                state.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, aux_value);

                                if (!String.IsNullOrEmpty(aux_value2))
                                {
                                    state.SetTaggedValue("cycles", aux_value2);
                                }

                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        state.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }
                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        state.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                string tag = taggedValuesNode.Attributes["tag"].Value;
                                string var = null;
                                try
                                {
                                    var = taggedValuesNode.Attributes["value"].Value;
                                }
                                catch (Exception)
                                {
                                    state.SetTaggedValue(tag, "");
                                }
                                if (var != null)
                                {
                                    state.SetTaggedValue(tag, var);
                                }
                            }
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(state);
                    }
                    #endregion
                    #region FinalState
                    foreach (XmlNode finalStateNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:FinalState[@xmi.id]", nsManager))
                    {
                        UmlElement finalState = new UmlFinalState();
                        finalState.Name = finalStateNode.Attributes["name"].Value;
                        finalState.Id   = finalStateNode.Attributes["xmi.id"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in finalStateNode.SelectNodes("//UML:FinalState[@xmi.id='" + finalState.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            //finalState.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                            finalState.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(finalState);
                    }
                    #endregion
                    #region Transition
                    //UmlTransition
                    foreach (XmlNode transitionNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id]", nsManager))
                    {
                        UmlTransition transition = new UmlTransition();

                        transition.Id   = transitionNode.Attributes["xmi.id"].Value;
                        transition.Name = transitionNode.Attributes["name"].Value;
                        // Tagged Values
                        foreach (XmlNode tagValuesNode in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:TaggedValue", nsManager))
                        {
                            try
                            {
                                //transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(tagValuesNode.Attributes["value"].Value));
                                transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value.ToUpper(), tagValuesNode.Attributes["value"].Value);
                            }
                            catch
                            {
                                transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value.ToUpper(), "");
                            }
                        }
                        // Transition Source
                        foreach (XmlNode transitionSource in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:Transition.source//UML:StateVertex", nsManager))
                        {
                            UmlElement element = actDiagram.GetElementById(transitionSource.Attributes["xmi.idref"].Value);
                            transition.Source = element;
                        }
                        // Transition Target
                        foreach (XmlNode transitionTarget in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:Transition.target//UML:StateVertex", nsManager))
                        {
                            UmlElement element = actDiagram.GetElementById(transitionTarget.Attributes["xmi.idref"].Value);
                            transition.Target = element;
                        }
                        actDiagram.UmlObjects.Add(transition);
                    }
                    #endregion
                    #region Lanes
                    XmlNodeList partition   = node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Partition[@xmi.id]", nsManager);
                    bool        isDimension = false;

                    if (partition.Count != 0)
                    {
                        foreach (XmlNode dimensionNode in partition)
                        {
                            if (isDimension == false)
                            {
                                isDimension = true;
                                UmlLane dimension = new UmlLane();
                                dimension.Id   = dimensionNode.Attributes["xmi.id"].Value;
                                dimension.Name = dimensionNode.Attributes["name"].Value;
                                foreach (XmlNode laneNode in dimensionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Partition[@xmi.id='" + dimension.Id + "']//JUDE:ModelElement", nsManager))
                                {
                                    XmiImporter importer = new XmiImporter();
                                    UmlLane     lane     = importer.CreateLane(dimension.Id, node, laneNode.Attributes["xmi.idref"].Value, actDiagram, nsManager);
                                    actDiagram.UmlObjects.Add(lane);
                                    actDiagram.Lanes.Add(lane);
                                    dimension.ListLane.Add(lane);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            #endregion

            //importing usecase diagrams into model.
            XmlNodeList nodesWithUseCaseDiagrams = doc.SelectNodes("//UML:UseCase[@xmi.id]", nsManager);
            XmlNodeList nodesWithActorDiagrams   = doc.SelectNodes("//UML:Actor[@xmi.id]", nsManager);

            #region UseCase Diagrams
            //   if (nodesWithUseCaseDiagrams.Count != 0 && nodesWithActorDiagrams.Count != 0)
            {
                XmlNodeList modelElements = doc.SelectNodes("//UML:Model[@xmi.id]", nsManager);

                foreach (XmlNode node in modelElements)
                {
                    UmlUseCaseDiagram useCaseDiagram = new UmlUseCaseDiagram();
                    useCaseDiagram.Id   = node.Attributes["xmi.id"].Value;
                    useCaseDiagram.Name = node.Attributes["name"].Value;
                    model.AddDiagram(useCaseDiagram);
                    #region Actor
                    foreach (XmlNode actorNode in node.SelectNodes("//UML:Actor[@xmi.id]", nsManager))
                    {
                        UmlActor actor = new UmlActor();
                        actor.Id   = actorNode.Attributes["xmi.id"].Value;
                        actor.Name = actorNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in actorNode.SelectNodes("//UML:Actor[@xmi.id='" + actor.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string aux_value = taggedValuesNode.Attributes["value"].Value.Substring(22);
                                aux_value = aux_value.Substring(0, aux_value.Length - 23);
                                actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, aux_value);
                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        actor.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }
                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        actor.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                try
                                {
                                    //actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                    actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), taggedValuesNode.Attributes["value"].Value);
                                }
                                catch
                                {
                                    actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), "");
                                }
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(actor);
                    }
                    #endregion
                    #region UseCase
                    foreach (XmlNode useCaseNode in node.SelectNodes("//UML:UseCase[@xmi.id]", nsManager))
                    {
                        UmlUseCase useCase = new UmlUseCase();
                        useCase.Id   = useCaseNode.Attributes["xmi.id"].Value;
                        useCase.Name = useCaseNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in node.SelectNodes("//UML:UseCase[@xmi.id='" + useCase.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string aux_value = taggedValuesNode.Attributes["value"].Value.Substring(22);
                                aux_value = aux_value.Substring(0, aux_value.Length - 23);
                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        useCase.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }

                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        useCase.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                try
                                {
                                    //useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                    useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), taggedValuesNode.Attributes["value"].Value);
                                }
                                catch
                                {
                                    useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), "");
                                }
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(useCase);
                    }
                    #endregion
                    #region Association
                    foreach (XmlNode associationNode in node.SelectNodes("//UML:Association[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = associationNode.Attributes["xmi.id"].Value;
                        association.Name = associationNode.Attributes["name"].Value;

                        bool putEnd1 = false;

                        foreach (XmlNode associationEndNode in associationNode.SelectNodes("//UML:Association[@xmi.id='" + association.Id + "']//UML:AssociationEnd//UML:AssociationEnd.participant//UML:Classifier[@xmi.idref]", nsManager))
                        {
                            foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                            {
                                if (!putEnd1)
                                {
                                    if (element.Id.Equals(associationEndNode.Attributes["xmi.idref"].Value))
                                    {
                                        association.End1 = element;
                                        putEnd1          = true;
                                    }
                                }
                                else
                                {
                                    if (element.Id.Equals(associationEndNode.Attributes["xmi.idref"].Value))
                                    {
                                        association.End2 = element;
                                    }
                                }
                            }
                        }

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in node.SelectNodes("//UML:Association[@xmi.id='" + association.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            try
                            {
                                //association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                            }
                            catch
                            {
                                association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, "");
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(association);
                    }

                    #endregion
                    #region Include
                    foreach (XmlNode includeNode in node.SelectNodes("//UML:Include[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = includeNode.Attributes["xmi.id"].Value;
                        association.Name = includeNode.Attributes["name"].Value;
                        association.Stereotypes.Add("Include");

                        XmlNode begin = includeNode.SelectSingleNode("//UML:Include[@xmi.id='" + association.Id + "']//UML:Include.base//UML:UseCase[@xmi.idref]", nsManager);
                        XmlNode end   = includeNode.SelectSingleNode("//UML:Include[@xmi.id='" + association.Id + "']//UML:Include.addition//UML:UseCase[@xmi.idref]", nsManager);

                        foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                        {
                            if (element.Id.Equals(begin.Attributes["xmi.idref"].Value))
                            {
                                association.End1 = element;
                            }
                            else if (element.Id.Equals(end.Attributes["xmi.idref"].Value))
                            {
                                association.End2 = element;
                            }
                        }
                        useCaseDiagram.UmlObjects.Add(association);
                    }
                    #endregion
                    #region Extend
                    foreach (XmlNode extendNode in node.SelectNodes("//UML:Extend[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = extendNode.Attributes["xmi.id"].Value;
                        association.Name = extendNode.Attributes["name"].Value;
                        association.Stereotypes.Add("Extend");

                        XmlNode end   = extendNode.SelectSingleNode("//UML:Extend[@xmi.id='" + association.Id + "']//UML:Extend.base//UML:UseCase[@xmi.idref]", nsManager);
                        XmlNode begin = extendNode.SelectSingleNode("//UML:Extend[@xmi.id='" + association.Id + "']//UML:Extend.extension//UML:UseCase[@xmi.idref]", nsManager);

                        foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                        {
                            if (element.Id.Equals(begin.Attributes["xmi.idref"].Value))
                            {
                                association.End1 = element;
                            }
                            else if (element.Id.Equals(end.Attributes["xmi.idref"].Value))
                            {
                                association.End2 = element;
                            }
                        }
                        useCaseDiagram.UmlObjects.Add(association);
                    }
                    #endregion
                }
            }
            #endregion
            return(model);
        }
コード例 #9
0
 public static string GetStereotypeText(UmlElement elem, string defaultStereotype)
 {
     return(string.IsNullOrEmpty(elem.Stereotype)?
            "<<" + defaultStereotype + ">>":
            "<<" + defaultStereotype + ", " + elem.Stereotype + ">>");
 }