示例#1
0
        /// <summary>
        /// Reads the associations.
        /// </summary>
        private void ReadAssociations()
        {
            foreach (XmlNode assocNode in _xdoc.SelectNodes("/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Association/UML:Association.connection", _nsManager))
            {
                XmlNodeList assocEndNodes = assocNode.SelectNodes("UML:AssociationEnd", _nsManager);

                string typeName;
                bool   isPrimitive;
                bool   classExists;

                XmlNode node2 = assocEndNodes[0].SelectSingleNode("UML:AssociationEnd.participant/UML:Class", _nsManager);
                string  id    = node2.Attributes["xmi.idref"].Value;
                GetTypeInfo(id, out typeName, out isPrimitive);

                ClassNameInfo nameHelper = new ClassNameInfo(_initialNamespace, typeName);
                Entity        source     = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);
                Debug.Assert(isPrimitive == false && classExists == true);
                XmlNode      multiplicityNode   = assocEndNodes[0].SelectSingleNode("UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange", _nsManager);
                Multiplicity sourceMultiplicity = GetMultiplicityFromValue(multiplicityNode.Attributes["lower"].Value, multiplicityNode.Attributes["upper"].Value);

                node2 = assocEndNodes[1].SelectSingleNode("UML:AssociationEnd.participant/UML:Class", _nsManager);
                id    = node2.Attributes["xmi.idref"].Value;
                GetTypeInfo(id, out typeName, out isPrimitive);
                Entity target = (Entity)_layer.AddTypeIfNotExists(nameHelper, false, out classExists);
                Debug.Assert(isPrimitive == false && classExists == true);
                multiplicityNode = assocEndNodes[1].SelectSingleNode("UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange", _nsManager);
                Multiplicity targetMultiplicity = GetMultiplicityFromValue(multiplicityNode.Attributes["lower"].Value, multiplicityNode.Attributes["upper"].Value);

                Association assoc = source.AddAssociationTo(target);
                assoc.SourceMultiplicity = sourceMultiplicity;
                assoc.TargetMultiplicity = targetMultiplicity;
            }
        }
示例#2
0
        /// <summary>
        /// Execute the command
        /// </summary>
        public void Exec()
        {
            using (Transaction transaction = _clazz.Store.TransactionManager.BeginTransaction("Property to Association"))
            {
                Entity targetModel = FindModelClassByName(_property);
                if (targetModel == null)
                {
                    return;
                }

                // Suppression en tant que propriété
                _clazz.Properties.Remove(_property);

                // Propriétés de l'association
                Association assoc = _clazz.AddAssociationTo(targetModel);
                assoc.SourceRoleName     = _property.Name;
                assoc.SourceMultiplicity = Multiplicity.ZeroOne;
                assoc.XmlName            = _property.XmlName;

                // TIPS sélection d'un composant
                // On enlève la sélection sur la propriété car on vient de la supprimer
                IMonitorSelectionService monitorSelectionService = (IMonitorSelectionService)_serviceProvider.GetService(typeof(IMonitorSelectionService));
                if (monitorSelectionService != null)
                {
                    ISelectionService selectionService = monitorSelectionService.CurrentSelectionContainer as ISelectionService;
                    if (selectionService != null)
                    {
                        selectionService.SetSelectedComponents(null);
                    }
                }
                transaction.Commit();
            }
        }
示例#3
0
        /// <summary>
        /// Création d'un modèle de type classe
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="clazz">Clr Type initial</param>
        private void CreateEntity(Entity model, Type clazz)
        {
            // Héritage
            if (clazz.BaseType != null && !(clazz.BaseType.FullName.StartsWith("System.")))
            {
                model.SuperClass = _layer.SoftwareComponent.FindGlobalType(clazz.BaseType.FullName) as Entity;
            }

            // Propriétés de la classe
            foreach (PropertyInfo prop in clazz.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (prop.CanRead)
                {
                    string xmlName = "";
                    try
                    {
                        object[] attributes = prop.GetCustomAttributes(typeof(XmlElementAttribute), false);
                        if (attributes.Length > 0)
                        {
                            XmlElementAttribute attr = attributes[0] as XmlElementAttribute;
                            xmlName = attr.ElementName;
                        }
                    }
                    catch { }

                    // Création d'une association
                    if (prop.PropertyType.IsClass && prop.PropertyType.Assembly == clazz.Assembly)
                    {
                        string typeName = GetTypeElement(prop, prop.PropertyType);
                        if (typeName != null)
                        {
                            Entity target = _layer.SoftwareComponent.FindGlobalType(typeName) as Entity;
                            if (target != null)
                            {
                                Association association = model.AddAssociationTo(target);
                                association.SourceRoleName     = prop.Name;
                                association.SourceMultiplicity = IsListe(prop.PropertyType) ? Multiplicity.OneMany : Multiplicity.One;
                                association.XmlName            = xmlName;
                                continue;
                            }
                        }

                        typeName = "$error:unable to determine the type.";
                    }

                    // Création d'un attribut
                    DSLFactory.Candle.SystemModel.Property p = new DSLFactory.Candle.SystemModel.Property(_layer.Store);
                    p.Type = prop.PropertyType.FullName;
                    p.Name = prop.Name;
                    //p.IsPrimitive = IsTypePrimitive(prop.PropertyType);
                    p.XmlName = xmlName;
                    model.Properties.Add(p);
                }
            }
        }