Package org.yaml.snakeyaml.constructor
Class BaseConstructor
- java.lang.Object
-
- org.yaml.snakeyaml.constructor.BaseConstructor
-
- Direct Known Subclasses:
SafeConstructor
public abstract class BaseConstructor extends java.lang.Object
Base code
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BaseConstructor.RecursiveTuple<T,K>
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowDuplicateKeys
protected Composer
composer
No graph creator(package private) java.util.Map<Node,java.lang.Object>
constructedObjects
private boolean
enumCaseSensitive
private boolean
explicitPropertyUtils
protected LoaderOptions
loadingConfig
optionsprivate java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Map<java.lang.Object,java.lang.Object>,BaseConstructor.RecursiveTuple<java.lang.Object,java.lang.Object>>>
maps2fill
protected static java.lang.Object
NOT_INSTANTIATED_OBJECT
An instance returned by newInstance methods when instantiation has not been performed.private PropertyUtils
propertyUtils
private java.util.Set<Node>
recursiveObjects
protected Tag
rootTag
the tag for the root nodeprivate java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Set<java.lang.Object>,java.lang.Object>>
sets2fill
protected java.util.Map<java.lang.Class<? extends java.lang.Object>,TypeDescription>
typeDefinitions
Mapping from a class to its managerprotected java.util.Map<Tag,java.lang.Class<? extends java.lang.Object>>
typeTags
register classes for tagsprivate boolean
wrappedToRootException
protected java.util.Map<NodeId,Construct>
yamlClassConstructors
It maps the node kind to the Construct implementation.protected java.util.Map<Tag,Construct>
yamlConstructors
It maps the (explicit or implicit) tag to the Construct implementation.protected java.util.Map<java.lang.String,Construct>
yamlMultiConstructors
It maps the (explicit or implicit) tag to the Construct implementation.
-
Constructor Summary
Constructors Constructor Description BaseConstructor(LoaderOptions loadingConfig)
Create
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeDescription
addTypeDescription(TypeDescription definition)
Make YAML aware how to parse a custom Class.boolean
checkData()
Check if more documents availableprotected java.lang.Object
constructArray(SequenceNode node)
Create array from sequenceprotected java.lang.Object
constructArrayStep2(SequenceNode node, java.lang.Object array)
Fill array from nodeprotected java.lang.Object
constructDocument(Node node)
Construct complete YAML document.protected java.util.Map<java.lang.Object,java.lang.Object>
constructMapping(MappingNode node)
Create Map from mappingprotected void
constructMapping2ndStep(MappingNode node, java.util.Map<java.lang.Object,java.lang.Object> mapping)
Fill provided Map with constructed dataprotected java.lang.Object
constructObject(Node node)
Construct object from the specified Node.protected java.lang.Object
constructObjectNoCheck(Node node)
Construct object from the specified Node without the check if it was already created.protected java.lang.String
constructScalar(ScalarNode node)
Create string from scalarprotected java.util.List<? extends java.lang.Object>
constructSequence(SequenceNode node)
Create List and fill it with dataprotected void
constructSequenceStep2(SequenceNode node, java.util.Collection<java.lang.Object> collection)
Fill the provided collection with the data from the Nodeprotected java.util.Set<java.lang.Object>
constructSet(MappingNode node)
Create Set from mappingprotected java.util.Set<? extends java.lang.Object>
constructSet(SequenceNode node)
create Set from sequenceprotected void
constructSet2ndStep(MappingNode node, java.util.Set<java.lang.Object> set)
protected java.lang.Object
createArray(java.lang.Class<?> type, int size)
protected java.util.List<java.lang.Object>
createDefaultList(int initSize)
protected java.util.Map<java.lang.Object,java.lang.Object>
createDefaultMap(int initSize)
protected java.util.Set<java.lang.Object>
createDefaultSet(int initSize)
private void
fillRecursive()
Fill the recursive structures and clean the internal collectionsprotected java.lang.Object
finalizeConstruction(Node node, java.lang.Object data)
protected Construct
getConstructor(Node node)
Get the constructor to construct the Node.java.lang.Object
getData()
Construct and return the next documentLoaderOptions
getLoadingConfig()
PropertyUtils
getPropertyUtils()
java.lang.Object
getSingleData(java.lang.Class<?> type)
Ensure that the stream contains a single document and construct itboolean
isAllowDuplicateKeys()
boolean
isEnumCaseSensitive()
boolean
isExplicitPropertyUtils()
boolean
isWrappedToRootException()
protected java.lang.Object
newInstance(java.lang.Class<?> ancestor, Node node)
protected java.lang.Object
newInstance(java.lang.Class<?> ancestor, Node node, boolean tryDefault)
Tries to create a new object for the node.protected java.lang.Object
newInstance(Node node)
protected java.util.List<java.lang.Object>
newList(SequenceNode node)
protected java.util.Map<java.lang.Object,java.lang.Object>
newMap(MappingNode node)
protected java.util.Set<java.lang.Object>
newSet(CollectionNode<?> node)
protected void
postponeMapFilling(java.util.Map<java.lang.Object,java.lang.Object> mapping, java.lang.Object key, java.lang.Object value)
protected void
postponeSetFilling(java.util.Set<java.lang.Object> set, java.lang.Object key)
void
setAllowDuplicateKeys(boolean allowDuplicateKeys)
void
setComposer(Composer composer)
void
setEnumCaseSensitive(boolean enumCaseSensitive)
void
setPropertyUtils(PropertyUtils propertyUtils)
void
setWrappedToRootException(boolean wrappedToRootException)
-
-
-
Field Detail
-
NOT_INSTANTIATED_OBJECT
protected static final java.lang.Object NOT_INSTANTIATED_OBJECT
An instance returned by newInstance methods when instantiation has not been performed.
-
yamlClassConstructors
protected final java.util.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 java.util.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 java.util.Map<java.lang.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
-
constructedObjects
final java.util.Map<Node,java.lang.Object> constructedObjects
-
recursiveObjects
private final java.util.Set<Node> recursiveObjects
-
maps2fill
private final java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Map<java.lang.Object,java.lang.Object>,BaseConstructor.RecursiveTuple<java.lang.Object,java.lang.Object>>> maps2fill
-
sets2fill
private final java.util.ArrayList<BaseConstructor.RecursiveTuple<java.util.Set<java.lang.Object>,java.lang.Object>> sets2fill
-
rootTag
protected Tag rootTag
the tag for the root node
-
propertyUtils
private PropertyUtils propertyUtils
-
explicitPropertyUtils
private boolean explicitPropertyUtils
-
allowDuplicateKeys
private boolean allowDuplicateKeys
-
wrappedToRootException
private boolean wrappedToRootException
-
enumCaseSensitive
private boolean enumCaseSensitive
-
typeDefinitions
protected final java.util.Map<java.lang.Class<? extends java.lang.Object>,TypeDescription> typeDefinitions
Mapping from a class to its manager
-
typeTags
protected final java.util.Map<Tag,java.lang.Class<? extends java.lang.Object>> typeTags
register classes for tags
-
loadingConfig
protected LoaderOptions loadingConfig
options
-
-
Constructor Detail
-
BaseConstructor
public BaseConstructor(LoaderOptions loadingConfig)
Create- Parameters:
loadingConfig
- - options
-
-
Method Detail
-
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 java.lang.Object getData() throws java.util.NoSuchElementException
Construct and return the next document- Returns:
- constructed instance
- Throws:
java.util.NoSuchElementException
-
getSingleData
public java.lang.Object getSingleData(java.lang.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 java.lang.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
-
fillRecursive
private void fillRecursive()
Fill the recursive structures and clean the internal collections
-
constructObject
protected java.lang.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 java.lang.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.
-
constructScalar
protected java.lang.String constructScalar(ScalarNode node)
Create string from scalar- Parameters:
node
- - the source- Returns:
- the data
-
createDefaultList
protected java.util.List<java.lang.Object> createDefaultList(int initSize)
-
createDefaultSet
protected java.util.Set<java.lang.Object> createDefaultSet(int initSize)
-
createDefaultMap
protected java.util.Map<java.lang.Object,java.lang.Object> createDefaultMap(int initSize)
-
createArray
protected java.lang.Object createArray(java.lang.Class<?> type, int size)
-
finalizeConstruction
protected java.lang.Object finalizeConstruction(Node node, java.lang.Object data)
-
newInstance
protected java.lang.Object newInstance(Node node)
-
newInstance
protected final java.lang.Object newInstance(java.lang.Class<?> ancestor, Node node)
-
newInstance
protected java.lang.Object newInstance(java.lang.Class<?> ancestor, Node node, boolean tryDefault)
Tries to create a new object for the node.- Parameters:
ancestor
- expected ancestor of thenode.getType()
node
- for which to create a corresponding java objecttryDefault
- should default constructor to be tried when there is no correspondingTypeDescription
orTypeDescription.newInstance(node)
returnsnull
.- 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 java.util.Set<java.lang.Object> newSet(CollectionNode<?> node)
-
newList
protected java.util.List<java.lang.Object> newList(SequenceNode node)
-
newMap
protected java.util.Map<java.lang.Object,java.lang.Object> newMap(MappingNode node)
-
constructSequence
protected java.util.List<? extends java.lang.Object> constructSequence(SequenceNode node)
Create List and fill it with data- Parameters:
node
- - the source- Returns:
- filled List
-
constructSet
protected java.util.Set<? extends java.lang.Object> constructSet(SequenceNode node)
create Set from sequence- Parameters:
node
- - sequence- Returns:
- constructed Set
-
constructArray
protected java.lang.Object constructArray(SequenceNode node)
Create array from sequence- Parameters:
node
- - sequence- Returns:
- constructed array
-
constructSequenceStep2
protected void constructSequenceStep2(SequenceNode node, java.util.Collection<java.lang.Object> collection)
Fill the provided collection with the data from the Node- Parameters:
node
- - the sourcecollection
- - data to fill
-
constructArrayStep2
protected java.lang.Object constructArrayStep2(SequenceNode node, java.lang.Object array)
Fill array from node- Parameters:
node
- - the sourcearray
- - the destination- Returns:
- filled array
-
constructSet
protected java.util.Set<java.lang.Object> constructSet(MappingNode node)
Create Set from mapping- Parameters:
node
- - mapping- Returns:
- constructed Set
-
constructMapping
protected java.util.Map<java.lang.Object,java.lang.Object> constructMapping(MappingNode node)
Create Map from mapping- Parameters:
node
- - mapping- Returns:
- constructed Map
-
constructMapping2ndStep
protected void constructMapping2ndStep(MappingNode node, java.util.Map<java.lang.Object,java.lang.Object> mapping)
Fill provided Map with constructed data- Parameters:
node
- - sourcemapping
- - map to fill
-
postponeMapFilling
protected void postponeMapFilling(java.util.Map<java.lang.Object,java.lang.Object> mapping, java.lang.Object key, java.lang.Object value)
-
constructSet2ndStep
protected void constructSet2ndStep(MappingNode node, java.util.Set<java.lang.Object> set)
-
postponeSetFilling
protected void postponeSetFilling(java.util.Set<java.lang.Object> set, java.lang.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
, ornull
if there was no mapping fordefinition
.
-
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()
-
-