com.mobenga.ngen.xml.parser.ProtectedClassMap Maven / Gradle / Ivy
Show all versions of ngen-xml-parser Show documentation
package com.mobenga.ngen.xml.parser;
import com.google.common.collect.MutableClassToInstanceMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class contains a set of object, with the single rule that each object in the set must be of a unique class.
*
* It is used to keep the XML Parsers "Object Branch". This contains all objects in the current branch of the destination
* tree. The destination tree is a tree (or a single node) that describes the Java structure that becomes the result
* of this parsing. The Object Branch does not contain any relations itself, the relation between objects in the destination
* tree is kept in the objects themselves like in an ordinary tree. Thus a protected class map is a good data storage
* for a branch in the tree.
*
* Typically, each time a result object is created during the XML parsing, it is pushed to this map. When the parsing
* is done with the object it is poped from this map. this makes the object in this map reflect the current branch in the XML.
* Finally getInstance can be used to peek at an object in the current object branch.
*
* For example, when parsing a retail range for an e-commerce we have a product category that contains a set of products.
* Each product contains a set of spare parts, and each spare part contains a set of prices for different markets.
* During the parsing process, the Object Branch will typically contain the object that is currently "written" to and
* all its ancestors. Data in current XML level can be injected in any object in the Object Branch.
*
*/
public class ProtectedClassMap {
private static final Logger log = LoggerFactory.getLogger(ProtectedClassMap.class);
private final MutableClassToInstanceMap