Skip to content
tdl-constraints.ocl 64.3 KiB
Newer Older
Philip Makedonski's avatar
Philip Makedonski committed
import 'http://www.etsi.org/spec/TDL/1.4.1'

package tdl

context NamedElement
  -- Mandatory name
  inv MandatoryName ('A \'NamedElement\' shall have the \'name\' property set and the \'name\' shall be not an empty String.' + self.toString()):
        not self.name.oclIsUndefined() and self.name.size() > 0
  

  -- Distinguishable qualified names
  inv DistinquishableName ('All qualified names of instances of \'NamedElement\'s shall be distinguishable within a TDL model.' + self.toString()):
        NamedElement.allInstances()->one(e | e.qualifiedName = self.qualifiedName)
  

  -- [NOTE:	It is up to the concrete syntax definition and tooling to resolve any name clashes between instances of the same meta-class in the qualified name.]


context Package
  -- No cyclic imports
  inv CyclicImports ('A \'Package\' shall not import itself directly or indirectly.' + self.toString()):
        self.import->asOrderedSet()->closure(i | i.importedPackage.import)->forAll(i | 
              i.importedPackage <> self)
  



context ElementImport
  -- Consistency of imported elements
  inv ConsistentImports ('All imported \'PackageableElement\'s referenced by an \'ElementImport\' shall be directly owned by the imported \'Package\'.' + self.toString()):
        self.importedElement->forAll(e | self.importedPackage.packagedElement->includes(e))
  

  -- [Figure 5.2: Miscellaneous elements]


context Comment
  -- No nested comments
  inv CommentNestedComments ('A \'Comment\' shall not contain \'Comment\'s.' + self.toString()):
        self.comment->isEmpty()
  

  -- No annotations to comments
  inv CommentNestedAnnotations ('A \'Comment\' shall not contain \'Annotation\'s.' + self.toString()):
        self.annotation->isEmpty()
  



context Annotation
  -- No nested annotations
  inv AnnotationNestedAnnotations ('An \'Annotation\' shall not contain \'Annotation\'s' + self.toString()):
        self.annotation->isEmpty()
  

  -- No comments to annotations
  inv AnnotationNestedComments ('An \'Annotation\' shall not contain \'Comment\'s.' + self.toString()):
        self.comment->isEmpty()
  



context Extension
  -- Inherit from element of the same meta-class
  inv Extension ('The element containing an \'Extension\' and the element in the \'extending\' property shall have the same meta-class.' + self.toString()):
        self.container().oclType()  = self.extending.oclType()
  



context Constraint
  -- Effectively static quantifiers 
  inv StaticQuantifiers ('All \'DataUse\'s specified as \'quantifier\'s shall be effectively static.' + self.toString()):
        self.quantifier->forAll(q | q.isEffectivelyStatic())
  

  -- Empty arguments for quantifiers 
  inv NoArgumentQuantifiers ('The \'argument\' sets for all \'DataUse\'s specified as \'quantifier\'s shall be empty.' + self.toString()):
        self.quantifier->forAll(q | q.argument->isEmpty())
  

  -- Constraint applicability for 'union' and 'uniontype' 
  inv ConstraintApplicabilityUnionUniontype ('The predefined \'ConstraintType\'s \'union\' and \'uniontype\' shall be applied to \'StructuredDataType\'s only. ' + self.toString()):
        (self.type.name = 'union' or self.type.name = 'uniontype') 
          implies self.container().oclIsTypeOf(StructuredDataType)
  

  -- Constraint applicability for 'range' and 'format'
  inv ConstraintApplicabilityRangeFormat ('The predefined \'ConstraintType\'s \'range\' and \'format\' shall be applied to \'SimpleDataType\'s and \'Member\'s with a \'SimpleDataType\' \'dataType\' only. ' + self.toString()):
        (self.type.name = 'range' or self.type.name = 'format') 
          implies (self.container().oclIsTypeOf(SimpleDataType)
             or (self.container().oclIsTypeOf(Member) 
                 and self.container().oclAsType(Member).dataType.oclIsTypeOf(SimpleDataType)))
  

  -- Constraint applicability for 'length', 'minLength', and 'maxLength' 
  inv ConstraintApplicabilityLength ('The predefined \'ConstraintType\'s \'length\', \'minLength\', and \'maxLength\' shall be applied to \'CollectionDataType\'s, \'SimpleDataType\'s and \'Member\'s with a \'SimpleDataType\' or a \'CollectionDataType\' \'dataType\' only. ' + self.toString()):
        (self.type.name = 'length' or self.type.name = 'minLength' or self.type.name = 'maxLength')
          implies (self.container().oclIsTypeOf(SimpleDataType)
              or self.container().oclIsTypeOf(CollectionDataType)
              or (self.container().oclIsTypeOf(Member) 
                 and self.container().oclAsType(Member).dataType.oclIsTypeOf(SimpleDataType))
                 and self.container().oclAsType(Member).dataType.oclIsTypeOf(CollectionDataType))
  

  -- Quantifiers for 'length', 'minLength', and 'maxLength'
  inv ConstraintQuantifierLength ('The predefined \'ConstraintType\'s \'length\', \'minLength\', and \'maxLength\' shall be used with exactly one \'quantifier\' resolved to an instance conforming to the predefined \'Integer\' \'DataType\'. ' + self.toString()):
        (self.type.name = 'length' or self.type.name = 'minLength' or self.type.name = 'maxLength') 
          implies (self.quantifier->size() = 1 
              and self.quantifier->forAll(q | q.resolveDataType().conformsTo('Integer')))
  

  -- Quantifiers for 'range' 
  inv ConstraintQuantifierRange ('The predefined \'ConstraintType\' \'range\' shall be used with exactly two \'quantifier\'s resolved to instance conforming to the predefined \'Integer\' \'DataType\'. ' + self.toString()):
        (self.type.name = 'length') 
          implies (self.quantifier->size() = 2 
              and self.quantifier->forAll(q | q.resolveDataType().conformsTo('Integer')))
  



context DataElementMapping
  -- Restricted use of 'ParameterMapping'
  inv ParameterMappingType ('A set of \'ParameterMapping\'s may only be provided if \'mappableDataElement\' refers to a \'StructuredDataType\', an \'Action\' or a \'Function\' definition and the \'mappableDataElement\' contains the mapped \'Parameters\'.' + self.toString()):
        self.parameterMapping->size() = 0
      or (self.mappableDataElement.oclIsTypeOf(StructuredDataType) 
      and self.parameterMapping->forAll(p | 
               self.mappableDataElement.oclAsType(StructuredDataType).allMembers()->includes(p.parameter))) 
      or (self.mappableDataElement.oclIsKindOf(Action) 
      and self.parameterMapping->forAll(p | 
               self.mappableDataElement.oclAsType(Action).formalParameter->includes(p.parameter)))
  

  -- All parameters shall be mapped
  inv ParameterMappings ('If the \'mappableDataElement\' refers to a \'StructuredDataType\', an \'Action\' or a \'Function\' definition, all the \'Parameters\' contained in the \'mappableDataElement\' shall be mapped.' + self.toString()):
        (self.mappableDataElement.oclIsTypeOf(SimpleDataType)
      or (self.mappableDataElement.oclIsTypeOf(StructuredDataType)
      and self.mappableDataElement.oclAsType(StructuredDataType).member->forAll(p | 
               self.parameterMapping->exists(m | m.parameter = p)))
      or (self.mappableDataElement.oclIsKindOf(Action) 
      and self.mappableDataElement.oclAsType(Action).formalParameter->forAll(p | 
               self.parameterMapping->exists(m | m.parameter = p)))
      and self.parameterMapping->forAll(p | 
               self.mappableDataElement.oclAsType(Action).formalParameter->includes(p.parameter)))
  



context SimpleDataInstance
  -- SimpleDataInstance shall refer to SimpleDataType
  inv SimpleDataInstanceType ('The inherited reference \'dataType\' from \'DataInstance\' shall refer to instances of \'SimpleDataType\' solely.' + self.toString()):
        self.dataType.oclIsKindOf(SimpleDataType)
  

  -- [Figure 6.3: Structured data type and instance]


context StructuredDataType
  -- Different member names in a structured data type
  inv DistinguishableMemberNames ('All \'Member\' names of a \'StructuredDataType\' (including the names of inherited \'Members\') shall be distinguishable.' + self.toString()):
        self.allMembers()->isUnique(e | e.name)
  



context StructuredDataInstance
  -- StructuredDataInstance shall refer to StructuredDataType
  inv StructuredDataInstance ('The inherited reference \'dataType\' from \'DataInstance\' shall refer to instances of \'StructuredDataType\' solely.' + self.toString()):
        self.dataType.oclIsTypeOf(StructuredDataType)
  

  -- 'Member' of the 'StructuredDataType'
  inv ExistingMemberOfDataType ('The referenced \'Member\' shall be contained in or inherited by the \'StructuredDataType\' that the \'StructuredDataInstance\', which contains this \'MemberAssignment\', refers to.' + self.toString()):
        self.memberAssignment->forAll(a | self.dataType.oclAsType(StructuredDataType).allMembers()->includes(a.member))
  

  -- Unique assignments for each 'Member' of the 'StructuredDataType'
  inv UniqueMemberAssignments ('There shall be at most one \'memberAssignment\' for each \'Member\' of the \'StructuredDataType\' that the \'StructuredDataInstance\', which contains this \'MemberAssignment\', refers to.' + self.toString()):
        self.memberAssignment->isUnique(m | m.member)
  

  -- 'union' constraint on the type of the 'StructuredDataInstance'
  inv StructuredDataInstanceUnionConstraint ('If the \'dataType\' of the \'StructuredDataInstance\' has the predefined constraint \'union\' then the \'memberAssignment\' shall not contain more than one \'MemberAssignment\'.' + self.toString()):
        not self.dataType.allConstraints()->exists(c | c.type.name = 'union')
          or self.memberAssignment->size() <= 1
  

  -- 'uniontype' constraint on the type of the 'StructuredDataInstance'
  inv StructuredDataInstanceUniontypeConstraint ('If the \'dataType\' of \'StructuredDataInstance\' has the predefined constraint \'uniontype\' then there shall only be \'MemberAssignment\' for the \'Member\'s of the \'dataType\' itself or of at most one of the \'StructuredDataType\'s which the \'dataType\' is extending.' + self.toString()):
        not self.dataType.allConstraints()->exists(c | c.type.name = 'uniontype')
          or self.memberAssignment->forAll(m | self.dataType.oclAsType(StructuredDataType).member->includes(m)
              or self.dataType.oclAsType(StructuredDataType).extension->one(e | 
                  e.extending.oclAsType(StructuredDataType).allMembers()->includes(m)))
  



context MemberAssignment
  -- Type of a 'memberSpec' shall conform to the type of the 'member'
  inv MatchingMemberDataType ('The \'DataType\' of the \'DataUse\' of \'memberSpec\' shall conform to the \'DataType\' of the \'Member\' of the \'MemberAssignment\'.' + self.toString()):
Loading
Loading full blame…