Class PSPattern

java.lang.Object
com.helger.schematron.pure.model.PSPattern
All Implemented Interfaces:
IPSElement, IPSHasForeignAttributes, IPSHasForeignElements, IPSHasID, IPSHasIncludes, IPSHasLets, IPSHasRichGroup

@NotThreadSafe public class PSPattern extends Object implements IPSElement, IPSHasID, IPSHasForeignElements, IPSHasIncludes, IPSHasLets, IPSHasRichGroup
A single Schematron pattern-element.
A structure, simple or complex. A set of rules giving constraints that are in some way related. The id attribute provides a unique name for the pattern and is required for abstract patterns.
The title and p elements allow rich documentation.
The icon, see and fpi attributes allow rich interfaces and documentation.
When a pattern element has the attribute abstract with a value true, then the pattern defines an abstract pattern. An abstract pattern shall not have a is-a attribute and shall have an id attribute.
Abstract patterns allow a common definition mechanism for structures which use different names and paths, but which are at heart the same. For example, there are different table markup languages, but they all can be in large part represented as an abstract pattern where a table contains rows and rows contain entries, as defined in the following example using the default query language binding:
     <sch:pattern abstract="true" id="table">
         <sch:rule context="$table">
             <sch:assert test="$row">
             The element <sch:name/> is a table. Tables contain rows.
             </sch:assert>
         </sch:rule>
         <sch:rule context="$row">
             <sch:assert test="$entry">
             The element <sch:name/> is a table row. Rows contain entries.
             </sch:assert>
         </sch:rule>
     </sch:pattern>
 
When a pattern element has the attribute is-a with a value specifying the name of an abstract pattern, then the pattern is an instance of an abstract pattern. Such a pattern shall not contain any rule elements, but shall have param elements for all parameters used in the abstract pattern.
The following example uses the abstract pattern for tables given above to create three patterns for tables with different names or structures.
     <sch:pattern is-a="table" id="HTML_Table">
         <sch:param name="table" value="table"/>
         <sch:param name="row"   value="tr"/>
         <sch:param name="entry" value="td|th"/>
     </sch:pattern>
     <sch:pattern is-a="table" id="CALS_Table">
         <sch:param name="table" value="table"/>
         <sch:param name="row"   value=".//row"/>
         <sch:param name="entry" value="cell"/>
     </sch:pattern>
     <sch:pattern is-a="table" id="calendar">
         <sch:param name="table" value="calendar/year"/>
         <sch:param name="row"   value="week"/>
         <sch:param name="entry" value="day"/>
     </sch:pattern>
 
When creating an instance of an abstract pattern, the parameter values supplied by the param element replace the parameter references used in the abstract patterns. The examples above use the default query language binding in which the character $ is used as the delimiter for parameter references.
Thus, given the abstract patterns defined earlier in this clause, the patterns defined above are equivalent to the following, with the id elements shown expanded:
     <sch:pattern id="HTML_table">
         <sch:rule context="table">
             <sch:assert test="tr">
             The element table is a table. Tables containing rows.
             </sch:assert>
         </sch:rule>
         <sch:rule context="tr">
             <sch:assert test="td|th">
             The element tr is a table row. Rows contain entries.
             </sch:assert>
         </sch:rule>
     </sch:pattern>
     <sch:pattern id="CALS_table">
         <sch:rule context="table">
             <sch:assert test=".//row">
             The element table is a table. Tables containing rows.
             </sch:assert>
         </sch:rule>
         <sch:rule context=".//row">
             <sch:assert test="cell">
             The element row is a table row. Rows contain entries.
             </sch:assert>
         </sch:rule>
     </sch:pattern>
     <sch:pattern id="calendar">
         <sch:rule context="calendar/year">
             <sch:assert test="week">
             The element year is a table. Tables containing rows.
             </sch:assert>
         </sch:rule>
         <sch:rule context="week">
             <sch:assert test="day">
             The element week is a table row. Rows contain entries.
             </sch:assert>
         </sch:rule>
     </sch:pattern>
 
Author:
Philip Helger
  • Constructor Details

    • PSPattern

      public PSPattern()
  • Method Details

    • isValid

      public boolean isValid(@Nonnull IPSErrorHandler aErrorHandler)
      Description copied from interface: IPSElement
      Check if this element is specified completely. This method stops at the first encountered error.
      Specified by:
      isValid in interface IPSElement
      Parameters:
      aErrorHandler - The error handler where the error details are stored. May not be null.
      Returns:
      true if all mandatory fields are set and the element is valid, false otherwise.
    • validateCompletely

      public void validateCompletely(@Nonnull IPSErrorHandler aErrorHandler)
      Description copied from interface: IPSElement
      Check if this element is specified completely. This method performs all validations independent of the number of encountered error.
      Specified by:
      validateCompletely in interface IPSElement
      Parameters:
      aErrorHandler - The error handler where the error details are stored. May not be null.
    • isMinimal

      public boolean isMinimal()
      Specified by:
      isMinimal in interface IPSElement
      Returns:
      true if this element conforms to the Schematron minimal syntax, false otherwise.
    • hasForeignElements

      public boolean hasForeignElements()
      Specified by:
      hasForeignElements in interface IPSHasForeignElements
    • getAllForeignElements

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<com.helger.xml.microdom.IMicroElement> getAllForeignElements()
      Specified by:
      getAllForeignElements in interface IPSHasForeignElements
    • addForeignElement

      public void addForeignElement(@Nonnull com.helger.xml.microdom.IMicroElement aForeignElement)
      Specified by:
      addForeignElement in interface IPSHasForeignElements
    • hasForeignAttributes

      public boolean hasForeignAttributes()
      Specified by:
      hasForeignAttributes in interface IPSHasForeignAttributes
    • getAllForeignAttributes

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAllForeignAttributes()
      Specified by:
      getAllForeignAttributes in interface IPSHasForeignAttributes
    • addForeignAttribute

      public void addForeignAttribute(@Nonnull String sAttrName, @Nonnull String sAttrValue)
      Specified by:
      addForeignAttribute in interface IPSHasForeignAttributes
    • isAbstract

      public boolean isAbstract()
    • setAbstract

      public void setAbstract(boolean bAbstract)
    • getID

      @Nullable public String getID()
      Specified by:
      getID in interface IPSHasID
      Returns:
      The optional ID of this element. May be null.
    • setID

      public void setID(@Nullable String sID)
      Description copied from interface: IPSHasID
      Set an ID for this object.
      Specified by:
      setID in interface IPSHasID
      Parameters:
      sID - The ID to be set. May be null.
    • getIsA

      @Nullable public String getIsA()
    • setIsA

      public void setIsA(@Nullable String sIsA)
    • getRich

      @Nullable public PSRichGroup getRich()
      Specified by:
      getRich in interface IPSHasRichGroup
      Returns:
      Get the existing rich group or null if none is present.
    • setRich

      public void setRich(@Nullable PSRichGroup aRich)
      Description copied from interface: IPSHasRichGroup
      Overwrite any existing rich group.
      Specified by:
      setRich in interface IPSHasRichGroup
      Parameters:
      aRich - The new rich group to set. May be null.
    • hasAnyInclude

      public boolean hasAnyInclude()
      Specified by:
      hasAnyInclude in interface IPSHasIncludes
      Returns:
      true if at least one include is present in this object.
    • getAllIncludes

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSInclude> getAllIncludes()
      Specified by:
      getAllIncludes in interface IPSHasIncludes
      Returns:
      A list of all contained includes. Never null.
    • addInclude

      public void addInclude(@Nonnull PSInclude aInclude)
      Description copied from interface: IPSHasIncludes
      Add an include to this object.
      Specified by:
      addInclude in interface IPSHasIncludes
      Parameters:
      aInclude - The include to be added. May not be null.
    • getTitle

      @Nullable public PSTitle getTitle()
    • hasTitle

      public boolean hasTitle()
    • setTitle

      public void setTitle(@Nullable PSTitle aTitle)
    • getRuleOfID

      @Nullable public PSRule getRuleOfID(@Nullable String sID)
    • getAllRules

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSRule> getAllRules()
    • containsRule

      public boolean containsRule(@Nullable PSRule aRule)
    • getRuleCount

      @Nonnegative public int getRuleCount()
    • addRule

      public void addRule(@Nonnull PSRule aRule)
    • removeRule

      public void removeRule(@Nonnull Predicate<? super PSRule> aRuleFilter)
    • getAllParams

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSParam> getAllParams()
    • hasAnyParam

      public boolean hasAnyParam()
    • addParam

      public void addParam(@Nonnull PSParam aParam)
    • getAllPs

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSP> getAllPs()
    • addP

      public void addP(@Nonnull PSP aP)
    • hasAnyLet

      public boolean hasAnyLet()
      Specified by:
      hasAnyLet in interface IPSHasLets
      Returns:
      true if this object has at least on contained PSLet object.
    • getAllLets

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSLet> getAllLets()
      Specified by:
      getAllLets in interface IPSHasLets
      Returns:
      A list of all contained PSLet elements. Never null.
    • addLet

      public void addLet(@Nonnull PSLet aLet)
      Description copied from interface: IPSHasLets
      Add a PSLet element.
      Specified by:
      addLet in interface IPSHasLets
      Parameters:
      aLet - The let element to be added. May not be null.
    • getAllLetsAsMap

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAllLetsAsMap()
      Specified by:
      getAllLetsAsMap in interface IPSHasLets
      Returns:
      The content of all PSLet elements as an ordered Map from name to value. The order must match the declaration order! Never null.
    • getAllContentElements

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<IPSElement> getAllContentElements()
      Returns:
      A list consisting of PSP, PSLet, PSRule and PSParam parameters
    • getAsMicroElement

      @Nonnull public com.helger.xml.microdom.IMicroElement getAsMicroElement()
      Specified by:
      getAsMicroElement in interface IPSElement
      Returns:
      The XML representation of this element. Never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object