org.nasdanika.persistence.DispatchingLoader Maven / Gradle / Ivy
package org.nasdanika.persistence;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import org.eclipse.emf.common.util.URI;
import org.nasdanika.common.ProgressMonitor;
/**
* Registers loaders by prefixes and then delegates to the registered loaders removing prefix first.
* @author Pavel
*
*/
public class DispatchingLoader implements ObjectLoader {
private org.nasdanika.persistence.ObjectLoader chain;
public DispatchingLoader(ObjectLoader chain) {
this.chain = chain;
}
public DispatchingLoader() {}
protected Map registry = new HashMap<>();
/**
* Registers a loader with given prefix
* @param prefix
* @param loader
*/
public void register(String prefix, ObjectLoader loader) {
registry.put(prefix, loader);
}
@Override
public Object create(
ObjectLoader loader,
String type,
Object config,
URI base,
BiConsumer