예제 #1
0
        public StereotypeInstance ApplyTo(Element element)
        {
            // Cast the element
            _ImplElement implElement = element as _ImplElement;

            if (implElement == null)
            {
                throw new ArgumentException("The given element was created outside the model library!");
            }

            // Verify that the element can be extended by this stereotype
            Type metaClassType     = implElement.AdaptedElement.GetType();
            bool extensibleElement = false;

            foreach (string metaClassName in applicationDomain)
            {
                Type metaClassInterface = metaClassType.GetInterface(metaClassName, true);
                if (metaClassInterface != null)
                {
                    extensibleElement = true;
                    break;
                }
            }

            if (!extensibleElement)
            {
                throw new NotSupportedException("The given element is not an instance of a metaclass that " +
                                                "may be extended by this stereotype!");
            }

            // Apply the stereotype
            _StereotypeInstance instance = new _StereotypeInstance(this, Schema);

            element.AppliedStereotypes.Add(instance);

            // Return the stereotype instance
            return(instance);
        }
예제 #2
0
파일: _PSMClass.cs 프로젝트: mff-uk/xcase
        /// <summary>
        /// Changes the XSem stereotype of this PSM Class to either XSem.PSMClass
        /// if the RepresentedPSMClass property is null or to XSem.PSMStructuralRepresentative
        /// if the RepresentedPSMClass references another PSM class.
        /// </summary>
        protected void ChangeStereotype()
        {
            Profile    xsem          = Schema.Profiles.Get("XSem");
            Stereotype newStereotype = null;

            if (xsem == null)
            {
                throw new Exception("Fatal error! Could not find the XSem profile!");
            }

            if (representedPSMClass != null)
            {
                newStereotype = xsem.Stereotypes.Get("PSMStructuralRepresentative");
            }
            else
            {
                newStereotype = xsem.Stereotypes.Get("PSMClass");
            }

            if (newStereotype == null)
            {
                throw new Exception("Fatal error! Could not find the XSem stereotype!");
            }

            StereotypeInstance instance = new _StereotypeInstance(newStereotype as _Stereotype, Schema);

            instance.Attributes.Get("RepresentedClass").Value = xsemStereotype.Attributes.Get("RepresentedClass").Value;
            instance.Attributes.Get("ElementName").Value      = xsemStereotype.Attributes.Get("ElementName").Value;

            if (representedPSMClass != null)
            {
                instance.Attributes.Get("RepresentedPSMClass").Value = new ValueSpecification(representedPSMClass);
            }

            xsemStereotype = instance;
        }