通过 Java API 配置数据源

装入文档规范之后,您可以循环访问模板和每个模板的数据源。模板的数据源可在 RPETemplate.getDataSources() 集合中找到。 识别数据源之后,您可以根据需要修改数据源属性。
以下示例显示了对数据源“DS1”的 URI 的修改过程。在文档规范的所有模板中搜索该数据源。如果要限制该搜索,那么需要验证模板的路径属性。
for (RPETemplate template : docspec.getRuntime().getTemplates())
{
	String templatePath = PropertyUtils.getPropertyRawValue( template.getProperty(RPEConfigConstants.PROPERTY_PATH), “”);

	for ( RPEDataSource ds : template.getDataSources())
	{
	String dsName = PropertyUtils.getPropertyRawValue( ds.getProperty(RPEConfigConstants.PROPERTY_NAME), “”); 
	if ( dsName.equals(DS1))
	{
		Property dsURI = ds.getProperty(RPEConfigConstants.PROPERTY_URI);
		assert( dsURI != null);
		dsURI.setValue( new Value( null, “c:\\test\\sample.xml”));
	}
}
注: 还可以在将模板添加到文档规范时,从该模板配置数据源。

反馈