com.saxonica.schema
Class Facet

java.lang.Object
  extended by com.saxonica.schema.Facet
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AssertionFacet, DigitsFacet, EnumerationFacet, EnumerationFacetSet, ExplicitTimezoneFacet, LengthRangeFacet, PatternFacet, PreprocessFacet, ValueRangeFacet, WhitespaceFacet

public abstract class Facet
extends Object
implements Serializable

Represents an XML Schema Facet. Most facets are represented by subclasses of this class, the only exception is whiteSpace.

See Also:
Serialized Form

Constructor Summary
Facet()
           
 
Method Summary
 void checkFacetRestriction(UserSimpleType type, SimpleType base, SchemaCompiler compiler)
          Check that this facet is legal when used on a type derived by restriction
 String getMessage()
          Get the message to be used when this facet is violated.
abstract  String getName()
          Returns the name of this Facet
abstract  String getValue()
          Returns the lexical representation of the value of this facet
 int getWhitespaceAction()
          Get the whitespace action required by this facet: one of PRESERVE, REPLACE, or COLLAPSE.
 boolean isConstraining()
          Ask whether this is a constraining facet (as distinct from a pre-lexical facet)
static boolean isFacetName(String name, int xsdVersion)
          Test whether a given string is one of the recognized facet names
 boolean isFixed()
          Ask whether the facet is defined in the schema with fixed="true"
 boolean isNewlyIntroduced(SimpleType base)
          Test whether this facet is newly introduced on this type, that is, whether it is absent from the base type
static Facet makeFacet(String name, String value, EnterpriseConfiguration config, NamespaceResolver resolver, SchemaCompiler compiler)
          Factory method: creates a new Facet with the given name
 void serializeFacet(SchemaModelSerializer serializer)
          Serialize this facet when externalizing the schema component model
 void setFixed(boolean fixed)
          Say whether the facet is defined as fixed
 void setMessage(String message)
          Set the message to be used when this facet is violated.
abstract  boolean testAtomicValue(AtomicValue value)
          Test whether an atomic value conforms to this facet
 boolean testLength(int count)
          Test whether the length of a list conforms to this facet.
 boolean testListValue(Value value)
          Test whether a list value conforms to this facet.
 long toLong()
          Returns the numeric value of this facet, for facets where this is appropriate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Facet

public Facet()
Method Detail

setFixed

public void setFixed(boolean fixed)
Say whether the facet is defined as fixed

Parameters:
fixed - true if the facet is fixed

isFixed

public boolean isFixed()
Ask whether the facet is defined in the schema with fixed="true"

Returns:
true if fixed

isConstraining

public boolean isConstraining()
Ask whether this is a constraining facet (as distinct from a pre-lexical facet)

Returns:
true if this is a constraining facet

setMessage

public void setMessage(String message)
Set the message to be used when this facet is violated. If no message is supplied, a generic message is constructed, for example "the value does not match the pattern XYZ".

Parameters:
message - the message to be used

getMessage

public String getMessage()
Get the message to be used when this facet is violated.

Returns:
the message, if one has been set, or null otherwise

getName

public abstract String getName()
Returns the name of this Facet

Returns:
the name of this Facet

getValue

public abstract String getValue()
Returns the lexical representation of the value of this facet

Returns:
the value of this facet, as a string

toLong

public long toLong()
            throws NumberFormatException
Returns the numeric value of this facet, for facets where this is appropriate

Returns:
a long representation of the value of this facet
Throws:
NumberFormatException - if the value is not numeric

checkFacetRestriction

public void checkFacetRestriction(UserSimpleType type,
                                  SimpleType base,
                                  SchemaCompiler compiler)
                           throws SchemaException,
                                  ValidationException
Check that this facet is legal when used on a type derived by restriction

Parameters:
type - the type on which the facet is defined
base - the type from which the restricted type is derived
compiler - the schema compiler
Throws:
SchemaException - if the facet is not legal
ValidationException - if a value is found that does not conform to the facet

isNewlyIntroduced

public boolean isNewlyIntroduced(SimpleType base)
Test whether this facet is newly introduced on this type, that is, whether it is absent from the base type

Parameters:
base - the base type
Returns:
true if the facet is present on this type and not on the base type

testAtomicValue

public abstract boolean testAtomicValue(AtomicValue value)
Test whether an atomic value conforms to this facet

Parameters:
value - the value to be tested
Returns:
true if the value conforms; false if it doesn't conform, or if the test fails

testListValue

public boolean testListValue(Value value)
Test whether a list value conforms to this facet. This is used only for the enumeration and assertion facets.

Parameters:
value - the value to be tested
Returns:
true if the value conforms; false if it doesn't conform, or if the test fails

testLength

public boolean testLength(int count)
Test whether the length of a list conforms to this facet. Always true except for length facets

Parameters:
count - the actual length of the list
Returns:
true if the facet allows a list of this length, otherwise false

getWhitespaceAction

public int getWhitespaceAction()
Get the whitespace action required by this facet: one of PRESERVE, REPLACE, or COLLAPSE. Returns a dummy value of PRESERVE for facets other than whitespace facets.

Returns:
the whitespace action, by default PRESERVE

serializeFacet

public void serializeFacet(SchemaModelSerializer serializer)
                    throws XPathException
Serialize this facet when externalizing the schema component model

Parameters:
serializer - receives the content for serialization
Throws:
XPathException - if an error occurs writing the value to the output

isFacetName

public static boolean isFacetName(String name,
                                  int xsdVersion)
Test whether a given string is one of the recognized facet names

Parameters:
name - a candidate facet name, for example "totalDigits"
xsdVersion - either XSD10 or XSD11
Returns:
true if the name is recognized as a facet name in the selected version of the XSD specification

makeFacet

public static Facet makeFacet(String name,
                              String value,
                              EnterpriseConfiguration config,
                              NamespaceResolver resolver,
                              SchemaCompiler compiler)
                       throws SchemaException
Factory method: creates a new Facet with the given name

Parameters:
name - the name of the Facet
value - the value of the Facet
config - the Saxon configuration
resolver - a namespace resolver used for resolving prefixes in namespace-sensitive enumeration values
Returns:
the constructed facet
Throws:
SchemaException - if an error is found


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