com.saxonica.schema

## Class AttributeDecl

- java.lang.Object
- - com.saxonica.schema.SchemaStructure
  - - com.saxonica.schema.AttributeDecl

- All Implemented Interfaces:
    SerializableSchemaComponent, UserSchemaComponent, Serializable, SourceLocator, SchemaComponent, SchemaDeclaration

      public final class AttributeDecl
      extends SchemaStructure
      implements UserSchemaComponent, SerializableSchemaComponent, SchemaDeclaration

  An XML Schema Attribute Declaration. This includes global attribute declarations, local attribute declarations, and "attribute uses". It corresponds to either (a) an attribute declaration schema component for a global attribute, or (b) an attribute declaration schema component for a local attribute, plus an attribute use referencing that attribute declaration, or (c) an attribute use referencing a global attribute declaration.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### 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
    `AttributeDecl(EnterpriseConfiguration config, boolean global)` Creates a new AttrDecl in the given schema.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `fixup(SchemaCompiler compiler)` Check references from this component to other components
    `FunctionItem` | `getComponentAsFunction()` Get the schema component in the form of a function item.
    `AttributeGroupDecl` | `getContainingAttributeGroup()` Get the containing attribute group.
    `UserComplexType` | `getContainingComplexType()` Get the containing complex type.
    `String` | `getDefaultValue()` Returns the default value of this attribute declaration.
    `String` | `getDisplayName()` Returns the name of the attribute defined by this AttributeDecl.
    `int` | `getFingerprint()` Gets the fingerprint of this attribute name
    `AtomicSequence` | `getFixedValue()` Returns the fixed value of this attribute declaration.
    `String` | `getName()` Get the local name of this Attribute Declaration.
    `int` | `getNameCode()` Get the nameCode of the name of this attribute declaration in the namePool
    `String` | `getNamespace()` Deprecated. since 9.0: use the renamed method getTargetNamespace()
    `SimpleType` | `getSimpleType()` Get the type associated with this Attribute Declaration.
    `String` | `getTargetNamespace()` Get the namespace URI of this element declaration.
    `SimpleType` | `getType()` Get the type of this attribute declaration.
    `boolean` | `isAbstract()` Determine, in the case of an Element Declaration, whether it is nillable.
    `boolean` | `isGlobal()` Determine whether this attribute declaration is global.
    `boolean` | `isInheritable()` Ask whether this attribute is inheritable
    `boolean` | `isNillable()` Determine, in the case of an Element Declaration, whether it is nillable.
    `boolean` | `isSameDeclaration(AttributeDecl other)` Test whether this is the same declaration as another attribute declaration.
    `NodeTest` | `makeSchemaNodeTest()` Create a NodeTest that implements the semantics of schema-element(name) or schema-attribute(name) applied to this element or attribute declaration.
    `void` | `serialize(SchemaModelSerializer serializer)` Serialize the schema component
    `void` | `setContainingAttributeGroup(AttributeGroupDecl type)` Sets the containing attribute group definition.
    `void` | `setContainingComplexType(UserComplexType type)` Sets the containing complex type definition.
    `void` | `setDefaultValue(String value)` Sets the default value.
    `void` | `setFixedValue(AtomicSequence value)` Sets the fixed value.
    `void` | `setInheritable(boolean inherit)` Say whether this attribute is inheritable
    `void` | `setNameCode(int nameCode)` Set the name code for this attribute name.
    `void` | `setNamespaceResolver(NamespaceResolver resolver)` Set the namespace resolver for resolving QName-valued fixed and default values
    `void` | `setSimpleType(SimpleType simpleType)` Sets the SimpleType for this attribute declaration.
    `void` | `setTypeReference(TypeReference type)` Sets the schema type for this attribute declaration.
    `boolean` | `testFixedValue(CharSequence value, NamespaceResolver resolver)` Test a value against the fixed value.
    `boolean` | `validate(SchemaCompiler compiler)` Checks the validity of this Attribute declaration

    - ### 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`

- - ### Constructor Detail

    - #### AttributeDecl

          public AttributeDecl(EnterpriseConfiguration config,
                       boolean global)

      Creates a new AttrDecl in the given schema. For system use only.
      Parameters:
        `config` - the configuration that contains the new attrDecl
        `global` - true if the attribute declaration is global

  - ### Method Detail

    - #### isGlobal

          public boolean isGlobal()

      Determine whether this attribute declaration is global. This represents one aspect of the {scope} property defined in the schema data model.
      Returns:
        true if the attribute declaration is global, false if it is local

    - #### setContainingComplexType

          public void setContainingComplexType(UserComplexType type)

      Sets the containing complex type definition. For internal use only.
      Parameters:
        `type` - the containing complex type

    - #### getContainingComplexType

          public UserComplexType getContainingComplexType()

      Get the containing complex type. This represents one aspect of the {scope} property defined in the schema component model. If the attribute is a local attribute declaration and is defined as part of a complex type (and not as part of a named attribute group), returns the complex type definition. Otherwise, returns null.
      Returns:
        the containing complex type definition if there is one, otherwise null

    - #### setContainingAttributeGroup

          public void setContainingAttributeGroup(AttributeGroupDecl type)

      Sets the containing attribute group definition. For internal use only.
      Parameters:
        `type` - the containing attribute group

    - #### getContainingAttributeGroup

          public AttributeGroupDecl getContainingAttributeGroup()

      Get the containing attribute group. This represents one aspect of the {scope} property defined in the schema component model. If the attribute is a local attribute declaration and is defined as part of an attribute group (and not as part of a complex type), returns the attribute group. Otherwise, returns null.
      Returns:
        the containing attribute group if there is one, otherwise null

    - #### getName

          public String getName()

      Get the local name of this Attribute Declaration. This corresponds to the {name} property as defined in the schema component model.
      Returns:
        the local name of the attribute

    - #### getNamespace

          public String getNamespace()

      Deprecated. since 9.0: use the renamed method getTargetNamespace()
      Get the namespace part of the name of this Attribute Declaration. This corresponds to the {targetNamespace} property as defined in the schema component model.
      Returns:
        the namespace URI part of the name of the attribute

    - #### getTargetNamespace

          public String getTargetNamespace()

      Get the namespace URI of this element declaration. This corresponds to the {targetNamespace} property defined in the schema component model.
      Returns:
        the target namespace URI

    - #### 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.

    - #### setNameCode

          public void setNameCode(int nameCode)

      Set the name code for this attribute name. For internal use only.
      Parameters:
        `nameCode` - the nameCode, as allocated from the name pool.

    - #### setTypeReference

          public void setTypeReference(TypeReference type)

      Sets the schema type for this attribute declaration. For internal use only.
      Parameters:
        `type` - the schema type for this element declaration.

    - #### getFingerprint

          public int getFingerprint()

      Gets the fingerprint of this attribute name
      Specified by:
        `getFingerprint` in interface `SchemaDeclaration`
      Returns:
        the fingerprint of the attribute name in the NamePool

    - #### getNameCode

          public int getNameCode()

      Get the nameCode of the name of this attribute declaration in the namePool
      Returns:
        the nameCode of the attribute name

    - #### getSimpleType

          public SimpleType getSimpleType()
                                   throws UnresolvedReferenceException

      Get the type associated with this Attribute Declaration.
      Returns:
        the type of this attribute.
      Throws:
        `UnresolvedReferenceException` - if the reference from the attribute declaration to its type has not been resolved

    - #### getType

          public SimpleType getType()
                             throws UnresolvedReferenceException

      Get the type of this attribute declaration. This corresponds to the {typeDefinition} property defined in the schema component model
      Specified by:
        `getType` in interface `SchemaDeclaration`
      Returns:
        the type of this attribute. The returned SchemaType will always be an instanceof `SimpleType`
      Throws:
        `UnresolvedReferenceException`

    - #### getDefaultValue

          public String getDefaultValue()

      Returns the default value of this attribute declaration. This corresponds to one aspect of the {valueConstraint} property defined in the schema component model.
      Returns:
        the default value defined by this attribute declaration, or null if no default was specified. The default value is always maintained as a string, in the form supplied in the original schema document.

    - #### getFixedValue

          public AtomicSequence getFixedValue()

      Returns the fixed value of this attribute declaration. This corresponds to one aspect of the {valueConstraint} property defined in the schema component model.
      Returns:
        the fixed value defined by this attribute declaration, 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 document.

    - #### setSimpleType

          public void setSimpleType(SimpleType simpleType)

      Sets the SimpleType for this attribute declaration. For internal use only.
      Parameters:
        `simpleType` - the SimpleType for this attribute declaration

    - #### 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. This will initially be saved as an UntypedAtomicValue; later, when the type is known, it will be converted to the correct type

    - #### setNamespaceResolver

          public void setNamespaceResolver(NamespaceResolver resolver)

      Set the namespace resolver for resolving QName-valued fixed and default values
      Parameters:
        `resolver` - the namespace resolver

    - #### makeSchemaNodeTest

          public NodeTest makeSchemaNodeTest()

      Create a NodeTest that implements the semantics of schema-element(name) or schema-attribute(name) applied to this element or attribute declaration.
      Specified by:
        `makeSchemaNodeTest` in interface `SchemaDeclaration`

    - #### setInheritable

          public void setInheritable(boolean inherit)

      Say whether this attribute is inheritable
      Parameters:
        `inherit` - true if it is inheritable

    - #### isInheritable

          public boolean isInheritable()

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

    - #### fixup

          public boolean fixup(SchemaCompiler compiler)
                        throws SchemaException,
                               UnresolvedReferenceException

      Check references from this component to other components
      Specified by:
        `fixup` in interface `UserSchemaComponent`
      Overrides:
        `fixup` in class `SchemaStructure`
      Parameters:
        `compiler` - used for error reporting
      Returns:
        true if all is well, false if errors found
      Throws:
        `SchemaException`
        `UnresolvedReferenceException`

    - #### validate

          public boolean validate(SchemaCompiler compiler)
                           throws SchemaException

      Checks the validity of this Attribute declaration
      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

    - #### 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` - Namespace resolver for use if the value is namespace-sensitive (QName or NOTATION)
      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

    - #### isSameDeclaration

          public boolean isSameDeclaration(AttributeDecl other)

      Test whether this is the same declaration as another attribute declaration. They are considered to be the same declaration if they came from the same xs:attribute element in the same schema document
      Parameters:
        `other` - the other attribute declaration
      Returns:
        true if the two attribute declarations are considered identical

    - #### isNillable

          public boolean isNillable()

      Determine, in the case of an Element Declaration, whether it is nillable. For an Attribute declaration, always return false;
      Specified by:
        `isNillable` in interface `SchemaDeclaration`

    - #### isAbstract

          public boolean isAbstract()

      Determine, in the case of an Element Declaration, whether it is nillable. For an Attribute declaration, always return false;
      Specified by:
        `isAbstract` in interface `SchemaDeclaration`

    - #### serialize

          public void serialize(SchemaModelSerializer serializer)
                         throws XPathException

      Serialize the schema component
      Specified by:
        `serialize` in interface `SerializableSchemaComponent`
      Parameters:
        `serializer` - the object responsible for performing the serialization
      Throws:
        `XPathException` - if serialization fails

    - #### 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.