예제 #1
0
 public void AddPart(Association association, ObjectPlusPlus partObject)
 {
     if (AllParts.Contains(partObject))
     {
         throw new Exception("Given part object is already linked");
     }
     AddLink(association, partObject);
     AllParts.Add(partObject);
 }
예제 #2
0
        public bool IsLinked(Role role, ObjectPlusPlus linkedObject)
        {
            if (!Links.ContainsKey(role))
            {
                throw new Exception("Role undefined");
            }
            Dictionary <object, ObjectPlusPlus> roleLinks = Links[role];

            if (roleLinks.Values.Contains(linkedObject))
            {
                return(true);
            }
            return(false);
        }
예제 #3
0
        private void AddLink(Association association, ObjectPlusPlus linkedObject, object qualifier, int counter)
        {
            if (counter < 1)
            {
                return;
            }
            if (linkedObject == null)
            {
                return;
            }
            if (association == null)
            {
                return;
            }
            if (!LegalAssociations.Any(x => x.Role.Equals(association.Role)))
            {
                throw new Exception("Association is not legal");
            }
            if (this.GetType() != association.StartClassifier)
            {
                throw new Exception("This object type is not correct");
            }
            if (linkedObject.GetType() != association.EndClassifier)
            {
                throw new Exception("Linked object type is not correct");
            }
            Dictionary <object, ObjectPlusPlus> roleLinks;

            if (Links.ContainsKey(association.Role))
            {
                roleLinks = Links[association.Role];
            }
            else
            {
                roleLinks = new Dictionary <object, ObjectPlusPlus>();
                Links.Add(association.Role, roleLinks);
            }
            if (!roleLinks.ContainsKey(linkedObject))
            {
                Association reverseAssociation = association.GetReversedAssociation();
                switch (association.EndMultiplicityLimit)
                {
                case -1:
                    roleLinks.Add(qualifier, linkedObject);
                    if (reverseAssociation != null)
                    {
                        linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    }
                    break;

                case 0:
                    if (roleLinks.Count != 0)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;

                default:
                    if (roleLinks.Count >= association.EndMultiplicityLimit)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;
                }
            }
        }
예제 #4
0
 public void AddLink(Association association, ObjectPlusPlus linkedObject)
 {
     AddLink(association, linkedObject, linkedObject, 2);
 }
예제 #5
0
 public void AddLink(Association association, ObjectPlusPlus linkedObject, object qualifier)
 {
     AddLink(association, linkedObject, qualifier, 2);
 }
예제 #6
0
파일: ObjectPlus4.cs 프로젝트: Qarpiu/MAS
 public void AddLink_Subset(Association parentAssociation, Association childAssociation, ObjectPlusPlus linkedObject)
 {
     if (IsLinked(parentAssociation.Role, linkedObject))
     {
         AddLink(childAssociation.Role, linkedObject);
     }
     else
     {
         throw new Exception("There is no parent associayion for that object");
     }
 }