com.venky.extension.Registry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Commonly used programming tasks in java
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();
}
}