Windchill 开发技术-类型属性获取约束 - 获取枚举列表

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);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蜗牛_snail

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值