Java 如何在FileNet P8中获取属性数据类型
在FileNetP8中,我需要使用JavaAPI获取自定义类的属性的数据类型。有没有办法做到这一点?这会让你知道你需要做什么:Java 如何在FileNet P8中获取属性数据类型,java,filenet-p8,Java,Filenet P8,在FileNetP8中,我需要使用JavaAPI获取自定义类的属性的数据类型。有没有办法做到这一点?这会让你知道你需要做什么: //SymbolicName of the property we will search for. String strSearchName = PropertyNames.DATE_LAST_MODIFIED; //Document (or other object) that we will use to get classDescript
//SymbolicName of the property we will search for.
String strSearchName = PropertyNames.DATE_LAST_MODIFIED;
//Document (or other object) that we will use to get classDescription.
Document document = (Document) arg0;
PropertyDescription objPropDesc = null;
PropertyDescriptionList pdl = document.get_ClassDescription().get_PropertyDescriptions();
Iterator<?> iter = pdl.iterator();
while (iter.hasNext())
{
objPropDesc = (PropertyDescription) iter.next();
// Get SymbolicName property from the property cache
String strPropDescSymbolicName = objPropDesc.get_SymbolicName();
if (strPropDescSymbolicName.equalsIgnoreCase(strSearchName))
{
// PropertyDescription object found
System.out.println("Property description selected: " + strPropDescSymbolicName);
System.out.println(objPropDesc);
TypeID type = objPropDesc.get_DataType();
System.out.println(type.toString());
break;
}
}
//我们将搜索的属性的符号名称。
字符串strearchname=PropertyNames.DATE\u LAST\u MODIFIED;
//我们将用来获取类描述的文档(或其他对象)。
文档=(文档)arg0;
PropertyDescription objPropDesc=null;
PropertyDescriptionList pdl=document.get_ClassDescription().get_PropertyDescriptions();
迭代器iter=pdl.Iterator();
while(iter.hasNext())
{
objPropDesc=(PropertyDescription)iter.next();
//从属性缓存中获取SymbolicName属性
字符串strPropDesconymarcName=objPropDesc.get_SymbolicName();
if(strPropDescrSymbolicName.equalsIgnoreCase(strSearchName))
{
//找到PropertyDescription对象
System.out.println(“所选属性描述:+strpropsdescsymbolicName”);
System.out.println(objPropDesc);
TypeID type=objPropDesc.get_DataType();
System.out.println(type.toString());
打破
}
}
其想法是:
// Get the ClassDescription
String strSymbolicName = "myClassName";
ClassDescription objClassDesc = Factory.ClassDescription.fetchInstance(myObjStore, strSymbolicName, null);
// find the PropertyDescription
PropertyDescription pds = null;
PropertyDescriptionList pdl = objClassDesc.get_PropertyDescriptions();
Iterator<?> itr = pdl.iterator();
while(itr.hasNext()){
pds = (PropertyDescription) itr.next();
System.out.println("Symbolic Name is "+pds.get_SymbolicName()+" DataType is "+pds.get_DataType().toString());
}
// You can now use it in a loop of several documents if you wish.
...
//获取类描述
字符串strSymbolicName=“myClassName”;
ClassDescription objClassDesc=Factory.ClassDescription.fetchInstance(myObjStore,strSymbolicName,null);
//查找PropertyDescription
PropertyDescription pds=null;
PropertyDescriptionList pdl=objClassDesc.get_PropertyDescriptions();
迭代器itr=pdl.Iterator();
而(itr.hasNext()){
pds=(PropertyDescription)itr.next();
System.out.println(“符号名称为”+pds.get_SymbolicName()+“数据类型为”+pds.get_DataType().toString());
}
//如果您愿意,现在可以在多个文档的循环中使用它。
...
请看这里:克里斯托弗·鲍威尔的回答是正确的,但有一件事它没有涵盖(取决于所讨论的自定义类的定义)。把这个看作是一个“最佳实践”,或者只是从克里斯托弗提到的URL中借用的代码的扩展。 FileNet P8类层次结构允许继承属性定义。简单示例:可以搜索对象存储的“Document”类(类层次结构的根类),并在搜索sql中使用子类的某些属性。将子类1想象为文档的直接子类。子类1具有属性Property1。即使文档的类描述中没有此属性,在Property1='somevalue'的文档中进行搜索也将返回子类1的对象(如果与'somevalue'匹配) 但是,
objClassDesc.get_PropertyDescriptions();
不会返回子类的属性描述,因此可能会出现API_property_NOT_IN_缓存错误。
若要为您提供一个良好的起点,请查看以下代码:
PropertyDescriptionList ownProps = objClassDesc.get_PropertyDescriptions();
PropertyDescriptionList subclassProps = null;
if (objClassDesc.get_HasProperSubclassProperties()) {
logger.debug("Document class '"+documentClassname+"' supports 'include descendant properties' queries, including descendant properties.");
subclassProps = objClassDesc.get_ProperSubclassPropertyDescriptions();
}
List<PropertyDescription> result = mergePropertyDescriptionLists(ownProps, subclassProps);
PropertyDescriptionList ownProps=objClassDesc.get_PropertyDescriptions();
PropertyDescriptionList子类Props=null;
if(objClassDesc.get_HasProperSubclassProperties()){
debug(“documentclass'”+documentClassname+“'支持'包含子体属性'查询,包括子体属性');
subclassProps=objClassDesc.get_propertsubclasspropertydescriptions();
}
列表结果=合并属性描述列表(ownProps、Subclass Props);
如果需要合并这两个列表,最好使用PropertyDescription对象列表而不是PropertyDescriptionList:服务器返回的对象是只读的
@SuppressWarnings("unchecked")
protected List<PropertyDescription> mergePropertyDescriptionLists(PropertyDescriptionList list1, PropertyDescriptionList list2) throws Exception {
try {
@SuppressWarnings("unchecked")
List<PropertyDescription> mergedList = new ArrayList<PropertyDescription>();
if (list1 != null && (list1.size() > 0)) {
mergedList.addAll(list1);
}
if (list2 != null && (list2.size() > 0)) {
mergedList.addAll(list2);
}
return mergedList;
} catch (Throwable t) {
throw new Exception("Failed to merge property description lists.", t);
}
}
@SuppressWarnings(“未选中”)
受保护列表MergePropertyDescriptionList(PropertyDescriptionList列表1,PropertyDescriptionList列表2)引发异常{
试一试{
@抑制警告(“未选中”)
List mergedList=new ArrayList();
如果(list1!=null&(list1.size()>0)){
mergedList.addAll(列表1);
}
如果(list2!=null&(list2.size()>0)){
mergedList.addAll(列表2);
}
返回合并列表;
}捕获(可丢弃的t){
抛出新异常(“未能合并属性描述列表。”,t);
}
}
我认为这对我不起作用。在我的情况下,我需要将新文档添加到文件网。属性作为键值对传递。Document myDocument=Factory.Document.fetchInstance(myObjStore,aDocument.getDocumentClassName(),null);PropertyDescription pds=null;PropertyDescriptionList pdl=myDocument.get_ClassDescription().get_PropertyDescriptions();迭代器itr=pdl.Iterator();而(itr.hasNext(){pds=(PropertyDescription)itr.next();System.out.println(“符号名是”+pds.get_SymbolicName()+”数据类型是“+pds.get_DataType().toString());}您会得到什么异常?您可能需要先获取pds对象的属性。文档的类已经定义,因此属性已经定义。我假设你想知道