Package com.saxonica.ee.schema
Class AttributeUse
- java.lang.Object
-
- com.saxonica.ee.schema.SchemaStructure
-
- com.saxonica.ee.schema.SimpleComponentReference
-
- com.saxonica.ee.schema.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sf.saxon.type.SchemaComponent
SchemaComponent.ValidationStatus
-
-
Field Summary
-
Fields inherited from class com.saxonica.ee.schema.SimpleComponentReference
symbolSpace, target
-
Fields inherited from interface net.sf.saxon.type.SchemaComponent
COMPONENT_FUNCTION_TYPE
-
-
Constructor Summary
Constructors Constructor Description AttributeUse(EnterpriseConfiguration config)
Creates a new Attribute Use in the given schema.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
fixup(SchemaCompiler compiler)
Fix up references to other elements in the schema.AttributeDecl
getAttributeDeclaration()
Get the corresponding attribute declarationint
getCardinality()
Get the value of the "use" attribute, expressed as a Cardinality value ofStaticProperty.EXACTLY_ONE
,StaticProperty.EMPTY
, orStaticProperty.ALLOWS_ZERO_OR_ONE
Function
getComponentAsFunction()
Get the schema component in the form of a function item.AttributeGroupDecl
getContainingAttributeGroupDecl()
Get the attribute group declaration containing this attribute use, if anyjava.lang.String
getDisplayName()
Returns the name of the attribute defined by this AttributeDecl.NamespaceResolver
getNamespaceResolver()
Get the namespace resolver used when the fixed or value constraints include lexical QNamesjava.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 nullAtomicSequence
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.ValueConstraint
getValueConstraint()
Get the value constraint (fixed or default value) that applies to this element declaration, if anyboolean
isInheritable()
Ask whether this attribute is inheritableboolean
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 componentvoid
setContainingAttributeGroupDecl(AttributeGroupDecl containingAttributeGroupDecl)
Set the attribute group declaration containing this attribute use, if anyvoid
setInheritable(int inherit)
Say whether this attribute is inheritablevoid
setNamespaceResolver(NamespaceResolver resolver)
Set the namespace resolver for resolving QName-valued fixed and default valuesvoid
setUse(Optionality value)
Sets the 'use' attribute of this attribute declaration.void
setValueConstraint(ValueConstraint vc)
Set the value constraint (fixed or default value) that applies to this element declarationvoid
tryToResolve(SchemaCompiler compiler, boolean fatal)
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.ee.schema.SimpleComponentReference
getSymbolSpace, getTarget, getTargetComponentName, getTargetFingerprint, isDangling, isResolved, setTarget, setTargetComponentName
-
Methods inherited from class com.saxonica.ee.schema.SchemaStructure
elaborate, getColumnNumber, getConfiguration, getFixupStatus, getGeneratedId, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, hasSameLocation, isValidationNeeded, lookForCycles, makeXPathExpressionPropertyRecord, saveLocation, setConfiguration, setFixupStatus, setGeneratedId, 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.ee.schema.ComponentReference
getConfiguration
-
Methods inherited from interface com.saxonica.ee.schema.ComponentWithValueConstraint
getDefaultValue, getDefaultValueConstraint, getDefaultValueLexicalForm, getFixedValue, getFixedValueConstraint, getFixedValueLexicalForm, getValueConstraintAsFunction
-
Methods inherited from interface net.sf.saxon.s9api.Location
getColumnNumber, getLineNumber, getPublicId, getSystemId, saveLocation
-
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getRedefinitionLevel, getValidationStatus
-
Methods inherited from interface com.saxonica.ee.schema.UserSchemaComponent
elaborate, lookForCycles
-
-
-
-
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 interfaceComponentReference
- Overrides:
tryToResolve
in classSimpleComponentReference
- 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.
-
getNamespaceResolver
public NamespaceResolver getNamespaceResolver()
Description copied from interface:ComponentWithValueConstraint
Get the namespace resolver used when the fixed or value constraints include lexical QNames- Specified by:
getNamespaceResolver
in interfaceComponentWithValueConstraint
- Returns:
- the namespace resolver for lexical QNames
-
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 ofStaticProperty.EXACTLY_ONE
,StaticProperty.EMPTY
, orStaticProperty.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 interfaceComponentWithValueConstraint
- Returns:
- the applicable value constraint if there is one, or null otherwise
-
getUnderlyingDefaultValue
public java.lang.String 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")
-
setValueConstraint
public void setValueConstraint(ValueConstraint vc)
Set the value constraint (fixed or default value) that applies to this element declaration- Specified by:
setValueConstraint
in interfaceComponentWithValueConstraint
- Parameters:
vc
- the value constraint
-
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() throws MissingComponentException
Ask whether this attribute is inheritable- Returns:
- true if it is inheritable
- Throws:
MissingComponentException
-
fixup
public boolean fixup(SchemaCompiler compiler) throws SchemaException
Fix up references to other elements in the schema.- Specified by:
fixup
in interfaceUserSchemaComponent
- Overrides:
fixup
in classSchemaStructure
- 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 interfaceUserSchemaComponent
- 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
- if a failure occurs
-
getComponentAsFunction
public Function 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 interfaceSchemaComponent
- Returns:
- the schema component represented as a function from property names to property values.
-
-