Class DocumentType

java.lang.Object
com.yahoo.vespa.objects.Selectable
com.yahoo.vespa.objects.Identifiable
All Implemented Interfaces:
Cloneable, Comparable<DataType>

public class DocumentType extends StructuredDataType

A document definition is a list of fields. Documents may inherit other documents, implicitly acquiring their fields as it's own. If a document is not set to inherit any document, it will always inherit the document "document.0".

Author:
Thomas Gundersen, bratseth
  • Field Details

  • Constructor Details

    • DocumentType

      public DocumentType(String name)
      Creates a new document type and registers it with the document type manager. This will be created as version 0 of this document type. Implicitly registers this with the document type manager. The document type id will be generated as a hash from the document type name.
      Parameters:
      name - The name of the new document type
    • DocumentType

      public DocumentType(String name, StructDataType contentStructType)
      Creates a new document type and registers it with the document type manager. Implicitly registers this with the document type manager. The document type id will be generated as a hash from the document type name.
      Parameters:
      name - The name of the new document type
      contentStructType - The type of the content struct
    • DocumentType

      public DocumentType(String name, StructDataType contentStructType, Set<String> importedFieldNames)
    • DocumentType

      public DocumentType(String name, Set<String> importedFieldNames)
  • Method Details

    • clone

      public DocumentType clone()
      Overrides:
      clone in class DataType
    • createFieldValue

      public Document createFieldValue()
      Description copied from class: DataType
      Creates a new, empty FieldValue of this type
      Specified by:
      createFieldValue in class StructuredDataType
    • getValueClass

      public Class getValueClass()
      Specified by:
      getValueClass in class DataType
    • isValueCompatible

      public boolean isValueCompatible(FieldValue value)
      Specified by:
      isValueCompatible in class DataType
    • contentStruct

      public StructDataType contentStruct()
      Provides the Struct describing the fields in the document.
      Returns:
      a struct describing the document fields.
    • getStructType

      public StructDataType getStructType(String name)
      Get a struct declared in this document (or any inherited document). Returns null if no such struct was found. If multiple possible structs are found in inherited documents, throws exception.
      Parameters:
      name - the name of the struct
      Returns:
      reference to a struct data type, or null
    • getDeclaredStructType

      public StructDataType getDeclaredStructType(String name)
      Get a struct declared in this document only. Returns null if no such struct was found.
      Parameters:
      name - the name of the struct
      Returns:
      reference to a struct data type, or null
    • register

      protected void register(DocumentTypeManager manager, List<DataType> seenTypes)
      Overrides:
      register in class StructuredDataType
    • isA

      public boolean isA(String docTypeName)
      Check if this document type has the given name, or inherits from a type with that name.
    • addField

      public void addField(Field field)
      Adds an field that can be used with this document type.
      Parameters:
      field - the field to add
    • addFieldSets

      public void addFieldSets(Map<String,Collection<String>> fieldSets)
    • addField

      public Field addField(String name, DataType type)
      Adds a new field to this document type and returns the new field object
      Parameters:
      name - The name of the field to add
      type - The datatype of the field to add
      Returns:
      The field created TODO Fix searchdefinition so that exception can be thrown if filed is already registerd.
    • inherit

      public void inherit(DocumentType type)
      Adds a document to the inherited document types of this. If this type is already directly inherited, nothing is done
      Parameters:
      type - An already DocumentType object.
    • getInheritedTypes

      public Collection<DocumentType> getInheritedTypes()
      Returns the DocumentNames which are directly inherited by this as a read-only collection. If this document type does not explicitly inherit anything, the list will contain the root type 'Document'
      Returns:
      a read-only list iterator containing the name Strings of the directly inherited document types of this
    • inheritedIterator

      public ListIterator<DataTypeName> inheritedIterator()
    • inherits

      public boolean inherits(DocumentType superType)
      Return whether this document type inherits the given document type.
      Parameters:
      superType - the documenttype to check if it inherits
      Returns:
      true if it inherits the superType, false if not
    • getField

      public Field getField(String name)
      Gets the field matching a given name.
      Specified by:
      getField in class StructuredDataType
      Parameters:
      name - the name of a field
      Returns:
      returns the matching field, or null if not found
    • getField

      public Field getField(int id)
      Description copied from class: StructuredDataType
      Gets the field with the specified id.
      Specified by:
      getField in class StructuredDataType
      Parameters:
      id - the id of the field to return.
      Returns:
      the matching field, or null if not found.
    • hasField

      public boolean hasField(String name)
      Returns whether this type defines the given field name
      Parameters:
      name - The name of the field to check if it has
      Returns:
      True if there is a field with the given name.
    • getFieldCount

      public int getFieldCount()
    • getImportedFieldNames

      public Set<String> getImportedFieldNames()
    • hasImportedField

      public boolean hasImportedField(String fieldName)
    • removeField

      public Field removeField(String name)
      Removes an field from the DocumentType.
      Parameters:
      name - The name of the field.
      Returns:
      The field that was removed or null if it did not exist.
    • getFields

      public Collection<Field> getFields()
      All fields defined in the document and its parents This is for internal use Use fieldSet() instead or fieldSetAll() if you really want all fields
      Specified by:
      getFields in class StructuredDataType
      Returns:
      All fields defined in the document and its parents
    • fieldSet

      public Set<Field> fieldSet()

      Returns an ordered set snapshot of all fields of this documenttype, except the fields of Document. Only the overridden version will be returned for overridden fields.

      The fields of a document type has a well-defined order which is exhibited in this set: - Fields come in the order defined in the document type definition. - The fields defined in inherited types come before those in the document type itself. - When a field in an inherited type is overridden, the value is overridden, but not the ordering.

      Returns:
      an unmodifiable snapshot of the fields in this type
    • fieldSetAll

      public Set<Field> fieldSetAll()
      This is identical to fieldSet() fieldSet}, but in addition extra hidden synthetic fields are returned.
      Returns:
      an unmodifiable snapshot of the all fields in this type
    • fieldSet

      public Set<Field> fieldSet(String name)
    • fieldIteratorThisTypeOnly

      public Iterator<Field> fieldIteratorThisTypeOnly()
      Returns an iterator over all fields in this documenttype
      Returns:
      An iterator for iterating the fields in this documenttype.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class StructuredDataType
    • onSerialize

      public void onSerialize(com.yahoo.vespa.objects.Serializer target)
      Overrides:
      onSerialize in class com.yahoo.vespa.objects.Identifiable
    • visitMembers

      public void visitMembers(com.yahoo.vespa.objects.ObjectVisitor visitor)
      Overrides:
      visitMembers in class DataType