1 package com.sslexplorer.extensions; 2 3 import java.util.HashMap ; 4 5 import org.apache.commons.logging.Log; 6 import org.apache.commons.logging.LogFactory; 7 8 import com.sslexplorer.extensions.types.AgentType; 9 import com.sslexplorer.extensions.types.DefaultAgentType; 10 import com.sslexplorer.extensions.types.LanguagePackType; 11 import com.sslexplorer.extensions.types.PluginType; 12 13 14 21 public class ExtensionTypeManager { 22 23 private static ExtensionTypeManager instance; 24 private static Log log = LogFactory.getLog(ExtensionTypeManager.class); 25 26 private HashMap <String , Class > extensionTypes = new HashMap <String , Class >(); 27 28 31 public ExtensionTypeManager() { 32 extensionTypes.put(PluginType.TYPE, PluginType.class); 33 extensionTypes.put(AgentType.TYPE, AgentType.class); 34 extensionTypes.put(DefaultAgentType.TYPE, DefaultAgentType.class); 35 extensionTypes.put(LanguagePackType.TYPE, LanguagePackType.class); 36 } 37 38 43 public static ExtensionTypeManager getInstance() { 44 return instance==null ? instance = new ExtensionTypeManager() : instance; 45 } 46 47 53 public void registerExtensionType(String type, Class cls) { 54 extensionTypes.put(type, cls); 55 } 56 57 62 public void unregisterExtensionType(String type) { 63 extensionTypes.remove(type); 64 } 65 66 75 public ExtensionType getExtensionType(String type, ExtensionBundle bundle) throws ExtensionException { 76 try { 77 if(extensionTypes.containsKey(type)) { 78 return (ExtensionType) extensionTypes.get(type).newInstance(); 79 } 80 } catch (Throwable t) { 81 log.error("Failed to create extension type " + type, t); 82 } 83 throw new ExtensionException(ExtensionException.UNKNOWN_EXTENSION_TYPE, type, bundle.getId()); 84 85 } 86 } 87 | Popular Tags |