1 7 8 package org.jboss.media.engine; 9 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 13 import org.jboss.logging.Logger; 14 import org.jboss.system.ServiceMBeanSupport; 15 import org.w3c.dom.Element ; 16 import org.w3c.dom.Node ; 17 import org.w3c.dom.NodeList ; 18 19 25 public class MediaPluginRegistry 26 extends ServiceMBeanSupport 27 implements MediaPluginRegistryMBean 28 { 29 private HashMap m_plugins = new HashMap (); 30 private Logger log = Logger.getLogger(getClass()); 31 private Element m_initialPlugins; 32 33 36 public void addPlugin(String name, MediaPlugin object) 37 { 38 m_plugins.put(name, object); 39 log.info( 40 "adding plugin with name " + name + "of class " + object.getName()); 41 } 42 43 46 public void removePlugin(String name) 47 { 48 m_plugins.remove(name); 49 log.info("removing plugin with name " + name); 50 } 51 52 55 public Iterator getPluginNames() 56 { 57 return ((HashMap ) m_plugins.clone()).keySet().iterator(); 58 } 59 60 63 public MediaPlugin getPlugin(String name) 64 { 65 return (MediaPlugin) m_plugins.get(name); 66 } 67 68 72 public Element getInitialPlugins() 73 { 74 return m_initialPlugins; 75 } 76 77 81 public void setInitialPlugins(Element xml) 82 { 83 m_initialPlugins = xml; 84 NodeList children = xml.getChildNodes(); 85 for (int i = 0; i < children.getLength(); i++) 86 { 87 if (children.item(i).getNodeType() == Node.ELEMENT_NODE) 88 { 89 Element element = (Element ) children.item(i); 90 String tag = element.getTagName(); 91 92 String name = element.getAttribute("name"); 95 String classname = element.getAttribute("class"); 96 try 97 { 98 addPlugin(name, (MediaPlugin)Class.forName(classname).newInstance()); 99 } 100 catch (InstantiationException e) 101 { 102 log.error(e); 103 } 104 catch (IllegalAccessException e) 105 { 106 log.error(e); 107 } 108 catch (ClassNotFoundException e) 109 { 110 log.error("Could not find plugin with class " + classname); 111 } 112 } 114 } 115 } 116 117 } 118 | Popular Tags |