Package com.saxonica.ee.schema
Class Wildcard
- java.lang.Object
-
- com.saxonica.ee.schema.SchemaStructure
-
- com.saxonica.ee.schema.Wildcard
-
- All Implemented Interfaces:
SerializableSchemaComponent
,Term
,UserSchemaComponent
,javax.xml.transform.SourceLocator
,Location
,SchemaComponent
,org.xml.sax.Locator
public class Wildcard extends SchemaStructure implements UserSchemaComponent, SerializableSchemaComponent, Term
A class that represents an XML Schema Wildcard. This is a helper class used to support the two distinct but similar schema components ElementWildcard and AttributeWildcard.A wildcard is represented by the XML elements xs:any and xs:anyAttribute
-
-
Constructor Summary
Constructors Constructor Description Wildcard()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAllowedNamespace(java.lang.String namespace)
Add a permitted namespace.void
addDisallowedNamespace(java.lang.String namespace)
Add a disallowed namespace.void
addDisallowedQName(int fingerprint)
Mark a specific QName as being disallowedboolean
allowsAny()
Determine whether this wildcard allows any namespace (##any)int
compareStrength(Wildcard other)
boolean
disallowsQName(int fingerprint)
Test whether a name is in the set of disallowed QNamesjava.util.Set<java.lang.String>
getAllowedNamespaces()
Returns the set of permitted namespaces of this wildcardFunction
getComponentAsFunction()
Get the schema component in the form of a function item.java.util.Set<java.lang.String>
getDisallowedNamespaces()
Get the disallowed namespaces.java.lang.String
getProcessContents()
Returns the processContents attribute of this wildcardboolean
isDisallowDefinedNames()
Ask whether globally-defined names are disallowedboolean
isDisallowDefinedSiblings()
Ask whether defined siblings are disallowedboolean
isDisallowedQName(int fingerprint)
Ask whether a specific QName is disallowedboolean
isInexpressible()
Determine whether this wildcard represents an "inexpressible" intersection or unionstatic boolean
isNotStronger(java.lang.String str1, java.lang.String str2)
Test whether one processContents value is <= the strength of another, where skip < lax < strictboolean
isSubset(Wildcard sup, NamePool pool)
Determine whether this wildcard is a subset of another wildcard.static Wildcard
makeIntersection(Wildcard wat1, Wildcard wat2, NamePool pool)
Create an AttributeWildcard as the intersection of two AttributeWildcards.static Wildcard
makeUnion(Wildcard wat1, Wildcard wat2, NamePool pool)
Create a AttributeWildcard as the union of two AttributeWildcards.boolean
matches(int fp, boolean isElement, Configuration config, UserComplexType parentType)
boolean
matches(java.lang.String uri)
Determine whether a particular namespace is allowed by this wildcard.boolean
matches(NodeName name, boolean isElement, Configuration config, UserComplexType parentType)
Determine whether a name is allowed by this wildcard.boolean
matches(StructuredQName name, boolean isElement, Configuration config, UserComplexType parentType)
Determine whether a name is allowed by this wildcard.boolean
overlaps(Wildcard other)
Determine whether this wildcard overlaps another wildcard, that is, whether there is an element that could match either.java.lang.String
reasonForNonMatch(NodeName nn, boolean isElement, Configuration config, UserComplexType parentType)
If matches() returns false, return a string explaining the reason for the non-matchvoid
serialize(SchemaModelSerializer serializer)
Serialize this schema componentvoid
setDisallowDefinedNames(boolean disallow)
Say that defined names are not allowed (notQName = "##defined")void
setDisallowDefinedSiblings(boolean disallow)
Say that defined siblings are not allowed (notQName = "##definedSibling")void
setNoNamespacesAllowed()
Initialize the set of permitted namespaces to an empty set.void
setProcessContents(java.lang.String process)
Sets the processContents attribute of the wildCard.java.lang.String
toString()
Get a string representation of this wildcard, used for diagnosticsboolean
validate(SchemaCompiler compiler)
Perform validation on this wildcard (this implementation of the method is a no-op)-
Methods inherited from class com.saxonica.ee.schema.SchemaStructure
elaborate, fixup, getColumnNumber, getConfiguration, getFixupStatus, getGeneratedId, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, hasSameLocation, isValidationNeeded, lookForCycles, makeXPathExpressionPropertyRecord, saveLocation, setConfiguration, setFixupStatus, setGeneratedId, setLineNumber, setLocator, setRedefinitionLevel, setSchemaDocumentURI, setSystemId, setValidationStatus
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getRedefinitionLevel, getValidationStatus
-
Methods inherited from interface com.saxonica.ee.schema.UserSchemaComponent
elaborate, fixup, lookForCycles
-
-
-
-
Method Detail
-
isInexpressible
public boolean isInexpressible()
Determine whether this wildcard represents an "inexpressible" intersection or union- Returns:
- true if the intersection or union is inexpressible, as defined in XML Schema. This is essentially an error condition, so the wildcard should not be used if this property is true.
-
allowsAny
public final boolean allowsAny()
Determine whether this wildcard allows any namespace (##any)- Returns:
- true if this wildcard allows any namespace
-
setNoNamespacesAllowed
public void setNoNamespacesAllowed()
Initialize the set of permitted namespaces to an empty set. This is needed in case the namespace attribute is present but empty; it indicates that no namespaces are allowed.
-
addAllowedNamespace
public void addAllowedNamespace(java.lang.String namespace)
Add a permitted namespace. This must be an actual namespace, not one of the special tokens such as ##other; the non-namespace ("absent") is represented by the zero-length string. Validation of the namespace is the responsibility of the caller.- Parameters:
namespace
- the namespace to add
-
addDisallowedNamespace
public void addDisallowedNamespace(java.lang.String namespace)
Add a disallowed namespace. This corresponds to the option ##other.- Parameters:
namespace
- the disallowed namespace to be added
-
getDisallowedNamespaces
public java.util.Set<java.lang.String> getDisallowedNamespaces()
Get the disallowed namespaces. Returns null if there is no disallowed namespace.- Returns:
- the set of disallowed namespaces; may be null to represent the empty set
-
matches
public boolean matches(java.lang.String uri)
Determine whether a particular namespace is allowed by this wildcard. This method ignores the QNames that have been explicitly disallowed (using notQNames)- Parameters:
uri
- the namespace to be tested. Supply "" for the no-namespace.- Returns:
- true if the wildcard allows this namespace, false if not.
-
matches
public boolean matches(StructuredQName name, boolean isElement, Configuration config, UserComplexType parentType)
Determine whether a name is allowed by this wildcard. This method ignores the restrictions imposed by ##definedSiblings- Parameters:
name
- the name to be testedisElement
- true if looking for an element, false if looking for an attributeconfig
- the Saxon configurationparentType
- the governing type definition of the parent element, used to assess whether the ##definedSibling constraint prevents an element from matching. May be null, in which case ##definedSibling is ignored.- Returns:
- true if the wildcard allows this name, false if not.
-
matches
public boolean matches(int fp, boolean isElement, Configuration config, UserComplexType parentType)
-
matches
public boolean matches(NodeName name, boolean isElement, Configuration config, UserComplexType parentType)
Determine whether a name is allowed by this wildcard. This method ignores the restrictions imposed by ##definedSiblings- Parameters:
name
- the name to be testedisElement
- true if looking for an element, false if looking for an attributeconfig
- the Saxon configurationparentType
- the governing type definition of the parent element, used to assess whether the ##definedSibling constraint prevents an element from matching. May be null, in which case ##definedSibling is ignored.- Returns:
- true if the wildcard allows this name, false if not.
-
reasonForNonMatch
public java.lang.String reasonForNonMatch(NodeName nn, boolean isElement, Configuration config, UserComplexType parentType)
If matches() returns false, return a string explaining the reason for the non-match- Parameters:
nn
- the name of the node that does not match the wildcardisElement
- true if looking for an element, false if looking for an attributeconfig
- the Saxon configurationparentType
- the governing type definition of the parent element, used to assess whether the ##definedSibling constraint prevents an element from matching. May be null, in which case ##definedSibling is ignored.- Returns:
- null if the name matches, or a string explaining the reason if not. The string will be in the form of one or more complete English sentences terminated by a full stop and trailing space.
-
disallowsQName
public boolean disallowsQName(int fingerprint)
Test whether a name is in the set of disallowed QNames- Parameters:
fingerprint
- the fingerprint of the name to be tested- Returns:
- true if the name is in the set of explicitly disallowed QNames
-
getAllowedNamespaces
public java.util.Set<java.lang.String> getAllowedNamespaces()
Returns the set of permitted namespaces of this wildcard- Returns:
- the set of permitted namespaces of this wildcard, or null if no namespaces are explicitly permitted
-
getProcessContents
public java.lang.String getProcessContents()
Returns the processContents attribute of this wildcard- Returns:
- the processContents attribute of this wildcard, as a string ("strict", "lax", or "skip")
-
setProcessContents
public void setProcessContents(java.lang.String process)
Sets the processContents attribute of the wildCard. For internal use only.- Parameters:
process
- the processContents value to set (e.g. "strict", "lax"). Validation of the value is the responsibility of the caller.
-
setDisallowDefinedNames
public void setDisallowDefinedNames(boolean disallow)
Say that defined names are not allowed (notQName = "##defined")- Parameters:
disallow
- true if defined names are disallowed
-
isDisallowDefinedNames
public boolean isDisallowDefinedNames()
Ask whether globally-defined names are disallowed- Returns:
- true if globally-defined names are disallowed (notQName = "##defined")
-
setDisallowDefinedSiblings
public void setDisallowDefinedSiblings(boolean disallow)
Say that defined siblings are not allowed (notQName = "##definedSibling")- Parameters:
disallow
- true if defined siblings are disallowed
-
isDisallowDefinedSiblings
public boolean isDisallowDefinedSiblings()
Ask whether defined siblings are disallowed- Returns:
- true if the names of defined siblings are disallowed (notQName = "##definedSibling")
-
addDisallowedQName
public void addDisallowedQName(int fingerprint)
Mark a specific QName as being disallowed- Parameters:
fingerprint
- the NamePool fingerprint of the disallowed name
-
isDisallowedQName
public boolean isDisallowedQName(int fingerprint)
Ask whether a specific QName is disallowed- Parameters:
fingerprint
- the NamePool fingerprint of the QName in question- Returns:
- true if the QName is in the list of QNames specifically disallowed by this wildcard
-
validate
public boolean validate(SchemaCompiler compiler)
Perform validation on this wildcard (this implementation of the method is a no-op)- Specified by:
validate
in interfaceUserSchemaComponent
- Overrides:
validate
in classSchemaStructure
- Parameters:
compiler
- the schema compiler- Returns:
- true when this Schema definition is valid, otherwise false.
-
toString
public java.lang.String toString()
Get a string representation of this wildcard, used for diagnostics- Overrides:
toString
in classjava.lang.Object
-
isSubset
public boolean isSubset(Wildcard sup, NamePool pool)
Determine whether this wildcard is a subset of another wildcard. See Schema Part 1 Schema Component Constraint: Wildcard Subset (section 3.10.6.2)- Parameters:
sup
- the other wildcardpool
- the NamePool- Returns:
- true if this wildcard is a subset of the other wildcard, as defined in the XSD specification
-
overlaps
public boolean overlaps(Wildcard other)
Determine whether this wildcard overlaps another wildcard, that is, whether there is an element that could match either. Note, this is no longer a defined algorithm in Schema 1.1, but it is still needed to assess UPA.- Parameters:
other
- the other wildcard- Returns:
- true if the two wildcards overlap, that is, if there are possible elements that could match either of the wildcards
-
isNotStronger
public static boolean isNotStronger(java.lang.String str1, java.lang.String str2)
Test whether one processContents value is <= the strength of another, where skip < lax < strict- Parameters:
str1
- the first processContents value, as a stringstr2
- the second processContents value, as a string- Returns:
- true if the pair is one of (strict, strict), (lax, lax), (skip, skip), (skip, strict), (lax, strict), (skip, lax)
-
compareStrength
public int compareStrength(Wildcard other)
-
makeIntersection
public static Wildcard makeIntersection(Wildcard wat1, Wildcard wat2, NamePool pool)
Create an AttributeWildcard as the intersection of two AttributeWildcards. For internal use only.In XML Schema 1.1, the intersection of two wildcards is always expressible. The resulting wildcard might not be expressible using XML Schema 1.0, however.
- Parameters:
wat1
- the first operand: the processContents is taken from this operandwat2
- the second operandpool
- the NamePool- Returns:
- a new AttributeWildcard representing the intersection, as defined in Schema Component Constraint: Attribute Wildcard Intersection; if the intersection "is not expressible" this will be flagged as such, for later rejection by the validator.
-
makeUnion
public static Wildcard makeUnion(Wildcard wat1, Wildcard wat2, NamePool pool)
Create a AttributeWildcard as the union of two AttributeWildcards. For internal use only.- Parameters:
wat1
- the first operand: the processContents is taken from this operandwat2
- the second operandpool
- the Name Pool- Returns:
- a new AttributeWildcard representing the union, as defined in Schema Component Constraint: Attribute Wildcard Union; if the union "is not expressible" then the result will be marked as such, for later use by the validator.
-
serialize
public void serialize(SchemaModelSerializer serializer) throws XPathException
Serialize this schema component- Specified by:
serialize
in interfaceSerializableSchemaComponent
- Parameters:
serializer
- the object responsible for performing the serialization- Throws:
XPathException
- if serialization fails
-
getComponentAsFunction
public Function getComponentAsFunction()
Description copied from interface:SchemaComponent
Get the schema component in the form of a function item. This allows schema information to be made visible to XSLT or XQuery code. The function makes available the contents of the schema component as defined in the XSD specification. The function takes a string as argument representing a property name, and returns the corresponding property of the schema component. There is also a property "class" which returns the kind of schema component, for example "Attribute Declaration".- Specified by:
getComponentAsFunction
in interfaceSchemaComponent
- Overrides:
getComponentAsFunction
in classSchemaStructure
- Returns:
- the schema component represented as a function from property names to property values.
-
-