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

com.venky.extension.Registry Maven / Gradle / Ivy

There is a newer version: 1.18
Show newest version
package com.venky.extension;

import java.util.HashMap;
import java.util.List;

import com.venky.core.collections.SequenceSet;


public class Registry {
	private Registry(){
		
	}
	private static Registry instance = new Registry();
	public static Registry instance(){
		return instance;
	}
	private HashMap> extensionsMap = new HashMap>();
	public void registerExtension(String name,Extension extension){
		List extensions = getExtensions(name);
		extensions.add(extension);
	}
	
	public List getExtensions(String extensionPoint){
		List extensions = extensionsMap.get(extensionPoint);
		if (extensions == null){
			extensions = new SequenceSet();
			extensionsMap.put(extensionPoint,extensions);
		}
		return extensions;
	}
	
	public void deregisterExtension(String extensionPoint, Extension extension) {
		List extensions = getExtensions(extensionPoint);
		extensions.remove(extension);
	}
	public boolean hasExtensions(String extensionPoint){
		return !getExtensions(extensionPoint).isEmpty();
	}
	
	public void callExtensions(String pointName, Object... context){
		for (Extension extn : getExtensions(pointName)){
			extn.invoke(context);
		}
	}
	
	public void clearExtensions(){
		extensionsMap.clear();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy