KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > engine > MediaPluginRegistry


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.engine;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Iterator JavaDoc;
12
13 import org.jboss.logging.Logger;
14 import org.jboss.system.ServiceMBeanSupport;
15 import org.w3c.dom.Element JavaDoc;
16 import org.w3c.dom.Node JavaDoc;
17 import org.w3c.dom.NodeList JavaDoc;
18
19 /**
20  * @version <tt>$Revision: 1.2 $</tt>
21  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
22  * @jmx.mbean extends="org.jboss.system.ServiceMBean"
23  * @jmx.mbean description="The media engine plugin registry"
24  */

25 public class MediaPluginRegistry
26    extends ServiceMBeanSupport
27    implements MediaPluginRegistryMBean
28 {
29    private HashMap JavaDoc m_plugins = new HashMap JavaDoc();
30    private Logger log = Logger.getLogger(getClass());
31    private Element JavaDoc m_initialPlugins;
32
33    /**
34     * @jmx.managed-operation description="add a plugin"
35     */

36    public void addPlugin(String JavaDoc 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    /**
44     * @jmx.managed-operation description="remove a plugin"
45     */

46    public void removePlugin(String JavaDoc name)
47    {
48       m_plugins.remove(name);
49       log.info("removing plugin with name " + name);
50    }
51
52    /**
53     * @jmx.managed-operation description="get the list of plugins"
54     */

55    public Iterator JavaDoc getPluginNames()
56    {
57       return ((HashMap JavaDoc) m_plugins.clone()).keySet().iterator();
58    }
59
60    /**
61     * @jmx.managed-operation description="acquire a plugin"
62     */

63    public MediaPlugin getPlugin(String JavaDoc name)
64    {
65       return (MediaPlugin) m_plugins.get(name);
66    }
67
68    /**
69     * @return
70     * @jmx.managed-attribute
71     */

72    public Element JavaDoc getInitialPlugins()
73    {
74       return m_initialPlugins;
75    }
76
77    /**
78     * @param element
79     * @jmx.managed-attribute
80     */

81    public void setInitialPlugins(Element JavaDoc xml)
82    {
83       m_initialPlugins = xml;
84       NodeList JavaDoc 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 JavaDoc element = (Element JavaDoc) children.item(i);
90             String JavaDoc tag = element.getTagName();
91
92            // if (tag.equals("plugin"))
93
// {
94
String JavaDoc name = element.getAttribute("name");
95                String JavaDoc classname = element.getAttribute("class");
96                try
97                {
98                   addPlugin(name, (MediaPlugin)Class.forName(classname).newInstance());
99                }
100                catch (InstantiationException JavaDoc e)
101                {
102                   log.error(e);
103                }
104                catch (IllegalAccessException JavaDoc e)
105                {
106                   log.error(e);
107                }
108                catch (ClassNotFoundException JavaDoc e)
109                {
110                   log.error("Could not find plugin with class " + classname);
111                }
112             //}
113
}
114       }
115    }
116
117 }
118
Popular Tags