com.saxonica.schema

## Class AttributeUse

- java.lang.Object
- - com.saxonica.schema.SchemaStructure
  - - com.saxonica.schema.SimpleComponentReference
    - - com.saxonica.schema.AttributeUse

- All Implemented Interfaces:
    ComponentReference, UserSchemaComponent, Serializable, SourceLocator, SchemaComponent

      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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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

      `COMPONENT_FUNCTION_TYPE, FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AttributeUse(EnterpriseConfiguration config)` Creates a new Attribute Use in the given schema.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `fixup(SchemaCompiler compiler)` Fix up references to other elements in the schema.
    `AttributeDecl` | `getAttributeDeclaration()` Get the corresponding attribute declaration
    `int` | `getCardinality()` Get the value of the "use" attribute, expressed as a Cardinality value of `StaticProperty.EXACTLY_ONE`, `StaticProperty.EMPTY`, or `StaticProperty.ALLOWS_ZERO_OR_ONE`
    `FunctionItem` | `getComponentAsFunction()` Get the schema component in the form of a function item.
    `AttributeGroupDecl` | `getContainingAttributeGroupDecl()` Get the attribute group declaration containing this attribute use, if any
    `String` | `getDefaultValue()` Returns the default value of this attribute use.
    `String` | `getDisplayName()` Returns the name of the attribute defined by this AttributeDecl.
    `AtomicSequence` | `getFixedValue()` Returns the fixed value of this attribute use.
    `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
    `AtomicSequence` | `getUnderlyingFixedValue()` Returns the fixed value of this attribute use, or of the corresponding attribute declaration if the attribute use has no fixed value.
    `String` | `getUse()` Get the value of the 'use' attribute for this attribute declaration or attribute reference.
    `boolean` | `isInheritable()` Ask whether this attribute is inheritable
    `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` | `isRequired()` Returns true if the 'use' attribute is equal to REQUIRED and there is no specified value.
    `void` | `serialize(SchemaModelSerializer serializer)` Serialize the schema component
    `void` | `setContainingAttributeGroupDecl(AttributeGroupDecl containingAttributeGroupDecl)` Set the attribute group declaration containing this attribute use, if any
    `void` | `setDefaultValue(String value)` Sets the default value.
    `void` | `setFixedValue(AtomicSequence value)` Sets the fixed value.
    `void` | `setInheritable(int inherit)` Say whether this attribute is inheritable
    `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(CharSequence value, NamespaceResolver resolver)` Test a value against the fixed value.
    `void` | `tryToResolve(SchemaCompiler compiler)` Attempt to resolve this reference using the components defined in a given schema.
    `boolean` | `validate(SchemaCompiler compiler)` Checks the validity of this Attribute Use

    - ### Methods inherited from class com.saxonica.schema.SimpleComponentReference

      `getFingerprint, getNameCode, getSymbolSpace, getTarget, isResolved, setNameCode, setTarget`

    - ### Methods inherited from class com.saxonica.schema.SchemaStructure

      `elaborate, getColumnNumber, getConfiguration, getFixupStatus, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, lookForCycles, makeXPathExpressionPropertyRecord, setConfiguration, setFixupStatus, setLineNumber, setLocator, setRedefinitionLevel, setSchemaDocumentURI, 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

      `elaborate, lookForCycles`

    - ### Methods inherited from interface net.sf.saxon.type.SchemaComponent

      `getRedefinitionLevel, getValidationStatus`

    - ### Methods inherited from interface com.saxonica.schema.ComponentReference

      `getConfiguration`

    - ### 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(EnterpriseConfiguration config)

      Creates a new Attribute Use in the given schema. For system use only.
      Parameters:
        `config` - the Configuration that contains the new attributeUse

  - ### Method Detail

    - #### tryToResolve

          public void tryToResolve(SchemaCompiler compiler)

      Description copied from class: `SimpleComponentReference`
      Attempt to resolve this reference using the components defined in a given schema. No error results if the reference cannot be resolved.
      Specified by:
        `tryToResolve` in interface `ComponentReference`
      Overrides:
        `tryToResolve` in class `SimpleComponentReference`
      Parameters:
        `compiler` - The compiler being used to compile the referring component. This is assumed to know about the schema containing the candidate target components for the reference. If null, the schema containing the reference is used.

    - #### getAttributeDeclaration

          public AttributeDecl getAttributeDeclaration()
                                                throws UnresolvedReferenceException

      Get the corresponding attribute declaration
      Returns:
        the attribute declaration referenced by this attribute use
      Throws:
        `UnresolvedReferenceException` - if the reference from the AttributeUse to the AttributeDecl has not been resolved

    - #### getContainingAttributeGroupDecl

          public AttributeGroupDecl getContainingAttributeGroupDecl()

      Get the attribute group declaration containing this attribute use, if any
      Returns:
        the containing attribute declaration, or null

    - #### setContainingAttributeGroupDecl

          public void setContainingAttributeGroupDecl(AttributeGroupDecl containingAttributeGroupDecl)

      Set the attribute group declaration containing this attribute use, if any
      Parameters:
        `containingAttributeGroupDecl` - the containing attribute declaration, or null

    - #### getDisplayName

          public 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 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".

    - #### getCardinality

          public int getCardinality()

      Get the value of the "use" attribute, expressed as a Cardinality value of `StaticProperty.EXACTLY_ONE`, `StaticProperty.EMPTY`, or `StaticProperty.ALLOWS_ZERO_OR_ONE`
      Returns:
        the cardinality implied by the "use" attribute

    - #### getDefaultValue

          public 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 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
      Returns:
        the default attribute value if there is one, otherwise null

    - #### getFixedValue

          public AtomicSequence 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 AtomicSequence 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
      Parameters:
        `resolver` - the namespace resolver to be used

    - #### testFixedValue

          public boolean testFixedValue(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
        `resolver` - the namespace resolver to be used if the value is namespace sensitive
      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". Note that in the W3C schema component model, no attribute use ever has the value "prohibited": this should be treated as if the attribute use did not exist.
      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

    - #### 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(String value)

      Sets the default value. For internal use only.
      Parameters:
        `value` - the default value

    - #### setFixedValue

          public void setFixedValue(AtomicSequence value)

      Sets the fixed value. For internal use only.
      Parameters:
        `value` - the fixed value

    - #### setInheritable

          public void setInheritable(int inherit)

      Say whether this attribute is inheritable
      Parameters:
        `inherit` - values are 0 (false), 1 (true), -1 (unspecified, use value from attribute declaration)

    - #### isInheritable

          public boolean isInheritable()

      Ask whether this attribute is inheritable
      Returns:
        true if it is inheritable

    - #### fixup

          public boolean fixup(SchemaCompiler compiler)
                        throws SchemaException

      Fix up references to other elements in the schema.
      Specified by:
        `fixup` in interface `UserSchemaComponent`
      Overrides:
        `fixup` in class `SchemaStructure`
      Parameters:
        `compiler` - the schema compiler, used for error reporting
      Returns:
        true if successful.
      Throws:
        `SchemaException`

    - #### validate

          public boolean validate(SchemaCompiler compiler)
                           throws SchemaException

      Checks the validity of this Attribute Use
      Specified by:
        `validate` in interface `UserSchemaComponent`
      Returns:
        true when this Schema definition is valid, otherwise false.
      Throws:
        `SchemaException` - if the error listener decides an error is fatal

    - #### serialize

          public void serialize(SchemaModelSerializer serializer)
                         throws XPathException

      Serialize the schema component
      Parameters:
        `serializer` - the schema serializer
      Throws:
        `XPathException`

    - #### getComponentAsFunction

          public FunctionItem 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 interface `SchemaComponent`
      Returns:
        the schema component represented as a function from property names to property values.

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