svn commit: r15529 - branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: penyaskito
Date: 2008-08-10 01:19:41-0700
New Revision: 15529

Modified:
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs

Log:
Look at the associations in the XMI. Cache results for performance.

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs?view=diff&rev=15529&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs&r1=15528&r2=15529
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/csharp-transformation/Program.cs	2008-08-10 01:19:41-0700
@@ -16,6 +16,8 @@
         private static string TargetFile =

             @"test-net.xml";

 

+        private static Dictionary<String, List<MyAttribute>> AttributesCache = new Dictionary<string, List<MyAttribute>>();

+

 

         private static XDocument doc;

 

@@ -164,6 +166,12 @@
 

         private static List<MyAttribute> GetAttributes(XElement element, XElement core_package)

         {

+            if (AttributesCache.ContainsKey(element.Attribute("name").Value))

+            {

+                return AttributesCache[element.Attribute("name").Value];

+            }

+

+

             List<MyAttribute> attrs = new List<MyAttribute>();

 

             var supertypes = element.Attribute("supertypes");

@@ -178,9 +186,25 @@
             }

 

             // TODO: Look at the Associations

+            string id = element.Attribute(XName.Get("xmi.id")).Value;

+            var associations = from a in core_package.Descendants()

+                               where a.Name.LocalName.Equals("Association")

+                               select a;

+            var associationEnd = (from x in associations.DescendantsAndSelf()

+                                  where x.Name != null

+                                    && x.Name.LocalName.Equals("AssociationEnd")

+                                    && x.Attribute(XName.Get("type")).Value.Equals(id)

+                                  select new MyAttribute

+                                   {

+                                       Name = GetNameOfAssociation(x),

+                                       Type = GetTypeByXmiId(x.Attribute("type").Value, core_package).Attribute("name").Value,

+                                       Multiplicity = GetMultiplicity(x)

+                                   }

+                                 ).Distinct();

+

             var ats = (from a in element.Descendants()

                        where a.Name != null

-                       where a.Name.Equals(XName.Get("{omg.org/mof.Model/1.3}Attribute"))

+                         && a.Name.Equals(XName.Get("{omg.org/mof.Model/1.3}Attribute"))

                          || a.Name.Equals(XName.Get("{omg.org/mof.Model/1.3}Reference"))

                        select new MyAttribute

                        {

@@ -189,11 +213,25 @@
                            Multiplicity = GetMultiplicity(a)

                        }).Distinct();

             AddElement(attrs, ats);

+            AddElement(attrs, associationEnd);

+

+            AttributesCache.Add(element.Attribute("name").Value, attrs);

 

 

             return attrs;

         }

 

+        private static string GetNameOfAssociation(XElement x)

+        {

+            var name = (from t in x.Parent.Descendants()

+                        where t != x

+                         && t.Attribute("name") != null

+                        select t.Attribute("name").Value).Single();

+            return name;

+        }

+

+

+

         private static Multiplicity GetMultiplicity(XElement a)

         {

             var mults = a.Elements().Single().Elements();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.