All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.n2oapp.framework.api.metadata.io.ProxyNamespaceIO Maven / Gradle / Ivy

There is a newer version: 7.28.2
Show newest version
package net.n2oapp.framework.api.metadata.io;

import net.n2oapp.framework.api.metadata.aware.NamespaceUriAware;
import net.n2oapp.framework.api.metadata.persister.NamespacePersister;
import net.n2oapp.framework.api.metadata.reader.NamespaceReader;
import org.jdom2.Element;
import org.jdom2.Namespace;

/**
 * Проксирующий считыватель элементов по неймспейсу
 * @param  Тип модели элемента
 */
public class ProxyNamespaceIO implements NamespaceReader, NamespacePersister, IOProcessorAware {

    private NamespaceIO io;
    private IOProcessor processor;

    public ProxyNamespaceIO(NamespaceIO io, IOProcessor processor) {
        this.io = io;
        this.processor = processor;
    }

    public ProxyNamespaceIO(NamespaceIO io) {
        this.io = io;
    }

    @Override
    public Class getElementClass() {
        return io.getElementClass();
    }

    @Override
    public String getElementName() {
        return io.getElementName();
    }

    @Override
    public String getNamespaceUri() {
        return io.getNamespaceUri();
    }


    @Override
    public Element persist(T entity, Namespace namespace) {
        Element element = new Element(getElementName(), entity.getNamespaceUri() != null ? entity.getNamespaceUri() : namespace.getURI());
        io.io(element, entity, processor);
        return element;
    }

    @Override
    public T read(Element element) {
        T entity = newInstance(element);
        io.io(element, entity, processor);
        entity.setNamespaceUri(element.getNamespaceURI());
        entity.setNamespacePrefix(element.getNamespacePrefix());
        return entity;
    }

    @Override
    public void setNamespaceUri(String namespaceUri) {
    }

    @Override
    public void setIOProcessor(IOProcessor processor) {
        this.processor = processor;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy