Class AttributeUse

  • All Implemented Interfaces:
    ComponentReference, ComponentWithValueConstraint, UserSchemaComponent, javax.xml.transform.SourceLocator, Location, SchemaComponent, org.xml.sax.Locator

    public final class AttributeUse
    extends SimpleComponentReference
    implements ComponentWithValueConstraint, 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.

    • 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,
                                 boolean fatal)
                          throws SchemaException
        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.
        fatal - True if a failure to resolve should be treated as fatal, irrespective of any settings in the SchemaCompiler
        Throws:
        SchemaException - if the reference cannot be resolved or repaired.
      • getAttributeDeclaration

        public AttributeDecl getAttributeDeclaration()
                                              throws MissingComponentException
        Get the corresponding attribute declaration
        Returns:
        the attribute declaration referenced by this attribute use
        Throws:
        MissingComponentException - 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 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".
      • 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. If the attribute is optional but either the attribute use or the corresponding attribute declaration defines a default or fixed value, then it is treated as optional (zero-or-one), because we don't know whether fixed/default attribute values are being reported to the application or not: see bug 3072.
      • getValueConstraint

        public ValueConstraint getValueConstraint()
        Get the value constraint (fixed or default value) that applies to this element declaration, if any
        Specified by:
        getValueConstraint in interface ComponentWithValueConstraint
        Returns:
        the applicable value constraint if there is one, or null otherwise
      • getUnderlyingDefaultValue

        public UnicodeString getUnderlyingDefaultValue()
                                                throws MissingComponentException
        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
        Throws:
        MissingComponentException
      • getUnderlyingFixedValue

        public AtomicSequence getUnderlyingFixedValue()
                                               throws MissingComponentException
        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.
        Throws:
        MissingComponentException
      • 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
      • 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​(Optionality value)
        Sets the 'use' attribute of this attribute declaration. For internal use only.
        Parameters:
        value - one of the following: ("prohibited" | "optional" | "required")
      • 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)
      • 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
        Overrides:
        getComponentAsFunction in class SchemaStructure
        Returns:
        the schema component represented as a function from property names to property values.