com.saxonica.schema
Class Wildcard

java.lang.Object
  extended by com.saxonica.schema.SchemaStructure
      extended by com.saxonica.schema.Wildcard
All Implemented Interfaces:
SerializableSchemaComponent, Term, UserSchemaComponent, Serializable, SourceLocator, SchemaComponent

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 wilcard is represented by the XML elements xs:any and xs:anyAttribute

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.saxon.type.SchemaComponent
FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING
 
Constructor Summary
Wildcard()
           
 
Method Summary
 void addAllowedNamespace(String namespace)
          Add a permitted namespace.
 void addDisallowedNamespace(String namespace)
          Add a disallowed namespace.
 void addDisallowedQName(int fingerprint)
          Mark a specific QName as being disallowed
 boolean 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 QNames
 Set<String> getAllowedNamespaces()
          Returns the set of permitted namespaces of this wildcard
 Set<String> getDisallowedNamespaces()
          Get the disallowed namespaces.
 String getProcessContents()
          Returns the processContents attribute of this wildcard
 boolean isDisallowDefinedNames()
          Ask whether globally-defined names are disallowed
 boolean isDisallowDefinedSiblings()
          Ask whether defined siblings are disallowed
 boolean isDisallowedQName(int fingerprint)
          Ask whether a specific QName is disallowed
 boolean isInexpressible()
          Determine whether this wildcard represents an "inexpressible" intersection or union
static boolean isNotStronger(String str1, String str2)
          Test whether one processContents value is <= the strength of another, where skip < lax < strict
 boolean 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 fingerprint, boolean isElement, Configuration config, UserComplexType parentType)
          Determine whether a name is allowed by this wildcard.
 boolean matches(String uri)
          Determine whether a particular namespace 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.
 String reasonForNonMatch(int fingerprint, boolean isElement, Configuration config)
          If matches() returns false, return a string explaining the reason for the non-match
 void serialize(SchemaModelSerializer serializer)
          Serialize this schema component
 void 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(String process)
          Sets the processContents attribute of the wildCard.
 String toString()
          Get a string representation of this wildcard, used for diagnostics
 boolean validate(SchemaCompiler compiler)
          Perform validation on this wildcard (this implementation of the method is a no-op)
 
Methods inherited from class com.saxonica.schema.SchemaStructure
elaborate, fixup, getColumnNumber, getConfiguration, getFixupStatus, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, lookForCycles, setConfiguration, setFixupStatus, 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 com.saxonica.schema.UserSchemaComponent
elaborate, fixup, lookForCycles
 
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getRedefinitionLevel, getValidationStatus
 

Constructor Detail

Wildcard

public Wildcard()
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(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(String namespace)
Add a disallowed namespace. This corresponds to the option ##other.

Parameters:
namespace - the disallowed namespace to be added

getDisallowedNamespaces

public Set<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(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(int fingerprint,
                       boolean isElement,
                       Configuration config,
                       UserComplexType parentType)
Determine whether a name is allowed by this wildcard. This method ignores the restrictions imposed by ##definedSiblings

Parameters:
fingerprint - the fingerprint of the name
isElement - true if looking for an element, false if looking for an attribute
config - the Saxon configuration
parentType - 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 String reasonForNonMatch(int fingerprint,
                                boolean isElement,
                                Configuration config)
If matches() returns false, return a string explaining the reason for the non-match

Parameters:
fingerprint - the fingerprint of the name
isElement - true if looking for an element, false if looking for an attribute
config - the Saxon configuration
Returns:
null if the name matches, or a string explaining the reason if not

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 Set<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 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(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)
                 throws SchemaException
Perform validation on this wildcard (this implementation of the method is a no-op)

Specified by:
validate in interface UserSchemaComponent
Returns:
true when this Schema definition is valid, otherwise false.
Throws:
SchemaException

toString

public String toString()
Get a string representation of this wildcard, used for diagnostics

Overrides:
toString in class 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 wildcard
pool - 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(String str1,
                                    String str2)
Test whether one processContents value is <= the strength of another, where skip < lax < strict

Parameters:
str1 - the first processContents value, as a string
str2 - 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 operand
wat2 - the second operand
pool - 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 operand
wat2 - the second operand
pool - 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 interface SerializableSchemaComponent
Parameters:
serializer - the object responsible for performing the serialization
Throws:
XPathException - if serialization fails


Copyright (c) 2004-2011 Saxonica Limited. All rights reserved.