package org.libj.xquery.xml.str;

import org.libj.xquery.xml.XML;
import org.libj.xquery.xml.XMLFactory;

import java.util.HashMap;
import java.util.Map;

public class StringNamespaceXMLFactory implements XMLFactory {
    private Map<String, String> namespaces = new HashMap<String, String>();
    public XML toXML(String xml) {
        return new StringNamespaceXML(xml, namespaces);
    }

    public void registerNamespace(String prefix, String namespace) {
        namespaces.put(prefix, namespace);
    }
}

package org.libj.xquery.xml.str;

import org.libj.xquery.xml.XML;
import org.libj.xquery.xml.XMLFactory;

import java.util.HashMap;
import java.util.Map;

public class StringNamespaceXMLFactory implements XMLFactory {
    private Map<String, String> namespaces = new HashMap<String, String>();
    public XML toXML(String xml) {
        return new StringNamespaceXML(xml, namespaces);
    }

    public void registerNamespace(String prefix, String namespace) {
        namespaces.put(prefix, namespace);
    }

    public static final XMLFactory SHARED_FACTORY = new StringNamespaceXMLFactory() {
        @Override
        public void registerNamespace(String prefix, String namespace) {
            throw new UnsupportedOperationException("StringNamespaceXMLFactory.SHARED_FACTORY is readonly");
        }
    };

}

create a immutable shared factory (can't register namespace), in the case factory creation is bottleneck