com.saxonica.schema
Class AttributeUse

java.lang.Object
  extended bycom.saxonica.schema.SchemaStructure
      extended bycom.saxonica.schema.SimpleComponentReference
          extended bycom.saxonica.schema.AttributeUse
All Implemented Interfaces:
ComponentReference, SchemaComponent, java.io.Serializable, javax.xml.transform.SourceLocator, UserSchemaComponent

public final class AttributeUse
extends SimpleComponentReference
implements UserSchemaComponent

An XML Schema Attribute Use: that is, a reference to an attribute declaration from within a complex type or attribute group.

This corresponds to an xs:attribute ref="" element in the XML representation of the schema.

Technically, a local attribute declaration (a non global xs:attribute name="") should be represented by two schema components, an attribute use and an attribute declaration. We don't currently do this, instead the containing attribute group refers to the attribute declaration directly.

See Also:
Serialized Form

Field Summary
static short OPTIONAL
          Value representing use="optional"
static short PROHIBITED
          Value representing use="prohibited"
static short REQUIRED
          Value representing use="required"
 
Fields inherited from class com.saxonica.schema.SimpleComponentReference
nameCode, symbolSpace, target
 
Fields inherited from interface net.sf.saxon.type.SchemaComponent
FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING
 
Constructor Summary
AttributeUse(PreparedSchema schema)
          Creates a new Attribute Use in the given schema.
 
Method Summary
 boolean fixup(PreparedSchema schema)
          Fix up references to other elements in the schema.
 AttributeDecl getAttributeDeclaration()
          Get the corresponding attribute declaration
 java.lang.String getDefaultValue()
          Returns the default value of this attribute use.
 java.lang.String getDisplayName()
          Returns the name of the attribute defined by this AttributeDecl.
 Value getFixedValue()
          Returns the fixed value of this attribute use.
 java.lang.String getUnderlyingDefaultValue()
          Get the default value of this attribute use if there is one; if there is none, get the default value of the corresponding attribute declaration; if the declaration defines no default value, return null
 Value getUnderlyingFixedValue()
          Returns the fixed value of this attribute use, or of the corresponding attribute declaration if the attribute use has no fixed value.
 java.lang.String getUse()
          Get the value of the 'use' attribute for this attribute declaration or attribute reference.
 boolean isOptional()
          Returns true if the use attribute is equal to "optional".
 boolean isProhibited()
          Returns true if the use attribute is equal to "prohibited".
 boolean isReference()
          Returns true if this attribute definition simply references another attribute Definition
 boolean isRequired()
          Returns true if the 'use' attribute is equal to REQUIRED and there is no specified value.
 void setDefaultValue(java.lang.String value)
          Sets the DEFAULT value.
 void setFixedValue(Value value)
          Sets the FIXED value.
 void setNamespaceResolver(NamespaceResolver resolver)
          Set the namespace resolver for resolving QName-valued fixed and default values
 void setUse(short value)
          Sets the 'use' attribute of this attribute declaration.
 boolean testFixedValue(java.lang.CharSequence value, NamespaceResolver resolver)
          Test a value against the fixed value.
 boolean validate(PreparedSchema schema)
          Checks the validity of this Attribute Use
 
Methods inherited from class com.saxonica.schema.SimpleComponentReference
getFingerprint, getNameCode, getSymbolSpace, getTarget, isResolved, setNameCode, setTarget, tryToResolve
 
Methods inherited from class com.saxonica.schema.SchemaStructure
getColumnNumber, getFixupStatus, getLineNumber, getPublicId, getSchema, getSystemId, getValidationStatus, lookForCycles, setFixupStatus, setLineNumber, setLocator, setSchema, setSystemId, setValidationStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.saxonica.schema.UserSchemaComponent
lookForCycles
 
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getValidationStatus
 
Methods inherited from interface com.saxonica.schema.ComponentReference
getSchema
 
Methods inherited from interface javax.xml.transform.SourceLocator
getColumnNumber, getLineNumber, getPublicId, getSystemId
 

Field Detail

OPTIONAL

public static final short OPTIONAL
Value representing use="optional"

See Also:
Constant Field Values

PROHIBITED

public static final short PROHIBITED
Value representing use="prohibited"

See Also:
Constant Field Values

REQUIRED

public static final short REQUIRED
Value representing use="required"

See Also:
Constant Field Values
Constructor Detail

AttributeUse

public AttributeUse(PreparedSchema schema)
Creates a new Attribute Use in the given schema. For system use only.

Parameters:
schema - the schema that contains the new attrDecl
Method Detail

getAttributeDeclaration

public AttributeDecl getAttributeDeclaration()
                                      throws UnresolvedReferenceException
Get the corresponding attribute declaration

Throws:
UnresolvedReferenceException

getDisplayName

public java.lang.String getDisplayName()
Returns the name of the attribute defined by this AttributeDecl. This is used only for diagnostic display purposes

Returns:
the name of the attribute as a lexical QName.

getUse

public java.lang.String getUse()
Get the value of the 'use' attribute for this attribute declaration or attribute reference. If this is a reference the value of the use attribute will *not* be obtained from the referenced attribute declaration as top-level attributes do not take into account the use attribute.

Returns:
the value of the 'use' attribute for this attribute declaration, as a string: "prohibited", "required", or "optional".

getDefaultValue

public java.lang.String getDefaultValue()
Returns the default value of this attribute use.

Returns:
the default value defined by this attribute declaration, or null if no default was specified.

getUnderlyingDefaultValue

public java.lang.String getUnderlyingDefaultValue()
Get the default value of this attribute use if there is one; if there is none, get the default value of the corresponding attribute declaration; if the declaration defines no default value, return null


getFixedValue

public Value getFixedValue()
Returns the fixed value of this attribute use.

Returns:
the fixed value defined by this attribute use, or null if no fixed value was specified. Once the schema has been compiled this will be the correctly-typed value; until then it will be the string value as specified in the source schema.

getUnderlyingFixedValue

public Value getUnderlyingFixedValue()
Returns the fixed value of this attribute use, or of the corresponding attribute declaration if the attribute use has no fixed value.

Returns:
the fixed value defined by this attribute use, if one was specified; failing that, the fixed value defined for the corresponding attribute declaration; failing that, null. Once the schema has been compiled this will be the correctly-typed value; until then it will be the string value as specified in the source schema.

setNamespaceResolver

public void setNamespaceResolver(NamespaceResolver resolver)
Set the namespace resolver for resolving QName-valued fixed and default values


testFixedValue

public boolean testFixedValue(java.lang.CharSequence value,
                              NamespaceResolver resolver)
                       throws ValidationException
Test a value against the fixed value. This tests both against the fixed value for this attribute use, and the fixed value of the corresponding attribute declaration (which must be equivalent if they are both present).

Parameters:
value - the value to be tested
Returns:
true if it matches (or if there is no fixed value), false otherwise
Throws:
ValidationException - if the value is not valid for this type

isOptional

public boolean isOptional()
Returns true if the use attribute is equal to "optional".

Returns:
true if the use attribute is equal to "optional".

isProhibited

public boolean isProhibited()
Returns true if the use attribute is equal to "prohibited".

Returns:
true if the use attribute is equal to "prohibited".

isRequired

public boolean isRequired()
Returns true if the 'use' attribute is equal to REQUIRED and there is no specified value. If a value is specified and the 'use' attribute is "required" then required is will return false, because the attribute value automatically becomes fixed.

Returns:
true if the use attribute is equal to "required" and no default value has been specified, otherwise false

isReference

public boolean isReference()
Returns true if this attribute definition simply references another attribute Definition

Returns:
true if this attribute definition is a reference

setUse

public void setUse(short value)
Sets the 'use' attribute of this attribute declaration. For internal use only.

Parameters:
value - one of the following: ("prohibited" | "optional" | "required")

setDefaultValue

public void setDefaultValue(java.lang.String value)
Sets the DEFAULT value. For internal use only.


setFixedValue

public void setFixedValue(Value value)
Sets the FIXED value. For internal use only.


fixup

public boolean fixup(PreparedSchema schema)
              throws SchemaException
Fix up references to other elements in the schema. This implementation does nothing

Specified by:
fixup in interface UserSchemaComponent
Parameters:
schema - The schema.
Returns:
true (this implementation does nothing).
Throws:
SchemaException

validate

public boolean validate(PreparedSchema schema)
                 throws SchemaException,
                        ValidationException
Checks the validity of this Attribute Use

Specified by:
validate in interface UserSchemaComponent
Parameters:
schema - if this is not null, any errors that are detected should be reported using the error() method of this schema.
Returns:
true when this Schema definition is valid, otherwise false.
Throws:
SchemaException - if the error listener decides an error is fatal
ValidationException