windchill 12版本(其他相近的版本应该也可以使用的) 依据类型和属性名称获取其约束中设置的全局枚举或局部枚举的方法
包括:全局枚举约束和局部枚举约束
public static Map<String, String> getEnumeratedInfoList(String typeName, String attrName) throws WTException {
    Map<String, String> enumeratedMap = new HashMap<>();
    EnumeratedSet enumeratedSet = getEnumeratedSet(typeName, attrName);
    if (enumeratedSet == null) {
        return enumeratedMap;
    }
    Object[] elements = enumeratedSet.getElements();
    for (Object value : elements) {
        if (value == null) {
            continue;
        }
        EnumerationEntryIdentifier element = enumeratedSet.getElementByKey(value);
        if (element == null) {
            continue;
        }
        DefinitionDescriptor defDescriptor = AttributeDataUtilityHelper.getDefinitionDescriptor(element, Locale.CHINA);
        if (defDescriptor == null) {
            continue;
        }
        enumeratedMap.put(value.toString(), defDescriptor.getDisplay());
    }
    return enumeratedMap;
}
public static EnumeratedSet getEnumeratedSet(String type, String name) throws WTException {
    AttributeTypeSummary summary = getAttributeTypeSummary(type, name, null);
    if (summary != null && isEnumeratedType(summary)) {
        return (EnumeratedSet)summary.getLegalValueSet();
    }
    return null;
}
public static AttributeTypeSummary getAttributeTypeSummary(String type, String name, Locale locale)
            throws WTException {
    try {
        AttributeTypeSummary summary = null;
        if (StringUtils.isBlank(type) || StringUtils.isBlank(name)) {
            return summary;
        }
        // 获取类型的标识符
        TypeIdentifier typeIdentifier = ClientTypedUtility.getTypeIdentifier(type);
        if (typeIdentifier != null) {
            // 获取类型定义
            TypeDefinitionReadView typeDefView = TypeDefinitionServiceHelper.service.getTypeDefView(typeIdentifier);
            if (typeDefView != null) {
                AttributeDefinitionReadView attribute = typeDefView.getAttributeByName(name);
                if (attribute != null) {
                    // 获取AttributeTypeSummary时,必须指定locale,否则AttributeTypeSummary的属性信息不完整
                    PersistableAdapter pAdapter = new PersistableAdapter(type,
                                                                         (locale == null ? getLocale() : locale), new DisplayOperationIdentifier());
                    pAdapter.load(name);
                    summary = pAdapter.getAttributeDescriptor(name);
                }
            }
        }
        return summary;
    } catch (WTException e) {
        throw new WTException(e);
    }
}
                
                  
                  
                  
                  
      
          
                
                
                
                
              
                
                
                
                
                
              
                
                
                    
              
            
                  
					1189
					
被折叠的  条评论
		 为什么被折叠?
		 
		 
		
    
  
    
  
					
					
					


            