如何通过IBM FileNet CE API 通过符号名称获取PropertyTemplate并将其附加到Custom Object类
您可以使用以下函数来获取属性模板:
public PropertyTemplate getPropertyTemplate(String name, ObjectStore objectStore )
{
String queryFormat = "SELECT [This] FROM [PropertyTemplate] WHERE ([SymbolicName] = ''{0}'')";
SearchScope scope = new SearchScope( objectStore );
String query = MessageFormat.format(queryFormat, name );
RepositoryRowSet fetchRows = scope.fetchRows(new SearchSQL( query ), null, null, null );
Iterator<?> iterator = fetchRows.iterator();
if ( !iterator.hasNext() )
{
return null;
}
RepositoryRow row = (RepositoryRow) iterator.next();
return (PropertyTemplate) row.getProperties().getObjectValue("This");
}
然后使用以下代码将属性模板添加到类中:
PropertyTemplate propertyTemplate = getPropertyTemplate(name, objectStore);
ClassDefinition classDefinition = Factory.ClassDefinition.fetchInstance(objectStore, className, null);
PropertyDefinition propertyDefinition = propertyTemplate.createClassProperty();
// Set some additional properties on the property definition
// to override template defaults
classDefinition.get_PropertyDefinitions().add(propertyDefinition);
classDefinition.save(RefreshMode.NO_REFRESH);