Class BaseConstructor

java.lang.Object
org.yaml.snakeyaml.constructor.BaseConstructor
Direct Known Subclasses:
SafeConstructor

public abstract class BaseConstructor extends Object
Base code
  • Field Details

    • NOT_INSTANTIATED_OBJECT

      protected static final Object NOT_INSTANTIATED_OBJECT
      An instance returned by newInstance methods when instantiation has not been performed.
    • yamlClassConstructors

      protected final Map<NodeId,Construct> yamlClassConstructors
      It maps the node kind to the Construct implementation. When the runtime class is known then the implicit tag is ignored.
    • yamlConstructors

      protected final Map<Tag,Construct> yamlConstructors
      It maps the (explicit or implicit) tag to the Construct implementation. It is used: 1) explicit tag - if present. 2) implicit tag - when the runtime class of the instance is unknown (the node has the Object.class) 3) when nothing else is found the Construct for the key 'null' is chosen (which is ConstructYamlObject)
    • yamlMultiConstructors

      protected final Map<String,Construct> yamlMultiConstructors
      It maps the (explicit or implicit) tag to the Construct implementation. It is used when no exact match found. The key in the Map is checked if it starts the class name
    • composer

      protected Composer composer
      No graph creator
    • rootTag

      protected Tag rootTag
      the tag for the root node
    • typeDefinitions

      protected final Map<Class<? extends Object>,TypeDescription> typeDefinitions
      Mapping from a class to its manager
    • typeTags

      protected final Map<Tag,Class<? extends Object>> typeTags
      register classes for tags
    • loadingConfig

      protected LoaderOptions loadingConfig
      options
  • Constructor Details

    • BaseConstructor

      public BaseConstructor(LoaderOptions loadingConfig)
      Create
      Parameters:
      loadingConfig - - options
  • Method Details

    • setComposer

      public void setComposer(Composer composer)
    • checkData

      public boolean checkData()
      Check if more documents available
      Returns:
      true when there are more YAML documents in the stream
    • getData

      public Object getData() throws NoSuchElementException
      Construct and return the next document
      Returns:
      constructed instance
      Throws:
      NoSuchElementException
    • getSingleData

      public Object getSingleData(Class<?> type)
      Ensure that the stream contains a single document and construct it
      Parameters:
      type - the class of the instance being created
      Returns:
      constructed instance
      Throws:
      ComposerException - in case there are more documents in the stream
    • constructDocument

      protected final Object constructDocument(Node node)
      Construct complete YAML document. Call the second step in case of recursive structures. At the end cleans all the state.
      Parameters:
      node - root Node
      Returns:
      Java instance
    • constructObject

      protected Object constructObject(Node node)
      Construct object from the specified Node. Return existing instance if the node is already constructed.
      Parameters:
      node - Node to be constructed
      Returns:
      Java instance
    • constructObjectNoCheck

      protected Object constructObjectNoCheck(Node node)
      Construct object from the specified Node without the check if it was already created.
      Parameters:
      node - - the source
      Returns:
      constructed instance
    • getConstructor

      protected Construct getConstructor(Node node)
      Get the constructor to construct the Node. For implicit tags if the runtime class is known a dedicated Construct implementation is used. Otherwise, the constructor is chosen by the tag.
      Parameters:
      node - Node to construct an instance from
      Returns:
      Construct implementation for the specified node
    • constructScalar

      protected String constructScalar(ScalarNode node)
      Create string from scalar
      Parameters:
      node - - the source
      Returns:
      the data
    • createDefaultList

      protected List<Object> createDefaultList(int initSize)
    • createDefaultSet

      protected Set<Object> createDefaultSet(int initSize)
    • createDefaultMap

      protected Map<Object,Object> createDefaultMap(int initSize)
    • createArray

      protected Object createArray(Class<?> type, int size)
    • finalizeConstruction

      protected Object finalizeConstruction(Node node, Object data)
    • newInstance

      protected Object newInstance(Node node)
    • newInstance

      protected final Object newInstance(Class<?> ancestor, Node node)
    • newInstance

      protected Object newInstance(Class<?> ancestor, Node node, boolean tryDefault)
      Tries to create a new object for the node.
      Parameters:
      ancestor - expected ancestor of the node.getType()
      node - for which to create a corresponding java object
      tryDefault - should default constructor to be tried when there is no corresponding TypeDescription or TypeDescription.newInstance(node) returns null.
      Returns:
      - a new object created for node.getType() by using corresponding TypeDescription.newInstance or default constructor. - NOT_INSTANTIATED_OBJECT in case no object has been created
    • newSet

      protected Set<Object> newSet(CollectionNode<?> node)
    • newList

      protected List<Object> newList(SequenceNode node)
    • newMap

      protected Map<Object,Object> newMap(MappingNode node)
    • constructSequence

      protected List<? extends Object> constructSequence(SequenceNode node)
      Create List and fill it with data
      Parameters:
      node - - the source
      Returns:
      filled List
    • constructSet

      protected Set<? extends Object> constructSet(SequenceNode node)
      create Set from sequence
      Parameters:
      node - - sequence
      Returns:
      constructed Set
    • constructArray

      protected Object constructArray(SequenceNode node)
      Create array from sequence
      Parameters:
      node - - sequence
      Returns:
      constructed array
    • constructSequenceStep2

      protected void constructSequenceStep2(SequenceNode node, Collection<Object> collection)
      Fill the provided collection with the data from the Node
      Parameters:
      node - - the source
      collection - - data to fill
    • constructArrayStep2

      protected Object constructArrayStep2(SequenceNode node, Object array)
      Fill array from node
      Parameters:
      node - - the source
      array - - the destination
      Returns:
      filled array
    • constructSet

      protected Set<Object> constructSet(MappingNode node)
      Create Set from mapping
      Parameters:
      node - - mapping
      Returns:
      constructed Set
    • constructMapping

      protected Map<Object,Object> constructMapping(MappingNode node)
      Create Map from mapping
      Parameters:
      node - - mapping
      Returns:
      constructed Map
    • constructMapping2ndStep

      protected void constructMapping2ndStep(MappingNode node, Map<Object,Object> mapping)
      Fill provided Map with constructed data
      Parameters:
      node - - source
      mapping - - map to fill
    • postponeMapFilling

      protected void postponeMapFilling(Map<Object,Object> mapping, Object key, Object value)
    • constructSet2ndStep

      protected void constructSet2ndStep(MappingNode node, Set<Object> set)
    • postponeSetFilling

      protected void postponeSetFilling(Set<Object> set, Object key)
    • setPropertyUtils

      public void setPropertyUtils(PropertyUtils propertyUtils)
    • getPropertyUtils

      public final PropertyUtils getPropertyUtils()
    • addTypeDescription

      public TypeDescription addTypeDescription(TypeDescription definition)
      Make YAML aware how to parse a custom Class. If there is no root Class assigned in constructor then the 'root' property of this definition is respected.
      Parameters:
      definition - to be added to the Constructor
      Returns:
      the previous value associated with definition, or null if there was no mapping for definition.
    • isExplicitPropertyUtils

      public final boolean isExplicitPropertyUtils()
    • isAllowDuplicateKeys

      public boolean isAllowDuplicateKeys()
    • setAllowDuplicateKeys

      public void setAllowDuplicateKeys(boolean allowDuplicateKeys)
    • isWrappedToRootException

      public boolean isWrappedToRootException()
    • setWrappedToRootException

      public void setWrappedToRootException(boolean wrappedToRootException)
    • isEnumCaseSensitive

      public boolean isEnumCaseSensitive()
    • setEnumCaseSensitive

      public void setEnumCaseSensitive(boolean enumCaseSensitive)
    • getLoadingConfig

      public LoaderOptions getLoadingConfig()