Portlet 和 PortletApplication MBean
类型为 Portlet 和 portletapplication 的 MBean 提供关于给定 Portlet 应用程序及其 Portlet 的信息。通过类型为 portletapplication 的 MBean,您可以检索属于 Portlet 应用程序的所有 Portlet 的名称列表。通过查询类型为 Portlet 且具有给定 Portlet 名称的 MBean,您可以从类型为 Portlet 的 MBean 中检索特定于 Portlet 的信息。
对应于 Portlet 或 Portlet 应用程序的每个 MBean
可通过其名称唯一地进行标识。不要求 Portlet 应用程序在
portlet.xml 中设置名称。portletapplication 类型的 MBean 的名称由后跟“#”的企业归档 (EAR) 文件名和后接字符串“_portlet”的 Web 模块名称组成。例如,portletapplication 类型 MBean 具有以下格式:
<EarFileName>#<WarFileName>_portlet为 Portlet 类型的 MBean 选择的名称是 Portlet 所属的 portletapplication 类型的 MBean 名称,此名称后面接 Portlet 名称:
<EarFileName>#<WarFileName>_portlet.<portletname>
以下是最后的 PortletApplication MBean 名称和 Portlet 名称的示例:
EarName SampleEar
WebModule SampleWar.war
PortletApplication MBean name: SampleEar#SampleWar_portlet
Portlet: SampleEar#SampleWar_portlet.BookmarkPortlet
已经根据 V6.1 更改了 MBean 名称,因为旧的命名模式不是唯一的,而且在某种情况下可能导致问题的出现。
如果您仍需要旧的命名模式,那么可以设置 Portlet 容器定制属性 useShortMBeanNames 为 true,以激活先前的已知 MBean 名称。因为这会影响性能,所以除非必要,最好不要激活旧的命名模式。句点用于将前面的 Web 模块名称与 Portlet 名称分隔开。请查看 Portlet 和 PortletApplication MBean 类型 API 文档以获取其他信息。在信息中心目录中,所生成的 API 文档位于以下路径中:
。以下代码示例说明如何使用名称 (SampleWar) 调用应用程序的 portletapplication 类型 MBean。
String myPortletApplicationName = "SampleEar#SampleWar_portlet";
This name is composed by the Ear file name followed by "#" and
the web module name concatenated with the substring "_portlet"
com.ibm.websphere.management.AdminService adminService =
com.ibm.websphere.management.AdminServiceFactory.getAdminService();
javax.management.ObjectName on =
new ObjectName("WebSphere:type=PortletApplication,name=" + myPortletApplicationName + ",*");
Iterator onIter = adminService.queryNames(on, null).iterator();
while(onIter.hasNext())
{
on = (ObjectName)onIter.next();
}
String ctxRoot = (java.lang.String)adminService.getAttribute(on, "webApplicationContextRoot");
在上面的示例中,首先查询 MBeanServer 以获取类型为 portletapplication 的 MBean。如果此查询成功,那么在该 MBean 或找到的第一个 MBean 上检索 webApplicationContextRoot 属性。结果存储在 ctxRoot 变量中。此变量现在包含 Web 应用程序的上下文根,该 Web 应用程序包含搜索的 Portlet 应用程序。此变量类似于“/bookmark”。下一个代码示例说明如何调用名称为 BookmarkPortlet 的 MBean 类型的 portlet。
String myPortletName = "SampleEar#SampleWar_portlet.BookmarkPortlet";
This name is composed by the name of the MBean of type portletapplication and
the portlet name, separated by a full stop because the same portlet name may
be used within different web modules, but must be unique within the system.
com.ibm.websphere.management.AdminService adminService =
com.ibm.websphere.management.AdminServiceFactory.getAdminService();
javax.management.ObjectName on =
new ObjectName("WebSphere:type=Portlet,name=" + myPortletName + ",*");
Iterator iter = adminService.queryNames(on, null).iterator();
while(iter.hasNext())
{
on = (ObjectName)iter.next;
}
java.util.Locale locale = (java.util.Locale) adminService.getAttribute(on, "defaultLocale");
由 MBean 的方法 getAttribute 返回的语言环境是为此 Portlet 定义的缺省语言环境。Portlet 和 PortletApplication MBean 的全名
还可以使用全限定名称注册 MBean:
<ApplicationName>#<WARfilename.war>_portlet.<portlet_name> for the Portlet MBean
<ApplicationName>#<WARfilename.war>_portlet for the PortletApplication MBean
其中 <..> 将替换为相应的应用程序数据。例如,SampleApplication#SamplePortlet.war_portlet.SamplePortlet。通过设置 useShortMBeanNames Portlet 容器定制属性为 true,您可以启用简短 MBean 名称。