Jackson Dataformat XML Source Code

Jackson is "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java".

Jackson also allows you to parse or generate XML messages with the Jackson Dataformat XML Extension.

Jackson Dataformat XML Source Code files are provided in the source packge (jackson-dataformat-xml-2.12.4-sources.jar). You can download it at Jackson Maven Website.

You can also browse Jackson Dataformat XML Source Code below:

✍: FYIcenter.com

com/fasterxml/jackson/dataformat/xml/deser/ElementWrapper.java

package com.fasterxml.jackson.dataformat.xml.deser;

/**
 * Helper class needed to keep track of virtual wrapper elements
 * added in the logical XML token stream.
 */
class ElementWrapper
{
    protected final ElementWrapper _parent;
    protected final String _wrapperName;
    protected final String _wrapperNamespace;

    /*
    /**********************************************************
    /* Life-cycle
    /**********************************************************
     */
    
    private ElementWrapper(ElementWrapper parent) {
        _parent = parent;
        _wrapperName = null;
        _wrapperNamespace = "";
    }
    
    private ElementWrapper(ElementWrapper parent,
            String wrapperLocalName, String wrapperNamespace)
    {
        _parent = parent;
        _wrapperName = wrapperLocalName;
        _wrapperNamespace = (wrapperNamespace == null) ? "" : wrapperNamespace;
    }

    /**
     * Factory method called to construct a new "matching" wrapper element,
     * at level where virtual wrapping is needed.
     */
    public static ElementWrapper matchingWrapper(ElementWrapper parent,
            String wrapperLocalName, String wrapperNamespace)
    {
        return new ElementWrapper(parent, wrapperLocalName, wrapperNamespace);
    }

    /**
     * Factory method used for creating intermediate wrapper level, which
     * is only used for purpose of keeping track of physical element
     * nesting.
     */
    public ElementWrapper intermediateWrapper() {
        return new ElementWrapper(this, null, null);
    }
    
    /*
    /**********************************************************
    /* API
    /**********************************************************
     */

    public boolean isMatching() { return _wrapperName != null; }
    
    public String getWrapperLocalName() { return _wrapperName; }
    public String getWrapperNamespace() { return _wrapperNamespace; }

    public ElementWrapper getParent() { return _parent; }

    public boolean matchesWrapper(String localName, String ns)
    {
        // null means "anything goes", so:
        if (_wrapperName == null) {
            return true;
        }
        if (ns == null) {
            ns = "";
        }
        return _wrapperName.equals(localName) && _wrapperNamespace.equals(ns);
    }

    /*
    /**********************************************************
    /* Overrides
    /**********************************************************
     */

    @Override
    public String toString()
    {
        if (_parent == null) {
            return "Wrapper: ROOT, matching: "+_wrapperName;
        }
        if (_wrapperName == null) {
            return "Wrapper: empty";
        }
        return "Wrapper: branch, matching: "+_wrapperName;
    }
}

com/fasterxml/jackson/dataformat/xml/deser/ElementWrapper.java

 

⇒ Download Jackson Dataformat Binary Packages

⇐ Jackson Dataformat Extensions

⇑ Downloading and Reviewing jackson-*.jar

⇑⇑ Jackson - Java JSON library

2021-10-10, 6434👍, 0💬