【发布时间】:2015-10-05 03:02:42
【问题描述】:
我已经为一个工作项创建了一个 Java 提供的属性,该属性通过查看来自同一/当前工作项的两个其他属性(枚举)来提供一个值集,这两个属性共同形成一个目录路径,java 提供的属性将创建一个目录路径使用嵌套在该目录中的文件名设置的值。如果第一次创建工作项,它会很好,但是在修改工作项时,它无法填充集合,因此可以选择新值。
我发现当谈到这个声明时:
IAttribute currentAttribute= (IAttribute) 句柄;
产生了异常。它无法转换为 IAttribute 句柄,因为来自 workItem.getCustomAttributes() 的返回项在新 Wotk 项和修改后的工作项之间是不同的。
异常信息是:
com.ibm.team.workitem.common.internal.model.impl.AttributeHandleImpl 与 com.ibm.team.workitem.common.model.IAttribute 不兼容
我不确定为什么 com.ibm.team.workitem.common.internal.model.impl.AttributeHandleImpl 用于修改工作项,而 ...AttributeHandle 用于首次创建工作项目。
我不确定如何解决这个问题或将其转换为我需要的 IAttribute。
public class SpecificArtifactType implements IValueSetProvider<String> {
private List<String> list;
public SpecificArtifactType() {
}
@Override
public List<String> getValueSet(IAttribute attribute, IWorkItem workItem,
IWorkItemCommon workItemCommon, IConfiguration configuration,
IProgressMonitor monitor) throws TeamRepositoryException {
String idValue= "";
String deliverableArtifactTypeValue= "";
List<IAttributeHandle> customAttributeHandles= workItem.getCustomAttributes();
/*
* THE DELIVERABLE ARTIFACT AND ID VALUES ARE BOTH USED TO BUILD
* THE DIRECTORY PATH WHICH THIS ATTRIBUTE WILL USE TO POPULATE
* ITS VALUE SET WITH THE ARTIFACTS LOCATED AT THAT LOCATION.
*/
for (IAttributeHandle handle: customAttributeHandles)
{
IAttribute currentAttribute= (IAttribute) handle;
if (currentAttribute.getDisplayName()
.equals(ICustomAttributeDefinitions.ID))
{
idValue= getValue(currentAttribute, monitor, workItemCommon, workItem);
}
else if (currentAttribute.getDisplayName()
.equals(ICustomAttributeDefinitions.DELIVERABLE_ARTIFACT_TYPE))
{
deliverableArtifactTypeValue= getValue(currentAttribute, monitor, workItemCommon, workItem);
}
}
// BUILD THE DIRECTORY PATH
String directory = ICustomAttributeDefinitions.STREAM_ROOT_DIRECTORY
+deliverableArtifactTypeValue +"\\"+ idValue;
File folderPath = new File(directory);
/*
* NEED A VALID PATH TO CONTINUE AND ALSO PREVENT TRYING TO
* LIST CHILD ITEMS IF IT'S A FILE.
*/
if (folderPath.exists() && folderPath.isDirectory())
{
if (folderPath.list().length == 0)
{
directoryEmpty();
return list;
}
list= new ArrayList<String>();
for (String name: folderPath.list())
list.add(name);
}
else invalidDirectoryPath();
return list;
}
/*
* CONVERT VALUE FROM MODEL IDENTIFIER (EG ID.literal.l01) TO ACTUAL VALUE
*/
private String getValue(IAttribute attribute,
IProgressMonitor monitor,
IWorkItemCommon workItemCommon,
IWorkItem workItem) throws TeamRepositoryException
{
IEnumeration<? extends ILiteral> enumeration= workItemCommon
.resolveEnumeration(attribute, monitor);
String value= "";
List<? extends ILiteral> literals= enumeration.getEnumerationLiterals();
for (Iterator<? extends ILiteral> iterator= literals.iterator(); iterator.hasNext(); )
{
ILiteral iLiteral= (ILiteral) iterator.next();
if (iLiteral.getIdentifier2().equals(workItem.getValue(attribute)))
{
value= iLiteral.getName().toString();
break;
}
}
return value;
}
private void directoryEmpty(){
list= new ArrayList<String>(1);
list.add(ICustomAttributeDefinitions.DIRECTORY_EMPTY);
}
private void invalidDirectoryPath()
{
list= new ArrayList<String>(1);
list.add(ICustomAttributeDefinitions.INVALID_DIRECTORY_PATH);
}
}
【问题讨论】: