Interface InstanceBuilder

All Known Implementing Classes:
DefaultInstanceBuilder

public interface InstanceBuilder
Builds instances from parsed JSON-LD.
  • Method Details

    • openObject

      void openObject(String id, String property, List<String> types)
      Creates new instance to fill filled mapped by the specified property.

      The instance type is determined from the declared type of the mapped field, which is taken from the currently open object, and from the specified types. Therefore, another object has to be already open before this method can be called.

      The new instance also becomes the currently open object.

      This method should also verify cardinality, i.e. multiple objects cannot be set for the same property, if the field it maps to is singular.

      This method assumes that the property is mapped, i.e. that isPropertyMapped(String) returned true.

      Parameters:
      id - Identifier of the object being open
      property - Property identifier (IRI)
      types - Types of the object being open
      Throws:
      IllegalStateException - If there is no OWLClass instance open
    • openObject

      <T> void openObject(String id, Class<T> cls)
      Creates new instance of the specified class.

      If there is a collection currently open, it adds the new instance to it.

      The new instance also becomes the currently open object.

      This method is intended for creating top level objects or adding objects to collections. Use openObject(String, String, List) for opening objects as values of attributes.

      Type Parameters:
      T - The type of the object to open
      Parameters:
      id - Identifier of the object being open
      cls - Java type of the object being open
      See Also:
    • closeObject

      void closeObject()
      Closes the most recently open object.
    • openCollection

      void openCollection(String property)
      Creates new instance of appropriate collection and sets it as value of the specified property of the currently open object.

      The collection type is determined from the declared type of the mapped field, which is taken from the currently open object. Therefore, another object has to be already open before this method can be called.

      The new collection also becomes the currently open object.

      This method should also verify cardinality, i.e. a collection cannot be set as value of a field mapped by property, if the field is singular.

      This method assumes that the property is mapped, i.e. that isPropertyMapped(String) returned true.

      Parameters:
      property - Property identifier (IRI)
      Throws:
      IllegalStateException - If there is no OWLClass instance open
    • openCollection

      void openCollection(CollectionType collectionType)
      Creates new instance of the specified collection type.

      If there is a collection currently open, it adds the new collection as its new item.

      The new collection also becomes the currently open object.

      This method is intended for creating top level collections or nesting collections. Use openCollection(String) for opening collections as values of attributes.

      Parameters:
      collectionType - Type of the JSON collection to instantiate in Java
      See Also:
    • closeCollection

      void closeCollection()
      Closes the most recently open collection.
    • addValue

      void addValue(String property, Object value)
      Adds the specified value of the specified property to the currently open object.

      This method is intended for non-composite JSON values like String, Number Boolean and null. It can also handle IRIs of objects already parsed by the deserializer, which are serialized as Strings in JSON-LD. In this case, the field is filled with the deserialized object.

      This method should also verify cardinality and correct typing, e.g. multiple values cannot be set for the same property, if the field it maps to is singular.

      This method assumes that the property is mapped, i.e. that isPropertyMapped(String) returned true.

      Parameters:
      property - Property identifier (IRI)
      value - The value to set
      Throws:
      IllegalStateException - If there is no OWLClass instance open
    • addValue

      void addValue(Object value)
      Adds the specified value to the currently open collection.

      This method is intended for non-composite JSON values like String, Number Boolean and null. It can also handle IRIs of objects already parsed by the deserializer, which are serialized as Strings in JSON-LD. In this case, the deserialized object is added to the collection.

      Parameters:
      value - The value to add
    • addNodeReference

      void addNodeReference(String property, String nodeId)
      Adds a reference to a node to the currently open object.

      This methods is invoked in case the deserializer encounters an object with a single attribute - @id. This assumes that the node either references an already encountered object (known instance) or that the node is a value of a plain identifier-valued object property.

      This method should also verify cardinality and correct typing, e.g. multiple values cannot be set for the same property, if the field it maps to is singular.

      It is assumed that the property is mapped, i.e. that isPropertyMapped(String) returned true.

      Parameters:
      property - Property identifier (IRI)
      nodeId - Identifier (IRI) of the node, i.e. value of the @id attribute
    • addNodeReference

      void addNodeReference(String nodeId)
      Adds the specified value to the currently open collection.

      This methods is invoked in case the deserializer encounters an object with a single attribute - @id. This assumes that the node either references an already encountered object (known instance) or that the node is a value of a plain identifier-valued object property.

      Parameters:
      nodeId - Identifier (IRI) of the node, i.e. value of the @id attribute
    • getCurrentRoot

      Object getCurrentRoot()
      Returns current root of the deserialized object graph.
      Returns:
      Object graph root, it can be a OWLClass instance, or a Collection
    • getCurrentCollectionElementType

      Class<?> getCurrentCollectionElementType()
      Returns the declared type of elements of the current instance, if it is a collection.
      Returns:
      Collection element type
      Throws:
      JsonLdDeserializationException - If the current instance is not a collection
    • isCurrentCollectionProperties

      boolean isCurrentCollectionProperties()
      Checks whether the current collection context represents a Properties attribute.
      Returns:
      true if the current context is a collection representing a Properties field
    • getCurrentContextType

      Class<?> getCurrentContextType()
      Gets the Java type of the current object context.
      Returns:
      Java class of the instance currently being built
    • isPlural

      boolean isPlural(String property)
      Checks whether the specified property is mapped to a plural field.

      This method assumes that the property is mapped, i.e. that isPropertyMapped(String) returned true.

      Note that Types and Properties fields are always treated as plural.

      Parameters:
      property - Property identifier (IRI)
      Returns:
      Whether mapped field is collection-valued or not
    • isPropertyMapped

      boolean isPropertyMapped(String property)
      Checks whether the specified property is mapped by the class representing the current instance context.

      Returns true also for the JsonLd.TYPE property, even though the target instance may not contain a Types field. The builder has to be able to handle types no matter whether a types field is present or not.

      Parameters:
      property - Property identifier (IRI)
      Returns:
      Whether the property is mapped in the current instance context
    • isPropertyDeserializable

      boolean isPropertyDeserializable(String property)
      Checks whether the specified property can be deserialized.

      A property cannot be deserialized if it is not mapped or if the mapped field's access is read-only.

      Parameters:
      property - Property identifier (IRI)
      Returns:
      Whether property can be deserialized
      See Also:
    • getTargetType

      Class<?> getTargetType(String property)
      Gets the target type of the specified property.

      That is, it retrieves the type of the field to which the specified property is mapped. If the target field is a collection, the element type is returned (equivalent to getCurrentCollectionElementType()).

      This method assumes that the property is mapped, i.e. that isPropertyMapped(String) returned true.

      Parameters:
      property - Property whose target type to resolve
      Returns:
      Target type wrapped in an optional