Package com.saxonica.ee.schema

## Class KeyRef

- java.lang.Object
- - com.saxonica.ee.schema.SchemaStructure
  - - com.saxonica.ee.schema.IdentityConstraint
    - - com.saxonica.ee.schema.KeyRef

- All Implemented Interfaces:
    `ComponentReference`, `SerializableSchemaComponent`, `UserSchemaComponent`, `javax.xml.transform.SourceLocator`, `Location`, `SchemaComponent`, `org.xml.sax.Locator`

      public class KeyRef
      extends IdentityConstraint
      implements ComponentReference

  This class represents an xs:keyRef identity constraint in a schema

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface net.sf.saxon.type.SchemaComponent

      `SchemaComponent.ValidationStatus`

  - ### Field Summary

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

      `COMPONENT_FUNCTION_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `KeyRef()` | Create a KeyRef object representing an xs:keyref constraints
    `KeyRef​(EnterpriseConfiguration config, StructuredQName refer)` | Create a new KeyRef Identity-Constraint.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `fixup​(SchemaCompiler compiler)` | Check references from this component to other components
    `java.lang.String` | `getConstraintCategory()` | The type of constraint: one of "key", "unique", or "keyref"
    `int` | `getSymbolSpace()` | Get the symbol space of the target of this reference
    `SchemaComponent` | `getTarget()` | Get the schema component identified by this reference.
    `StructuredQName` | `getTargetComponentName()` | Get the name of the target of this reference
    `boolean` | `isDangling()` | Ask whether this is known to be a dangling reference
    `boolean` | `isResolved()` | Determine whether this reference has been resolved
    `void` | `setTargetComponentName​(StructuredQName target)` | Sets the name of the key being referenced.
    `void` | `setTargetKey​(IdentityConstraint key)` | Set the target key or unique constraint
    `void` | `tryToResolve​(SchemaCompiler compiler, boolean fatal)` | Try to resolve the reference if possible, relative to components present in a given schema.
    `boolean` | `validate​(SchemaCompiler compiler)` | Checks the validity of this Schema defintion.

    - ### Methods inherited from class com.saxonica.ee.schema.IdentityConstraint

      `addField, elaborate, getComponentAsFunction, getConstraintName, getFields, getName, getSelector, getTargetNamespace, isOrdered, isSameDeclaration, serialize, setConstraintName, setOrdered, setSelector, typeCheck`

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

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

      `lookForCycles`

- - ### Constructor Detail

    - #### KeyRef

          public KeyRef()

      Create a KeyRef object representing an xs:keyref constraints

    - #### KeyRef

          public KeyRef​(EnterpriseConfiguration config,
                        StructuredQName refer)

      Create a new KeyRef Identity-Constraint.
      Parameters:
        `config` - the configuration
        `refer` - the name of the referenced key.

  - ### Method Detail

    - #### getConstraintCategory

          public java.lang.String getConstraintCategory()

      Description copied from class: `IdentityConstraint`
      The type of constraint: one of "key", "unique", or "keyref"
      Specified by:
        `getConstraintCategory` in class `IdentityConstraint`
      Returns:
        one of "key", "unique", or "keyref" (note the spelling)

    - #### getTargetComponentName

          public StructuredQName getTargetComponentName()

      Get the name of the target of this reference
      Specified by:
        `getTargetComponentName` in interface `ComponentReference`
      Returns:
        the component name

    - #### setTargetComponentName

          public void setTargetComponentName​(StructuredQName target)

      Sets the name of the key being referenced.
      Parameters:
        `target` - the fingerprint of the name of the key to reference.

    - #### setTargetKey

          public void setTargetKey​(IdentityConstraint key)

      Set the target key or unique constraint
      Parameters:
        `key` - the target key definition or unique constraint

    - #### tryToResolve

          public void tryToResolve​(SchemaCompiler compiler,
                                   boolean fatal)

      Try to resolve the reference if possible, relative to components present in a given schema. No error occurs if the reference cannot yet be resolved.
      Specified by:
        `tryToResolve` in interface `ComponentReference`
      Parameters:
        `compiler` - The schema containing the candidate target components for the reference. If null, the schema containing the reference is used.
        `fatal` -

    - #### isResolved

          public boolean isResolved()

      Determine whether this reference has been resolved
      Specified by:
        `isResolved` in interface `ComponentReference`
      Returns:
        true if the reference has been resolved to a schema component

    - #### isDangling

          public boolean isDangling()

      Ask whether this is known to be a dangling reference
      Specified by:
        `isDangling` in interface `ComponentReference`
      Returns:
        true if the target of this component reference is known to be absent, and if a warning has been issued to this effect

    - #### getTarget

          public SchemaComponent getTarget()
                                    throws MissingComponentException

      Get the schema component identified by this reference.
      Specified by:
        `getTarget` in interface `ComponentReference`
      Returns:
        the schema component if the reference has been resolved.
      Throws:
        `MissingComponentException` - if the reference has not been resolved. Note that this is an unchecked exception.

    - #### getSymbolSpace

          public int getSymbolSpace()

      Get the symbol space of the target of this reference
      Specified by:
        `getSymbolSpace` in interface `ComponentReference`
      Returns:
        an integer code identifying the symbol space

    - #### fixup

          public boolean fixup​(SchemaCompiler compiler)
                        throws SchemaException

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

    - #### validate

          public boolean validate​(SchemaCompiler compiler)
                           throws SchemaException

      Checks the validity of this Schema defintion.
      Specified by:
        `validate` in interface `UserSchemaComponent`
      Overrides:
        `validate` in class `IdentityConstraint`
      Returns:
        true when this Schema definition is valid, otherwise false.
      Throws:
        `SchemaException` - when this Schema definition is invalid.