查询对象的自定义类型WTTypeDefinition

import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import com.ptc.core.meta.type.mgmt.common.TypeDefinitionDefaultView;
import com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinition;
import wt.clients.prodmgmt.WTPartHelper;
import wt.epm.util.EPMSoftTypeServerUtilities;
import wt.fc.PersistenceHelper;
import wt.part.WTPart;
import wt.type.TypeDefinitionReference;
import wt.type.Typed;
import wt.util.WTException;

/**
 *
 * @author 云淡天晴
 * @version 1.0
 * 此例显示了如何获取一个对象的自定义类型
 * 在这里我们以部件为例,当然方法有很多种,此方法只是在众多方法中较为简洁。
 *
 */

public class TypeDemo implements wt.method.RemoteAccess{

 /**
  * 获取部件的自定义类型
  * @param args
  * @throws WTException
  * @throws InvocationTargetException
  * @throws RemoteException
  */
 public static void main(String[] args)  throws WTException, RemoteException, InvocationTargetException {
  // TODO Auto-generated method stub
  WTPart[] part=WTPartHelper.findPartByNumber("0000000021");
  System.out.println(part[0]);
  WTTypeDefinition definition=geTypeDefinition(part[0]);
  System.out.println(definition.getDisplayNameKey());
 }
 
 /**
  * 获取部件的自定义类型并且返回类型对象
  * @param type  此type为WTPart,WTDocument等接口
  * @return WTTypeDefinition
  * @throws WTException
  */
 public static WTTypeDefinition geTypeDefinition(Typed type) throws WTException
 {
  TypeDefinitionReference ref=type.getTypeDefinitionReference();
  TypeDefinitionDefaultView view = EPMSoftTypeServerUtilities.getTypeDefinition(ref);
  WTTypeDefinition definition = (WTTypeDefinition) PersistenceHelper.manager.refresh(view.getObjectID());
  return definition;
 }
}

发布了24 篇原创文章 · 获赞 4 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/wangxiaomei2008/article/details/4990997
今日推荐