Class PuzzlePieceSet

  • All Implemented Interfaces:
    Iterable<PuzzlePiece>, Collection<PuzzlePiece>, PuzzleComponent, QNamed, QNamedPuzzleComponent

    public class PuzzlePieceSet
    extends Object
    implements QNamedPuzzleComponent, Collection<PuzzlePiece>
    Collection Class for RelaxNG definitions of an Element, Attribute, Value or Datatype.

    Conventions:

    • PuzzlePiece sorting is done by ns:local tag names as first key and hashCode as second key (see class PuzzlePiece).
    • Since it is a Collection, PuzzlePieceSet is not meant to be used in a Collection. So equals(o) and hashCode() are not overwritten
    • All returned PuzzlePieceSet objects are immutable to protect them against naive usage in velocity templates
    • Constructor Detail

      • PuzzlePieceSet

        public PuzzlePieceSet()
    • Method Detail

      • makeImmutable

        public void makeImmutable()
        Make PuzzlePieceSet immutable. Cannot be undone.

        Template Usage: Not for use in templates as all PuzzlePieceSet already have been made immutable.

      • withoutMultiples

        public PuzzlePieceSet withoutMultiples()
        Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but restricted to one PuzzlePiece per Name.

        Template Usage: #foreach ($element in $elements.withoutMultiples())

        Returns:
        new PuzzlePieceSet
      • without

        public PuzzlePieceSet without​(QNamedPuzzleComponent removeAll)
        Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but without the elements of the parameter removeAll

        Template Usage: #set ($non_base_attributes = $element.getAttributes().without($baseclass.getAttributes())

        Parameters:
        removeAll - QNamedPuzzleComponent which (or which elements) should be removed from the new PuzzlePieceSet
        Returns:
        new PuzzlePieceSet
      • byParent

        public PuzzlePieceSet byParent​(QNamedPuzzleComponent parents)
        Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but only those which have at least one element from the QNamedPuzzleComponent parameter as one of their parent Definitions.

        Template Usage: Imagine we have one attribute name and we're not interested in the differences between Definitions sharing the same name. We're now printing the resulting allowed attribute values for each parent element name:
        #set ( $oneOrMoreAttributes = $model.getAttribute($atttributename) )
        ## we want to write information about only _one_ parent per Name...
        #foreach ($parent in $oneOrMoreAttributes.getParents().withoutMultiples())
        - Allowed Values for Parent Element $parent :
        ## but we want the attribute values displayed which are allowed in _all_ parents with the same Name...
        #foreach ($value in $oneOrMoreAttributes.byParent($parent.withMultiples()).getValues())
        -- "$value"
        #end
        #end

        Parameters:
        parents -
        Returns:
        new PuzzlePieceSet
      • containsName

        public boolean containsName​(String aDefinitionName)
        Check whether this List contains an Element by this Name
        Parameters:
        aDefinitionName -
        Returns:
        True if an element by this name exists
      • containsName

        public boolean containsName​(QNamed aNamed)
        Check whether this List contains an Element by this Name
        Parameters:
        aNamed -
        Returns:
        True if an element by this name exists
      • getQName

        public String getQName()
        Gets the ns:local tag name of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions share the same tag name. Throws Exception otherwise.
        Specified by:
        getQName in interface QNamed
        Returns:
        The tag name
      • getType

        public MSVExpressionType getType()
        Gets the type of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name. Throws Exception otherwise.
        Specified by:
        getType in interface PuzzleComponent
        Returns:
        The type of this PuzzleComponent
      • canHaveText

        public boolean canHaveText()
        Determines whether the Definitions can have text - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name. Throws Exception otherwise.
        Specified by:
        canHaveText in interface PuzzleComponent
        Returns:
        True if a text node is allowed, false otherwise
      • isSingleton

        public boolean isSingleton​(PuzzleComponent child)
        Description copied from interface: PuzzleComponent
        Determines whether the child PuzzlePiece(s) is/are singleton(s)

        Convention: If child is a collection this method returns false if one child element is no singleton. If this is a collection this method returns false if child is no singleton for one element of this.

        Specified by:
        isSingleton in interface PuzzleComponent
        Parameters:
        child - PuzzleComponent child
        Returns:
        True if child is defined as Singleton, falso otherwise.
      • getLocalName

        public String getLocalName()
        Description copied from interface: QNamed
        Get only localname
        Specified by:
        getLocalName in interface QNamed
        Returns:
        localname
      • getNamespace

        public String getNamespace()
        Description copied from interface: QNamed
        Get only namespace
        Specified by:
        getNamespace in interface QNamed
        Returns:
        namespace
      • toString

        public String toString()
        Returns String representation (convenient method for getQName())

        Template Usage: Just use $aDefinitionSet as you would use a string variable

        Overrides:
        toString in class Object
      • isMandatory

        public boolean isMandatory​(QNamedPuzzleComponent child)
        Description copied from interface: QNamedPuzzleComponent
        ELEMENT Definition only: Determine solely by child type and name whether child is mandatory.

        Here's why we're not using the child Definition object(s) for this: An element often has a mandatory attribute, but two (or more) different content definitions for this attribute. This is done by defining this attribute twice and creating a CHOICE between both Definitions. If you'd ask whether one of these definitions is mandatory, you'd always get false as answer as you have the choice between the two definitions. Mostly this is not the answer you're looking for.

        Contract: If 'this' is a Collection, mandatory means mandatory for one member of 'this'.

        Specified by:
        isMandatory in interface QNamedPuzzleComponent
        Parameters:
        child - The child Definition(s) of type ELEMENT or ATTRIBUTE
        Returns:
        true if child is a defined child of this and if it's mandatory. False otherwise.
      • getValues

        public PuzzlePieceSet getValues()
        Description copied from interface: PuzzleComponent
        ATTRIBUTE PuzzlePiece only: Get all value Definitions
        Specified by:
        getValues in interface PuzzleComponent
        Returns:
        The constant value Definitions of this PuzzleComponent