Class AbstractDescriptor

java.lang.Object
cz.cvut.kbss.jopa.model.descriptors.AbstractDescriptor
All Implemented Interfaces:
Descriptor
Direct Known Subclasses:
EntityDescriptor, FieldDescriptor

public abstract class AbstractDescriptor extends Object implements Descriptor
Defines base descriptor, which is used to specify context information for entities and their fields.

The descriptor hierarchy is a classical Composite pattern.

  • Field Details

    • contexts

      protected final Set<URI> contexts
    • assertionsInSubjectContext

      protected final boolean assertionsInSubjectContext
  • Constructor Details

    • AbstractDescriptor

      protected AbstractDescriptor()
    • AbstractDescriptor

      protected AbstractDescriptor(boolean assertionsInSubjectContext)
    • AbstractDescriptor

      protected AbstractDescriptor(URI context)
    • AbstractDescriptor

      protected AbstractDescriptor(URI context, boolean assertionsInSubjectContext)
    • AbstractDescriptor

      protected AbstractDescriptor(Set<URI> contexts, boolean assertionsInSubjectContext, String language, boolean hasLanguage, boolean includeInferred)
  • Method Details

    • getContexts

      public Set<URI> getContexts()
      Description copied from interface: Descriptor
      Gets contexts for this descriptor.

      An empty result indicates the default context.

      Note that for saving, there must be at most one context.

      Specified by:
      getContexts in interface Descriptor
      Returns:
      Context URIs
    • getSingleContext

      public Optional<URI> getSingleContext()
      Description copied from interface: Descriptor
      Gets the only context specified by this descriptor.

      This method will check whether there is at most one context specified in this descriptor. If there are none (meaning the default should be used), an empty Optional is returned. If there are more than one, an AmbiguousContextException is thrown.

      This method is intended to be used by data modification operations, which require at most one target context to be specified.

      Specified by:
      getSingleContext in interface Descriptor
      Returns:
      Single entity context wrapped in Optional, empty, if there is none
    • addContext

      public Descriptor addContext(URI context)
      Description copied from interface: Descriptor
      Adds the specified context to this descriptor.

      Note that adding the default context removes all the previously added contexts, as they become obsolete.

      Specified by:
      addContext in interface Descriptor
      Parameters:
      context - Context to add, null indicates default context
      Returns:
      This instance
    • getSingleAttributeContext

      public Optional<URI> getSingleAttributeContext(FieldSpecification<?,?> attribute)
      Description copied from interface: Descriptor
      Gets the only context specified by this descriptor for the specified attribute.

      If no context is specified (meaning the default context should be used), an empty Optional is returned.

      If more than one context are available for the specified attribute, an AmbiguousContextException is thrown.

      Specified by:
      getSingleAttributeContext in interface Descriptor
      Parameters:
      attribute - Entity attribute, as specified by the application model
      Returns:
      Context identifier
      See Also:
    • getLanguage

      public String getLanguage()
      Description copied from interface: Descriptor
      Gets the language set for this descriptor.
      Specified by:
      getLanguage in interface Descriptor
      Returns:
      Language tag (e.g. en, cs), can be null, meaning any language is supported or the language tag has not been set (see Descriptor.hasLanguage())
    • hasLanguage

      public boolean hasLanguage()
      Description copied from interface: Descriptor
      Gets information about whether language tag has been set on this descriptor.

      The language tag can be explicitly set to null, meaning any language is supported. This can be used to override PU-level language setting.

      Specified by:
      hasLanguage in interface Descriptor
      Returns:
      true if a language tag has been set on this descriptor, false otherwise
    • setLanguage

      public Descriptor setLanguage(String languageTag)
      Description copied from interface: Descriptor
      Sets language tag of this descriptor.

      Applies to any possible sub-descriptors as well.

      Specified by:
      setLanguage in interface Descriptor
      Parameters:
      languageTag - The language tag to use, possibly null, meaning no language preference should be used
      Returns:
      This instance
      See Also:
    • anyLanguage

      public Descriptor anyLanguage()
      Description copied from interface: Descriptor
      Configures this descriptor to support any language tag (including no language tags).

      This is useful for overriding previously set language tag expectations (either on PU level or parent descriptor level).

      This does the same as calling Descriptor.setLanguage(String) with null argument, but is more explicit.

      Specified by:
      anyLanguage in interface Descriptor
      Returns:
      This instance
    • areAssertionsInSubjectContext

      public boolean areAssertionsInSubjectContext()
      Description copied from interface: Descriptor
      Whether property assertion should be stored in the subject's context (default), or whether they should be stored together with the assertion value.

      This applies to object references, literal values are always stored in the specified context.

      Specified by:
      areAssertionsInSubjectContext in interface Descriptor
      Returns:
      Whether property assertion is stored in the subject context
    • includeInferred

      public boolean includeInferred()
      Description copied from interface: Descriptor
      Whether to include inferred statements when loading data corresponding to this descriptor.

      Note that this setting is taken into account only for attributes that are declared as possibly containing inferred values (using the Inferred annotation). For explicit attributes, this setting is ignored.

      The setting in this descriptor is applied recursively to all the descriptors it may be composed of, unless a different value is specified explicitly for them.

      Specified by:
      includeInferred in interface Descriptor
      Returns:
      Whether to include inferred values for inferred attributes
      See Also:
    • disableInference

      public Descriptor disableInference()
      Description copied from interface: Descriptor
      Instructs this descriptor to specify that only asserted statements should be loaded for otherwise inferred attributes.
      Specified by:
      disableInference in interface Descriptor
      Returns:
      This descriptor
      See Also:
    • enableInference

      public Descriptor enableInference()
      Description copied from interface: Descriptor
      Instructs this descriptor to specify that both inferred and asserted statements should be loaded for otherwise inferred attributes.

      This is the default setting.

      Specified by:
      enableInference in interface Descriptor
      Returns:
      This descriptor
      See Also:
    • setIncludeInferred

      protected void setIncludeInferred(boolean includeInferred)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • equalsImpl

      protected boolean equalsImpl(Object o)
    • equals

      protected boolean equals(Object other, Map<AbstractDescriptor.VisitedPair,Boolean> visited)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • hashCodeImpl

      protected int hashCodeImpl()
    • hashCode

      protected int hashCode(Map<Object,Boolean> visited)
    • toString

      public String toString()
      Overrides:
      toString in class Object