Package com.helger.schematron.pure.model
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:
The following example uses the abstract pattern for tables given above to create three patterns for tables with different names or structures.
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:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddForeignAttribute(String sAttrName, String sAttrValue) voidaddForeignElement(com.helger.xml.microdom.IMicroElement aForeignElement) voidaddInclude(PSInclude aInclude) Add an include to this object.voidAdd aPSLetelement.voidvoidvoidbooleancontainsRule(PSRule aRule) com.helger.commons.collection.impl.ICommonsList<IPSElement>com.helger.commons.collection.impl.ICommonsList<com.helger.xml.microdom.IMicroElement>com.helger.commons.collection.impl.ICommonsList<PSInclude>com.helger.commons.collection.impl.ICommonsList<PSLet>com.helger.commons.collection.impl.ICommonsList<PSParam>com.helger.commons.collection.impl.ICommonsList<PSP>getAllPs()com.helger.commons.collection.impl.ICommonsList<PSRule>com.helger.xml.microdom.IMicroElementgetID()getIsA()getRich()intgetRuleOfID(String sID) getTitle()booleanbooleanbooleanbooleanbooleanbooleanhasTitle()booleanbooleanbooleanisValid(IPSErrorHandler aErrorHandler) Check if this element is specified completely.voidremoveRule(Predicate<? super PSRule> aRuleFilter) voidsetAbstract(boolean bAbstract) voidSet an ID for this object.voidvoidsetRich(PSRichGroup aRich) Overwrite any existing rich group.voidtoString()voidvalidateCompletely(IPSErrorHandler aErrorHandler) Check if this element is specified completely.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.schematron.pure.model.IPSHasForeignAttributes
addForeignAttributesMethods inherited from interface com.helger.schematron.pure.model.IPSHasForeignElements
addForeignElementsMethods inherited from interface com.helger.schematron.pure.model.IPSHasRichGroup
getRichClone, hasRich
-
Constructor Details
-
PSPattern
public PSPattern()
-
-
Method Details
-
isValid
Description copied from interface:IPSElementCheck if this element is specified completely. This method stops at the first encountered error.- Specified by:
isValidin interfaceIPSElement- Parameters:
aErrorHandler- The error handler where the error details are stored. May not benull.- Returns:
trueif all mandatory fields are set and the element is valid,falseotherwise.
-
validateCompletely
Description copied from interface:IPSElementCheck if this element is specified completely. This method performs all validations independent of the number of encountered error.- Specified by:
validateCompletelyin interfaceIPSElement- Parameters:
aErrorHandler- The error handler where the error details are stored. May not benull.
-
isMinimal
public boolean isMinimal()- Specified by:
isMinimalin interfaceIPSElement- Returns:
trueif this element conforms to the Schematron minimal syntax,falseotherwise.
-
hasForeignElements
public boolean hasForeignElements()- Specified by:
hasForeignElementsin interfaceIPSHasForeignElements
-
getAllForeignElements
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<com.helger.xml.microdom.IMicroElement> getAllForeignElements()- Specified by:
getAllForeignElementsin interfaceIPSHasForeignElements
-
addForeignElement
- Specified by:
addForeignElementin interfaceIPSHasForeignElements
-
hasForeignAttributes
public boolean hasForeignAttributes()- Specified by:
hasForeignAttributesin interfaceIPSHasForeignAttributes
-
getAllForeignAttributes
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAllForeignAttributes()- Specified by:
getAllForeignAttributesin interfaceIPSHasForeignAttributes
-
addForeignAttribute
- Specified by:
addForeignAttributein interfaceIPSHasForeignAttributes
-
isAbstract
public boolean isAbstract() -
setAbstract
public void setAbstract(boolean bAbstract) -
getID
-
setID
Description copied from interface:IPSHasIDSet an ID for this object. -
getIsA
-
setIsA
-
getRich
- Specified by:
getRichin interfaceIPSHasRichGroup- Returns:
- Get the existing rich group or
nullif none is present.
-
setRich
Description copied from interface:IPSHasRichGroupOverwrite any existing rich group.- Specified by:
setRichin interfaceIPSHasRichGroup- Parameters:
aRich- The new rich group to set. May benull.
-
hasAnyInclude
public boolean hasAnyInclude()- Specified by:
hasAnyIncludein interfaceIPSHasIncludes- Returns:
trueif at least one include is present in this object.
-
getAllIncludes
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSInclude> getAllIncludes()- Specified by:
getAllIncludesin interfaceIPSHasIncludes- Returns:
- A list of all contained includes. Never
null.
-
addInclude
Description copied from interface:IPSHasIncludesAdd an include to this object.- Specified by:
addIncludein interfaceIPSHasIncludes- Parameters:
aInclude- The include to be added. May not benull.
-
getTitle
-
hasTitle
public boolean hasTitle() -
setTitle
-
getRuleOfID
-
getAllRules
-
containsRule
-
getRuleCount
-
addRule
-
removeRule
-
getAllParams
-
hasAnyParam
public boolean hasAnyParam() -
addParam
-
getAllPs
-
addP
-
hasAnyLet
public boolean hasAnyLet()- Specified by:
hasAnyLetin interfaceIPSHasLets- Returns:
trueif this object has at least on containedPSLetobject.
-
getAllLets
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<PSLet> getAllLets()- Specified by:
getAllLetsin interfaceIPSHasLets- Returns:
- A list of all contained
PSLetelements. Nevernull.
-
addLet
Description copied from interface:IPSHasLetsAdd aPSLetelement.- Specified by:
addLetin interfaceIPSHasLets- Parameters:
aLet- The let element to be added. May not benull.
-
getAllLetsAsMap
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAllLetsAsMap()- Specified by:
getAllLetsAsMapin interfaceIPSHasLets- Returns:
- The content of all
PSLetelements as an ordered Map from name to value. The order must match the declaration order! Nevernull.
-
getAllContentElements
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<IPSElement> getAllContentElements() -
getAsMicroElement
- Specified by:
getAsMicroElementin interfaceIPSElement- Returns:
- The XML representation of this element. Never
null.
-
toString
-