/// <summary> /// Create a subtyping relationship between two objects /// </summary> /// <param name="subtype">The object type to use as the subtype</param> /// <param name="supertype">The object type to use as the supertype</param> /// <returns>Subtype object</returns> public static SubtypeFact Create(ObjectType subtype, ObjectType supertype) { Debug.Assert(subtype != null && supertype != null); SubtypeFact retVal; IHasAlternateOwner <ObjectType> toAlternateOwner; IAlternateElementOwner <FactType> alternateFactTypeOwner; DomainClassInfo alternateCtor; if (null != (toAlternateOwner = subtype as IHasAlternateOwner <ObjectType>) && null != (alternateFactTypeOwner = toAlternateOwner.AlternateOwner as IAlternateElementOwner <FactType>) && null != (alternateCtor = alternateFactTypeOwner.GetOwnedElementClassInfo(typeof(SubtypeFact)))) { ((IHasAlternateOwner <FactType>)(retVal = (SubtypeFact)subtype.Partition.ElementFactory.CreateElement(alternateCtor))).AlternateOwner = alternateFactTypeOwner; } else { (retVal = new SubtypeFact(subtype.Partition)).Model = subtype.Model; } retVal.Subtype = subtype; retVal.Supertype = supertype; if (subtype.IsValueType) { retVal.ProvidesPreferredIdentifier = true; } return(retVal); }
/// <summary> /// DeleteRule: typeof(FactTypeHasRole), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority; /// Block roles from being removed from a subtype /// after it is included in a model. /// </summary> private static void LimitSubtypeRolesDeleteRule(ElementDeletedEventArgs e) { FactTypeHasRole link = (FactTypeHasRole)e.ModelElement; SubtypeFact subtypeFact = link.FactType as SubtypeFact; if (null != (subtypeFact = link.FactType as SubtypeFact) && !subtypeFact.IsDeleted && subtypeFact.ResolvedModel != null) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(subtypeFact.Store); } }
/// <summary> /// DeleteRule: typeof(ObjectTypePlaysRole), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority; /// Ensure that a role player deletion on a subtype results in a deletion /// of the subtype itself. /// </summary> private static void DeleteSubtypeWhenRolePlayerDeletedRule(ElementDeletedEventArgs e) { ObjectTypePlaysRole link = e.ModelElement as ObjectTypePlaysRole; Role role = link.PlayedRole; if (role != null && !role.IsDeleted) { SubtypeFact subtypeFact = role.FactType as SubtypeFact; if (subtypeFact != null && !subtypeFact.IsDeleted) { subtypeFact.Delete(); } } }
/// <summary> /// DeleteRule: typeof(ConstraintRoleSequenceHasRole), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority; /// Block roles from being removed from a subtype fact /// after it is included in a model. /// </summary> private static void LimitSubtypeConstraintRolesDeleteRule(ElementDeletedEventArgs e) { ConstraintRoleSequenceHasRole link = e.ModelElement as ConstraintRoleSequenceHasRole; SetConstraint ic = link.ConstraintRoleSequence as SetConstraint; LinkedElementCollection <FactType> facts; if (ic != null && !ic.IsDeleted && ic.Constraint.ConstraintIsInternal && 1 == (facts = ic.FactTypeCollection).Count) { SubtypeFact subtypeFact = facts[0] as SubtypeFact; if (null != (subtypeFact = facts[0] as SubtypeFact) && !subtypeFact.IsDeleted && subtypeFact.ResolvedModel != null) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(subtypeFact.Store); } } }