タイプが Portlet および PortletApplication の MBean は、所定のポートレット・アプリケーションおよびそのポートレットの情報を提供します。 タイプが PortletApplication の MBean を使用すると、ポートレット・アプリケーションに属するすべてのポートレットの名前のリストを取得できます。 タイプが Portlet の MBean を所定のポートレット名で照会すると、タイプが Portlet の MBean からポートレット固有の情報を取得できます。
ポートレットまたはポートレット・アプリケーションに対応する各 MBean は、その名前によって一意的に識別可能です。 ポートレット・アプリケーションでは、portlet.xml 内に名前セットが存在する必要はありません。 そのためタイプが PortletApplication の MBean では、ストリング「_portletapplication」と連結した Web モジュール名が MBean 名として選択されています。 タイプが Portlet の MBean の名前は、ポートレットが属する、タイプが PortletApplication の MBean の名前とポートレット名を連結したものです。 Web モジュール名とポートレット名はピリオドで区切られています。 タイプが Portlet および PortletApplication の MBean の詳細については、生成済み API 文書を参照してください。 生成済み API 文書は、インフォメーション・センターの目次で、「参照」>「Administrator」>「API 文書」>「MBean interfaces」とたどって入手できます。
String myPortletApplicationName = "Bookmark_war_portletapplication";
This name is composed by the Web module name concatenated with the substring "_portletapplication"
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 を照会されています。
この照会が成功した場合は、属性 webApplicationContextRoot がその MBean 上か、最初に見つかった MBean 上で検索され、結果が変数 ctxRoot 内に格納されます。
この変数には、検索されたポートレット・アプリケーションを含む Web アプリケーションのコンテキスト・ルートが含まれています。
例えば、これは「/bookmark」のようになります。
String myPortletName = "Bookmark_war_portletapplication.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");
getAttribute メソッドによって戻される MBean のロケールは、このポートレットで定義されているデフォルト・ロケールです。