Package org.yaml.snakeyaml.constructor
Class BaseConstructor
- java.lang.Object
-
- org.yaml.snakeyaml.constructor.BaseConstructor
-
- Direct Known Subclasses:
SafeConstructor
public abstract class BaseConstructor extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected Composercomposerprotected TagrootTagprotected Map<Class<? extends Object>,TypeDescription>typeDefinitionsprotected Map<Tag,Class<? extends Object>>typeTagsprotected Map<NodeId,Construct>yamlClassConstructorsIt maps the node kind to the the Construct implementation.protected Map<Tag,Construct>yamlConstructorsIt maps the (explicit or implicit) tag to the Construct implementation.protected Map<String,Construct>yamlMultiConstructorsIt maps the (explicit or implicit) tag to the Construct implementation.
-
Constructor Summary
Constructors Constructor Description BaseConstructor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeDescriptionaddTypeDescription(TypeDescription definition)Make YAML aware how to parse a custom Class.booleancheckData()Check if more documents availableprotected ObjectconstructArray(SequenceNode node)protected ObjectconstructArrayStep2(SequenceNode node, Object array)protected ObjectconstructDocument(Node node)Construct complete YAML document.protected Map<Object,Object>constructMapping(MappingNode node)protected voidconstructMapping2ndStep(MappingNode node, Map<Object,Object> mapping)protected ObjectconstructObject(Node node)Construct object from the specified Node.protected ObjectconstructObjectNoCheck(Node node)protected StringconstructScalar(ScalarNode node)protected List<? extends Object>constructSequence(SequenceNode node)protected voidconstructSequenceStep2(SequenceNode node, Collection<Object> collection)protected Set<Object>constructSet(MappingNode node)protected Set<? extends Object>constructSet(SequenceNode node)protected voidconstructSet2ndStep(MappingNode node, Set<Object> set)protected ObjectcreateArray(Class<?> type, int size)protected List<Object>createDefaultList(int initSize)protected Map<Object,Object>createDefaultMap(int initSize)protected Set<Object>createDefaultSet(int initSize)protected ObjectfinalizeConstruction(Node node, Object data)protected ConstructgetConstructor(Node node)Get the constructor to construct the Node.ObjectgetData()Construct and return the next documentPropertyUtilsgetPropertyUtils()ObjectgetSingleData(Class<?> type)Ensure that the stream contains a single document and construct itbooleanisAllowDuplicateKeys()booleanisExplicitPropertyUtils()protected ObjectnewInstance(Class<?> ancestor, Node node)protected ObjectnewInstance(Class<?> ancestor, Node node, boolean tryDefault)protected ObjectnewInstance(Node node)protected List<Object>newList(SequenceNode node)protected Map<Object,Object>newMap(MappingNode node)protected Set<Object>newSet(CollectionNode<?> node)voidsetAllowDuplicateKeys(boolean allowDuplicateKeys)voidsetComposer(Composer composer)voidsetPropertyUtils(PropertyUtils propertyUtils)
-
-
-
Field Detail
-
yamlClassConstructors
protected final Map<NodeId,Construct> yamlClassConstructors
It maps the node kind to the 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)
-
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.
-
composer
protected Composer composer
-
rootTag
protected Tag rootTag
-
typeDefinitions
protected final Map<Class<? extends Object>,TypeDescription> typeDefinitions
-
-
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 Object getData()
Construct and return the next document- Returns:
- constructed instance
-
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
-
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 String constructScalar(ScalarNode node)
-
newInstance
protected final Object newInstance(Class<?> ancestor, Node node) throws InstantiationException
- Throws:
InstantiationException
-
newInstance
protected Object newInstance(Class<?> ancestor, Node node, boolean tryDefault) throws InstantiationException
- Throws:
InstantiationException
-
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)
-
constructSet
protected Set<? extends Object> constructSet(SequenceNode node)
-
constructArray
protected Object constructArray(SequenceNode node)
-
constructSequenceStep2
protected void constructSequenceStep2(SequenceNode node, Collection<Object> collection)
-
constructArrayStep2
protected Object constructArrayStep2(SequenceNode node, Object array)
-
constructSet
protected Set<Object> constructSet(MappingNode node)
-
constructMapping
protected Map<Object,Object> constructMapping(MappingNode node)
-
constructMapping2ndStep
protected void constructMapping2ndStep(MappingNode node, Map<Object,Object> mapping)
-
constructSet2ndStep
protected void constructSet2ndStep(MappingNode node, Set<Object> set)
-
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)
-
-