public List <UMLFile> CreateFiles(IDictionary relationships)
        {
            List <PreFile> prefiles = new List <PreFile>();
            List <PreRET>  retsToDelete;
            List <UMLFile> files = new List <UMLFile>();
            IDictionary <String, String>   tnamemap;
            IDictionary <String, UMLClass> tclasses;
            UMLFile      tfile;
            String       tname;
            int          tdets;
            UMLAttribute tattrib;

            //0. Pre-Pre-Processing (set dependencies in relationships)
            foreach (DictionaryEntry entry in relationships)
            {
                UMLRelationship r = (UMLRelationship)entry.Value;

                if (r is UMLDependency)
                {
                    foreach (DictionaryEntry entry2 in relationships)
                    {
                        UMLRelationship q = (UMLRelationship)entry2.Value;

                        if (q is UMLAssociation)
                        {
                            if ((((UMLDependency)r).Client.Guid.Equals(((UMLAssociation)q).End1.Participant.Guid)) &&
                                (((UMLDependency)r).Supplier.Guid.Equals(((UMLAssociation)q).End2.Participant.Guid)) ||
                                (((UMLDependency)r).Client.Guid.Equals(((UMLAssociation)q).End2.Participant.Guid)) &&
                                (((UMLDependency)r).Supplier.Guid.Equals(((UMLAssociation)q).End1.Participant.Guid)))
                            {
                                ((UMLAssociation)q).DependencyType = "D";
                            }
                        }
                    }
                }
            }

            //1. PreFile Generation (Pre-Processing)
            foreach (DictionaryEntry entry in relationships)
            {
                UMLRelationship r = (UMLRelationship)entry.Value;

                if (!(r is UMLDependency))
                {
                    ActionKey key = new ActionKey(r);

                    AbstractAction action = map.GetAction(key);

                    if (action != null)
                    {
                        action.Execute(r, map, prefiles);
                    }
                    else
                    {
                        throw new ArgumentException("There is no defined action for the actionKey given.");
                    }
                }
            }

            //2. File Generation (Processing)
            if (prefiles.Count == 0)
            {
                return(null);
            }
            else
            {
                //2.1 Clean-up (eliminate parents in PreFiles - Generalization cases)
                foreach (PreFile prefile in prefiles)
                {
                    retsToDelete = new List <PreRET>();

                    foreach (PreRET preret in prefile.Rets)
                    {
                        foreach (PreRET parent in preret.Parents)
                        {
                            //2.1.1 Merge
                            preret.Merge(parent);

                            //mark parent ret for deletion
                            if (!retsToDelete.Contains(parent))
                            {
                                retsToDelete.Add(parent);
                            }
                        }
                    }

                    //2.1.2 Deletion (optimized since rets are only in one file)
                    foreach (PreRET retToDelete in retsToDelete)
                    {
                        prefile.Rets.Remove(retToDelete);
                    }

                    //2.1.3 File generation
                    tfile = new UMLFile();
                    //Rets
                    tfile.Rets = prefile.Rets.Count;
                    //Dets & Name
                    tdets    = 0;
                    tname    = "";
                    tnamemap = new Dictionary <String, String>();
                    tclasses = new Dictionary <String, UMLClass>();

                    foreach (PreRET ret in prefile.Rets)
                    {
                        UMLFile.RET tret = new UMLFile.RET();

                        foreach (UMLClass c in ret.Classes)
                        {
                            tnamemap[c.Name] = c.Name;

                            tret.Classes.Add(c);

                            if (!(tclasses.ContainsKey(c.Name)))
                            {
                                tclasses[c.Name] = c;
                                c.LoadAttributes();
                                tdets += c.Attributes.Count;
                                foreach (UMLAttribute attrib in c.Attributes)
                                {
                                    tattrib      = new UMLAttribute();
                                    tattrib.Name = c.Name + "." + attrib.Name;
                                    tfile.Attributes.Add(tattrib);
                                }
                            }
                        }

                        tfile.RetsCollection.Add(tret);
                    }

                    foreach (KeyValuePair <String, String> kvp in tnamemap)
                    {
                        tname += kvp.Value + "_";
                    }

                    tfile.Dets  = tdets;
                    tfile.Dets += prefile.DefaultDets;
                    tname       = tname.Remove(tname.Length - 1, 1);
                    //limit File name size to 50 chars (could cause name collisions)
                    tfile.Name = tname.Length > 50 ? tname.Substring(1, 50) : tname;

                    files.Add(tfile);
                }

                return(files);
            }
        }
Beispiel #2
0
        //METHODS
        #region Methods
        public static ActionMap ReadFile(string filepath)
        {
            StreamReader sr = new StreamReader(filepath);
            String line;
            String[] tokens;
            ActionKey actionKey;
            ActionMap map = new ActionMap();
            Type actionType;
            String actionKeyString;
            int linecounter = 0;

            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                linecounter++;
                tokens = line.Split('/');
                //tokens[0] = entry-type
                //tokens[1] = parameters
                actionKeyString = EncodeEntryType(tokens[0],linecounter);

                tokens = tokens[1].Split(':');

                //verify action format is valid
                switch (actionKeyString[0].ToString())
                {
                    case ActionKey.EntryType.ASSOCIATION:
                        actionKeyString += EncodeParametersAssociation(tokens, linecounter);
                        break;
                    case ActionKey.EntryType.ASSOCIATIONCLASS:
                        actionKeyString += EncodeParametersAssociationClass(tokens, linecounter);
                        break;
                    case ActionKey.EntryType.GENERALIZATION:
                        actionKeyString += EncodeParametersGeneralization(tokens, linecounter);
                        break;
                    case ActionKey.EntryType.REALIZATION:
                        actionKeyString += EncodeParametersRealization(tokens, linecounter);
                        break;
                }

                if (Regex.IsMatch(tokens[tokens.Length - 1], @"^[A-Za-z0-9]*$"))
                {
                    actionKey = new ActionKey(actionKeyString);

                    //add the value-pair if no equal action-key exists
                    if (map.GetAction(actionKey) == null)
                    {
                        //create/validate action object
                        actionType = Type.GetType(ActionKey.ACTIONNAMESPACE + tokens[tokens.Length - 1]);
                        //add the map entry
                        map.Add(actionKey, (AbstractAction)Activator.CreateInstance(actionType));
                    }
                    else
                    {
                        throw new InvalidOperationException("An equivalent ActionKey already exists in the ActionMap at line: " + linecounter);
                    }
                }
                else
                {
                    throw new ArgumentException("The action-name contains some invalid characters at line: " + linecounter);
                }
            }

            return map;
        }