Author: thomas.heute(a)jboss.com
Date: 2007-03-29 11:28:11 -0400 (Thu, 29 Mar 2007)
New Revision: 6868
Modified:
trunk/core/src/main/org/jboss/portlet/content/ContentTypeRegistration.java
Log:
Fixed registration of mbean with dependencies.
Modified: trunk/core/src/main/org/jboss/portlet/content/ContentTypeRegistration.java
===================================================================
--- trunk/core/src/main/org/jboss/portlet/content/ContentTypeRegistration.java 2007-03-28
16:37:50 UTC (rev 6867)
+++ trunk/core/src/main/org/jboss/portlet/content/ContentTypeRegistration.java 2007-03-29
15:28:11 UTC (rev 6868)
@@ -22,32 +22,38 @@
******************************************************************************/
package org.jboss.portlet.content;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.Attribute;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.log4j.Logger;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.portal.Mode;
+import org.jboss.portal.core.impl.model.content.InternalContentProviderRegistry;
import org.jboss.portal.core.impl.model.content.generic.GenericContentProviderRegistry;
import org.jboss.portal.core.impl.model.content.generic.InternalGenericContentProvider;
-import org.jboss.portal.core.impl.model.content.InternalContentProviderRegistry;
-import org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer;
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.spi.portlet.ContentPortlet;
-import org.jboss.portal.core.model.content.spi.ContentProviderRegistry;
import org.jboss.portal.core.model.instance.InstanceContainer;
-import org.jboss.portal.Mode;
import org.jboss.portal.jems.as.system.JBossServiceModelMBean;
-import org.jboss.mx.util.MBeanProxy;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.apache.log4j.Logger;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContext;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.Attribute;
-
/**
* Provide registration of a content type with a portlet instance. This listener can be
used
* in war files to register content driven portlet.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @version $Revision: 1.1 $
*/
public class ContentTypeRegistration implements ServletContextListener
@@ -90,51 +96,80 @@
//
log.debug("About to register content type "+ contentType + " with
portlet instance " + portletInstanceName);
- GenericContentProviderRegistry providerRegistry =
GenericContentProviderRegistry.getInstance();
- if (providerRegistry != null)
+ InternalGenericContentProvider provider = new InternalGenericContentProvider();
+ provider.setContentType(contentType.toString());
+
+ provider.setDecorateContent(true);
+ provider.setContentPortletInfo(contentPortlet);
+
+ try
{
+ String name = "portal:service=ContentRenderer,type=" +
portletInstanceName;
+ ObjectName objectName = new ObjectName(name);
+ MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+ JBossServiceModelMBean mbean = new JBossServiceModelMBean(provider);
- providerRegistry.register(contentType, contentPortlet);
- log.debug("Registered content type "+ contentType + " with
portlet instance " + portletInstanceName);
+ // Register the mbean
+ mbeanServer.registerMBean(mbean, objectName);
+
+ //
+ ObjectName scObjectName = new
ObjectName("jboss.system:service=ServiceController");
+ mbeanServer.invoke(scObjectName, "create", new ObjectName[]
{objectName} , new String[] {"javax.management.ObjectName"});
+
+ // Get proxy on Content Provide Registry
+ ObjectName contentProviderRegistryON = new
ObjectName("portal:service=ContentProviderRegistry");
+ Object registry = MBeanProxy.get(InternalContentProviderRegistry.class,
contentProviderRegistryON, mbeanServer);
+ mbean.setAttribute(new Attribute("Registry", registry));
+
+ // Get proxy on Instance Container
+ ObjectName instanceContainerON = new
ObjectName("portal:container=Instance");
+ Object container = MBeanProxy.get(InstanceContainer.class, instanceContainerON,
mbeanServer);
+ mbean.setAttribute(new Attribute("InstanceContainer", container));
+
+ // Set dependencies
+ List dependencies = new ArrayList();
+ dependencies.add(contentProviderRegistryON);
+ dependencies.add(instanceContainerON);
+ mbeanServer.invoke(scObjectName, "register", new Object[] {objectName,
dependencies} , new String[] {"javax.management.ObjectName",
"java.util.Collection"});
+
+ // Start the mbean
+ mbeanServer.invoke(scObjectName, "start", new ObjectName[]
{objectName} , new String[] {"javax.management.ObjectName"});
+
+ log.debug("Registered InternalGenericContentProvider with name:" +
name);
}
- else
+ catch(Exception e)
{
- InternalGenericContentProvider provider = new InternalGenericContentProvider();
- provider.setContentType(contentType.toString());
+ log.warn("Couldn't perform ContentProvider registration", e);
+ return;
+ }
+ log.debug("Registered content type "+ contentType + " with portlet
instance " + portletInstanceName);
+ }
- provider.setDecorateContent(true);
- provider.setContentPortletInfo(contentPortlet);
-
+ public void contextDestroyed(ServletContextEvent event)
+ {
+ if (contentType != null)
+ {
+ log.debug("About to unregister content type "+ contentType);
+
+ //
+ final String portletInstanceName =
event.getServletContext().getInitParameter("org.jboss.portal.portlet_instance");
+ String name = "portal:service=ContentRenderer,type=" +
portletInstanceName;
try
{
- String name = "portal:service=InternalGenericContentProvider,type="
+ portletInstanceName;
+ ObjectName objectName = new ObjectName(name);
+ ObjectName scObjectName = new
ObjectName("jboss.system:service=ServiceController");
+
+ // Stop the mbean
MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
- JBossServiceModelMBean mbean = new JBossServiceModelMBean(provider);
- Object registry = MBeanProxy.get(InternalContentProviderRegistry.class, new
ObjectName("portal:service=ContentProviderRegistry"), mbeanServer);
- Object container = MBeanProxy.get(InstanceContainer.class, new
ObjectName("portal:container=Instance"), mbeanServer);
- mbeanServer.registerMBean(mbean, new ObjectName(name));
- log.debug("Registered InternalGenericContentProvider with name:" +
name);
- mbean.setAttribute(new Attribute("Registry", registry));
- mbean.setAttribute(new Attribute("InstanceContainer", container));
-
+ mbeanServer.invoke(scObjectName, "stop", new ObjectName[]
{objectName} , new String[] {"javax.management.ObjectName"});
}
catch(Exception e)
{
log.warn("Couldn't perform ContentProvider registration", e);
return;
}
- log.debug("Registered content type "+ contentType + " with
portlet instance " + portletInstanceName);
- }
- }
- public void contextDestroyed(ServletContextEvent event)
- {
- if (contentType != null)
- {
- log.debug("About to unregister content type "+ contentType);
- GenericContentProviderRegistry providerRegistry =
GenericContentProviderRegistry.getInstance();
- providerRegistry.unregister(contentType);
log.debug("Content type "+ contentType + " has been
unregistered");
}
}
Show replies by date