您可使用 Java EE Application Deployment API 规范 (JSR-88) 中的 DConfigBean 类,在部署期间配置
Java Platform, Enterprise Edition (Java EE) 应用程序或独立模块。
关于此任务
JSR-88 中的 DConfigBean 类提供部署期间对 J2EE 应用程序和模块的、特定于平台配置的、基于 JavaBeans 的支持。您的代码可检查 DConfigBean 实例,以获取特定于平台的配置属性。WebSphere Application Server 提供的
DConfigBean 实例包含单个属性,它具有 java.util.Map 对象数组。映射条目包含配置属性,您的代码可获取并设置其值。
过程
- 编写使用 JSR-88 在应用程序服务器上安装 Java EE 模块的代码。
- 编写代码,该代码在部署 JSR-88 期间,访问产品生成的 DConfigBean。然后,您(或部署者)可定制已访问的 DConfigBeans 实例。
下列伪码显示 Java EE 工具提供程序可如何在 JSR-88 部署期间获取产品生成的 DConfigBean 实例属性,并为这些属性设置值。
import javax.enterprise.deploy.model.*;
import javax.enterprise.deploy.spi.*;
{
DeploymentConfiguration dConfig = ___; // Get from DeploymentManager
DDBeanRoot ddRoot = ___; // Provided by J2EE tool
// Obtain root bean.
DConfigBeanRoot dcRoot = dConfig.getDConfigBeanRoot(dr);
// Configure DConfigBean.
configureDCBean (dcRoot);
}
// Get children from DConfigBeanRoot and configure each child.
method configureDCBean (DConfigBean dcBean)
{
// Get DConfigBean attributes for a given archive.
BeanInfo bInfo = Introspector.getBeanInfo(dcBean.getClass());
IndexedPropertyDescriptor ipDesc =
(IndexedPropertyDescriptor)bInfo.getPropertyDescriptors()[0];
// Get the 0th map.
int index = 0;
Map map = (Map)
ipDesc.getIndexedReadMethod().invoke
(dcBean, new Object[]{new Integer(index)});
while (map != null)
{
// Iterate over the map and set values for attributes.
// Set the map back into the DCBean.
ipDesc.getIndexedWriteMethod().invoke
(dcBean, new Object[]{new Integer(index), map});
// Get the next entry in the indexed property
map = (Map)
ipDesc.getIndexedReadMethod().invoke
(dcBean, new Object[]{new Integer(++index)});
}
}