Windchill WTPart WTPartMaster 所有零件操作通用類 PartUtil.java

//01. 零件號 返回 WTPart對象
  public static WTPart getWTPartByNumber(String paramString)
    throws WTException
  {
    WTPart localWTPart = null;
    QuerySpec localQuerySpec = null;
    QueryResult localQueryResult = null;
    localQuerySpec = new QuerySpec(WTPartMaster.class);

    SearchCondition localSearchCondition = new SearchCondition(WTPartMaster.class, "number", "LIKE", paramString);
    localQuerySpec.appendSearchCondition(localSearchCondition);
    localQueryResult = PersistenceHelper.manager.find(localQuerySpec);
    if (localQueryResult.hasMoreElements())
    {
      WTPartMaster localWTPartMaster = (WTPartMaster)localQueryResult.nextElement();

      localWTPart = getLatestPartByPartMaster(localWTPartMaster);
    }

    return localWTPart;
  }
//02.零件號  返回 WTPartMaster 對象
  public static WTPartMaster getWTPartMasterByNumber(String paramString)
    throws WTException
  {
    WTPartMaster localWTPartMaster = null;
    QuerySpec localQuerySpec = null;
    QueryResult localQueryResult = null;
    localQuerySpec = new QuerySpec(WTPartMaster.class);

    SearchCondition localSearchCondition = new SearchCondition(WTPartMaster.class, "number", "LIKE", paramString);
    localQuerySpec.appendSearchCondition(localSearchCondition);
    localQueryResult = PersistenceHelper.manager.find(localQuerySpec);
    if (localQueryResult.hasMoreElements())
    {
      localWTPartMaster = (WTPartMaster)localQueryResult.nextElement();
    }

    if (VERBOSE)
      System.out.println(" getWTPartMasterByNumber=" + localWTPartMaster);
    return localWTPartMaster;
  }
//03. 通過WTPartMaster 返回最新版本WTPart對象
  public static WTPart getLatestPartByPartMaster(WTPartMaster paramWTPartMaster)
    throws WTException
  {
    Iterated localIterated = null;
    boolean bool = false;
    LatestConfigSpec localLatestConfigSpec = new LatestConfigSpec();

    QueryResult localQueryResult = ConfigHelper.service.filteredIterationsOf(paramWTPartMaster, localLatestConfigSpec);
    if ((localQueryResult != null) && (localQueryResult.size() <= 0))
    {
      ConfigSpec localConfigSpec = ConfigHelper.service.getDefaultConfigSpecFor(WTPartMaster.class);
      localQueryResult = ConfigHelper.service.filteredIterationsOf(paramWTPartMaster, localConfigSpec);
    }

    while ((localQueryResult.hasMoreElements()) && (!bool))
    {
      localIterated = (Iterated)localQueryResult.nextElement();
      bool = localIterated.isLatestIteration();
    }
    if ((VERBOSE) && (localIterated != null))
      System.out.println("    the latest iteration=" + localIterated.getIdentity());
    return (WTPart)localIterated;
  }
//04.通過WTPartMaster 和 版本    返回 WTPart
  public static WTPart getSpecialPartByMasterAndVersion(WTPartMaster paramWTPartMaster, String paramString)
    throws WTException
  {
    WTPart localWTPart = null;
    String str = "";

    QueryResult localQueryResult = VersionControlHelper.service.allVersionsOf(paramWTPartMaster);
    if ((localQueryResult != null) && (localQueryResult.size() <= 0))
    {
      return null;
    }
    while (localQueryResult.hasMoreElements())
    {
      localWTPart = (WTPart)localQueryResult.nextElement();

      str = VersionControlHelper.getVersionIdentifier(localWTPart).getValue();
      if (str.equalsIgnoreCase(paramString))
        return localWTPart;
    }
    return null;
  }
//05.零件向下所有零件列表
  public static Vector getSubPartListByPart(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector1 = new Vector();

    Vector localVector2 = getFirstLevelSubPartListByPart(paramWTPart, "");

    for (int i = 0; i < localVector2.size(); i++)
    {
      WTPart localWTPart1 = (WTPart)localVector2.elementAt(i);
      if (!ObjectUtil.isPersistableInobjVector(localVector1, localWTPart1)) {
        localVector1.addElement(localWTPart1);
      }
      Vector localVector3 = getSubPartListByPart(localWTPart1);

      for (int j = 0; j < localVector3.size(); j++)
      {
        WTPart localWTPart2 = (WTPart)localVector3.elementAt(j);
        if (ObjectUtil.isPersistableInobjVector(localVector1, localWTPart2))
          continue;
        localVector1.addElement(localWTPart2);
      }
    }

    return localVector1;
  }

  public static Vector getTopPartListByPart(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector1 = new Vector();
    if (paramWTPart == null)
      return null;
    Vector localVector2 = getParentPartListByPart(paramWTPart);
    if ((localVector2 == null) || (localVector2.size() <= 0)) {
      return null;
    }

    for (int i = 0; i < localVector2.size(); i++)
    {
      WTPart localWTPart = (WTPart)localVector2.elementAt(i);

      Vector localVector3 = getParentPartListByPart(localWTPart);
      if ((localVector3 != null) && (localVector3.size() <= 0))
      {
        if (ObjectUtil.isPersistableInobjVector(localVector1, localWTPart))
          continue;
        localVector1.addElement(localWTPart);
      }
      else
      {
        Vector localVector4 = new Vector();
        localVector4 = getTopPartListByPart(localWTPart);
      }

    }

    return localVector1;
  }
//上級零件
  public static Vector getParentPartListByPart(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector = new Vector();
    try
    {
      WTPartMaster localWTPartMaster = (WTPartMaster)paramWTPart.getMaster();
      Object localObject = null;
      QueryResult localQueryResult = StructHelper.service.navigateUsedBy(localWTPartMaster, true);
      while (localQueryResult.hasMoreElements())
      {
        WTPart localWTPart = (WTPart)localQueryResult.nextElement();
        if ((ObjectUtil.isPersistableInobjVector(localVector, localWTPart)) || 
          (localWTPart == null)) continue;
        localVector.addElement(localWTPart);
      }

    }
    catch (WTException localWTException)
    {
      localWTException.printStackTrace();
    }

    return localVector;
  }

  public static String getPartVersionNumber(WTPart paramWTPart)
    throws WTException
  {
    String str = "";
    try
    {
      str = VersionControlHelper.getVersionIdentifier(paramWTPart).getValue();
    }
    catch (VersionControlException localVersionControlException)
    {
      localVersionControlException.printStackTrace();
    }
    return str;
  }
//返回版本
  public static String getPartReversionNumber(WTPart paramWTPart)
    throws WTException
  {
    String str = "";
    try
    {
      str = VersionControlHelper.getIterationIdentifier(paramWTPart).getValue();
    }
    catch (VersionControlException localVersionControlException)
    {
      localVersionControlException.printStackTrace();
    }
    return str;
  }

  public static WTPart getPreVersionPart(WTPart paramWTPart)
    throws WTException
  {
    WTPart localWTPart = null;

    String str1 = getPartReversionNumber(paramWTPart);

    String str2 = getPartVersionNumber(paramWTPart);

    int i = 1;
    if (str2.equals("A")) {
      return null;
    }
    try
    {
      QueryResult localQueryResult = VersionControlHelper.service.allVersionsFrom(paramWTPart);
      if (localQueryResult != null) {
        while ((localQueryResult.hasMoreElements()) && (i != 0))
        {
          localWTPart = (WTPart)localQueryResult.nextElement();
          String str3 = VersionControlHelper.getVersionIdentifier(localWTPart).getValue();

          if (str3.equalsIgnoreCase(str2))
          {
            continue;
          }
          i = 0;
        }
      }
    }
    catch (WTException localWTException)
    {
      localWTException.printStackTrace();
    }
    return localWTPart;
  }

  public static Vector getRelatedDocListByPart(WTPart paramWTPart)
    throws WTException
  {
    if (paramWTPart == null)
      return null;
    Vector localVector = new Vector();

    QueryResult localQueryResult = PartDocHelper.service.getAssociatedDocuments(paramWTPart);

    while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
    {
      WTObject localWTObject = (WTObject)localQueryResult.nextElement();
      if ((localWTObject instanceof WTDocument))
        localVector.addElement(localWTObject);
    }
    return localVector;
  }

  public static double getQuantityOfUsagelink(WTPartUsageLink paramWTPartUsageLink)
    throws WTException
  {
    Quantity localQuantity = paramWTPartUsageLink.getQuantity();
    double d = 0.0D;
    if (localQuantity != null)
      d = localQuantity.getAmount();
    return d;
  }

  public static String getUnitOfUsagelink(WTPartUsageLink paramWTPartUsageLink)
    throws WTException
  {
    Quantity localQuantity = paramWTPartUsageLink.getQuantity();
    String str = "ea";
    if (localQuantity != null)
      str = localQuantity.getUnit().toString();
    return str;
  }

  public static String getContainerNameByPart(WTPart paramWTPart)
    throws WTException
  {
    String str = "";
    if (paramWTPart != null)
    {
      WTContainer localWTContainer = paramWTPart.getContainer();
      str = localWTContainer.getName();
    }

    return str;
  }

  public static WTPartUsageLink createUsageLink(WTPart paramWTPart1, WTPart paramWTPart2, long paramLong, String paramString, double paramDouble, boolean paramBoolean)
    throws WTException
  {
    String str = new Long(paramLong).toString();

    if ((paramWTPart1 == null) || (paramWTPart2 == null)) {
      return null;
    }
    WTPartUsageLink localWTPartUsageLink = null;
    Vector localVector = new Vector();
    localVector = getPartUsageLink(paramWTPart1, paramWTPart2, paramString, paramDouble, str);
    if (localVector.size() > 0)
    {
      if (VERBOSE)
        System.out.println("系統中已存在這樣的link!!!");
      localWTPartUsageLink = (WTPartUsageLink)localVector.elementAt(0);
      return localWTPartUsageLink;
    }

    if (VERBOSE) {
      System.out.println("創建新的link!!!");
    }

    if (paramBoolean == true) {
      paramWTPart1 = (WTPart)VcUtil.checkoutObject(paramWTPart1);
    }

    WTPartMaster localWTPartMaster = (WTPartMaster)paramWTPart2.getMaster();

    localWTPartUsageLink = WTPartUsageLink.newWTPartUsageLink(paramWTPart1, localWTPartMaster);
    try
    {
      localWTPartUsageLink.setLineNumber(LineNumber.newLineNumber(paramLong));

      localWTPartUsageLink.setQuantity(Quantity.newQuantity(paramDouble, QuantityUnit.toQuantityUnit(paramString)));

      if (paramBoolean == true)
      {
        PersistenceHelper.manager.save(localWTPartUsageLink);
        if (VERBOSE) {
          System.out.println("create usageLink.....");
        }

      }
      else
      {
        Transaction localTransaction = new Transaction();
        try
        {
          localTransaction.start();

          PersistenceServerHelper.manager.lock(paramWTPart1, true);

          System.out.println(" Start Directoy Create......");

          PersistenceServerHelper.manager.insert(localWTPartUsageLink);
          System.out.println(" End Directoy Create......");

          localTransaction.commit();
          localTransaction = null;
        }
        finally
        {
          if (localTransaction != null)
            localTransaction.rollback();
        }
      }
    }
    catch (WTPropertyVetoException localWTPropertyVetoException)
    {
      throw new WTException(localWTPropertyVetoException);
    }

    if (paramBoolean == true) {
      VcUtil.checkinObject(paramWTPart1, "");
    }
    return localWTPartUsageLink;
  }

  public static Vector getPartUsageLinkList(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector = new Vector();
    if (paramWTPart == null) {
      return null;
    }

    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartMasters(paramWTPart);
    while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
    {
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)localQueryResult.nextElement();
      localVector.addElement(localWTPartUsageLink);
    }
    return localVector;
  }

  public static Vector getPartUsageLinkListWithOccurence(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector = new Vector();

    if (paramWTPart == null)
      return null;
    WTPartConfigSpec localWTPartConfigSpec = WTPartHelper.service.findWTPartConfigSpec();

    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartsWithAllOccurrences(paramWTPart, localWTPartConfigSpec);

    while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
    {
      Persistable[] arrayOfPersistable = (Persistable[])localQueryResult.nextElement();
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)arrayOfPersistable[0];
      localVector.addElement(localWTPartUsageLink);
    }
    return localVector;
  }

  public static WTPart renamePart(WTPart paramWTPart, String paramString)
    throws WTException
  {
    if (paramWTPart.getName().equals(paramString))
      return paramWTPart;
    Identified localIdentified = null;
    localIdentified = (Identified)paramWTPart.getMaster();
    WTPartMasterIdentity localWTPartMasterIdentity = (WTPartMasterIdentity)localIdentified.getIdentificationObject();
    try
    {
      localWTPartMasterIdentity.setName(paramString);
      localIdentified = IdentityHelper.service.changeIdentity(localIdentified, localWTPartMasterIdentity);
    }
    catch (WTPropertyVetoException localWTPropertyVetoException)
    {
      throw new WTException(localWTPropertyVetoException);
    }
    return paramWTPart;
  }

  public static WTPart revisePart(WTPart paramWTPart, boolean paramBoolean)
    throws WTException
  {
    if (paramWTPart == null) {
      return null;
    }

    paramWTPart = (WTPart)VcUtil.checkinObject(paramWTPart, "");

    WTPart localWTPart = paramWTPart;
    RevisionControlled localRevisionControlled = null;
    try
    {
      localRevisionControlled = (RevisionControlled)VersionControlHelper.service.newVersion(localWTPart);
    }
    catch (WTPropertyVetoException localWTPropertyVetoException)
    {
      throw new WTException(localWTPropertyVetoException);
    }

    localRevisionControlled = (RevisionControlled)PersistenceHelper.manager.save(localRevisionControlled);

    if (paramBoolean) {
      localRevisionControlled = (RevisionControlled)VcUtil.checkoutObject((WTPart)localRevisionControlled);
    }

    return (WTPart)localRevisionControlled;
  }

  public static WTPartDescribeLink getDescribeLinkBetweenPartAndDoc(WTPart paramWTPart, WTDocument paramWTDocument)
    throws WTException
  {
    if ((paramWTPart == null) || (paramWTDocument == null)) {
      return null;
    }

    Vector localVector = new Vector();

    QueryResult localQueryResult = WTPartHelper.service.getDescribedByWTDocuments(paramWTPart, false);
    if ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
    {
      while (localQueryResult.hasMoreElements())
      {
        WTObject localWTObject = (WTObject)localQueryResult.nextElement();
        localVector.addElement(localWTObject);
      }

    }

    if ((localVector != null) && (localVector.size() > 0))
    {
      for (int i = 0; i < localVector.size(); i++)
      {
        WTPartDescribeLink localWTPartDescribeLink = (WTPartDescribeLink)localVector.elementAt(i);
        WTDocument localWTDocument = (WTDocument)localWTPartDescribeLink.getDescribedBy();

        if (PersistenceHelper.isEquivalent(localWTDocument, paramWTDocument) == true)
          return localWTPartDescribeLink;
      }
    }
    return null;
  }

  public static WTPartReferenceLink getReferenceLinkBetweenPartAndDoc(WTPart paramWTPart, WTDocument paramWTDocument)
    throws WTException
  {
    if ((paramWTPart == null) || (paramWTDocument == null)) {
      return null;
    }

    String str1 = paramWTDocument.getNumber();

    QueryResult localQueryResult = PersistenceHelper.manager.navigate(paramWTPart, "references", WTPartReferenceLink.class, false);
    while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
    {
      WTPartReferenceLink localWTPartReferenceLink = (WTPartReferenceLink)localQueryResult.nextElement();

      WTDocumentMaster localWTDocumentMaster = (WTDocumentMaster)localWTPartReferenceLink.getReferences();

      String str2 = localWTDocumentMaster.getNumber();

      if (str2.compareToIgnoreCase(str1) == 0)
        return localWTPartReferenceLink;
    }
    return null;
  }

  public static boolean isEqualOfTwoUsageLink(WTPartUsageLink paramWTPartUsageLink1, WTPartUsageLink paramWTPartUsageLink2, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, boolean paramBoolean5)
    throws WTException
  {
    if ((paramWTPartUsageLink1 == null) || (paramWTPartUsageLink2 == null))
      return false;
    Object localObject1;
    Object localObject2;
    if (paramBoolean1)
    {
      localObject1 = (WTPartMaster)paramWTPartUsageLink1.getObject("uses");

      String str1 = ((WTPartMaster)localObject1).getNumber();

      WTPartMaster localWTPartMaster = (WTPartMaster)paramWTPartUsageLink2.getObject("uses");

      localObject2 = localWTPartMaster.getNumber();

      if (str1.compareToIgnoreCase((String)localObject2) != 0) {
        return false;
      }
    }

    if (paramBoolean2)
    {
      localObject1 = paramWTPartUsageLink1.getLineNumber();
      long l1 = 0L;
      if (localObject1 != null) {
        l1 = ((LineNumber)localObject1).getValue();
      }

      localObject2 = paramWTPartUsageLink2.getLineNumber();
      long l2 = 0L;
      if (localObject2 != null) {
        l2 = ((LineNumber)localObject2).getValue();
      }

      if (l1 != l2) {
        return false;
      }
    }

    if (paramBoolean3)
    {
      localObject1 = paramWTPartUsageLink1.getQuantity().getUnit().toString();

      String str2 = paramWTPartUsageLink2.getQuantity().getUnit().toString();

      System.out.println("需要比較單位");
      System.out.println("qtunit1 =" + (String)localObject1);
      System.out.println("qtunit2 =" + str2);

      if (((String)localObject1).compareToIgnoreCase(str2) != 0) {
        return false;
      }
    }

    if (paramBoolean4)
    {
      double d1 = paramWTPartUsageLink1.getQuantity().getAmount();

      double d2 = paramWTPartUsageLink2.getQuantity().getAmount();

      System.out.println("需要比較數量");
      System.out.println("qtamount1 =" + d1);
      System.out.println("qtamount2 =" + d2);

      if (d1 != d2) {
        return false;
      }
    }

    if (paramBoolean5)
    {
      Vector localVector1 = paramWTPartUsageLink1.getUsesOccurrenceVector();
      if ((localVector1 == null) || (localVector1.size() == 0)) {
        System.out.println("vecOccurence1 is null");
      }
      else
      {
        for (int i = 0; i < localVector1.size(); i++)
        {
          String str3 = ((PartUsesOccurrence)localVector1.elementAt(i)).getUsesName();
          if (VERBOSE) {
            System.out.println("Occurence1:  " + str3);
          }
        }
      }

      Vector localVector2 = paramWTPartUsageLink2.getUsesOccurrenceVector();
      if ((localVector2 == null) || (localVector2.size() == 0)) {
        System.out.println("vecOccurence2 is null");
      }
      else
      {
        for (int j = 0; j < localVector2.size(); j++)
        {
          localObject2 = ((PartUsesOccurrence)localVector2.elementAt(j)).getUsesName();
          if (VERBOSE) {
            System.out.println("Occurence2:  " + (String)localObject2);
          }
        }
      }

      if ((localVector1 == null) && (localVector2 == null)) {
        return true;
      }

      if ((localVector1 != null) && (localVector2 != null))
      {
        return isUsageLinkOccurenceEqual(localVector1, localVector2);
      }

      return false;
    }

    return true;
  }

  public static Vector getAddedLinksOfTwoLinksList(Vector paramVector1, Vector paramVector2, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, boolean paramBoolean5)
    throws WTException
  {
    int i = 0;

    Vector localVector = new Vector();

    if ((paramVector2 == null) || (paramVector2.size() == 0)) {
      return null;
    }

    if ((paramVector1 == null) || (paramVector1.size() == 0)) {
      return paramVector2;
    }

    for (int j = 0; j < paramVector2.size(); j++)
    {
      i = 0;

      WTPartUsageLink localWTPartUsageLink1 = (WTPartUsageLink)paramVector2.elementAt(j);

      for (int k = 0; k < paramVector1.size(); k++)
      {
        WTPartUsageLink localWTPartUsageLink2 = (WTPartUsageLink)paramVector1.elementAt(k);

        if (isEqualOfTwoUsageLink(localWTPartUsageLink1, localWTPartUsageLink2, paramBoolean1, paramBoolean2, paramBoolean3, paramBoolean4, paramBoolean5) != true)
          continue;
        i = 1;
        break;
      }

      if (i == 0) {
        localVector.addElement(localWTPartUsageLink1);
      }
    }

    if ((localVector != null) && (localVector.size() > 0))
      return localVector;
    return null;
  }

  public static Vector getRemovedLinksOfTwoLinksList(Vector paramVector1, Vector paramVector2, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, boolean paramBoolean5)
    throws WTException
  {
    return getAddedLinksOfTwoLinksList(paramVector2, paramVector1, paramBoolean1, paramBoolean2, paramBoolean3, paramBoolean4, paramBoolean5);
  }

  public static Vector getUpdatedLinksOfTwoLinksList(Vector paramVector1, Vector paramVector2, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3)
    throws WTException
  {
    Vector localVector = new Vector();

    if ((paramVector1 == null) || (paramVector1.size() == 0)) {
      return null;
    }

    if ((paramVector2 == null) || (paramVector2.size() == 0)) {
      return null;
    }

    for (int i = 0; i < paramVector2.size(); i++)
    {
      WTPartUsageLink localWTPartUsageLink1 = (WTPartUsageLink)paramVector2.elementAt(i);

      int j = 0;

      for (int k = 0; k < paramVector1.size(); k++)
      {
        WTPartUsageLink localWTPartUsageLink2 = (WTPartUsageLink)paramVector1.elementAt(k);

        if (isEqualOfTwoUsageLink(localWTPartUsageLink2, localWTPartUsageLink1, paramBoolean1, paramBoolean2, false, false, paramBoolean3) != true)
        {
          continue;
        }
        if (isEqualOfTwoUsageLink(localWTPartUsageLink2, localWTPartUsageLink1, false, false, false, true, false) != true)
          continue;
        j = 1;
        break;
      }

      if (j != 0)
        continue;
      localVector.addElement(localWTPartUsageLink1);
    }

    return localVector;
  }

  public static boolean hasUsageLink(WTPart paramWTPart1, WTPart paramWTPart2)
    throws WTException
  {
    int i = 0;
    Vector localVector = getFirstLevelSubPartListByPart(paramWTPart1, "");
    for (int j = 0; j < localVector.size(); j++)
    {
      if (!localVector.elementAt(j).toString().equals(paramWTPart2.toString()))
        continue;
      i = 1;
      break;
    }

    return i;
  }

  public static Vector getPartUsageLink(WTPart paramWTPart1, WTPart paramWTPart2, String paramString, double paramDouble)
    throws WTException
  {
    Vector localVector = new Vector();
    if ((paramWTPart1 == null) || (paramWTPart2 == null)) {
      return null;
    }

    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartMasters(paramWTPart1);
    if ((localQueryResult != null) && (localQueryResult.size() <= 0)) {
      return null;
    }

    while (localQueryResult.hasMoreElements())
    {
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)localQueryResult.nextElement();
      WTPartMaster localWTPartMaster = (WTPartMaster)localWTPartUsageLink.getUses();
      WTPart localWTPart = getLatestPartByPartMaster(localWTPartMaster);

      String str = getUnitOfUsagelink(localWTPartUsageLink);
      double d = getQuantityOfUsagelink(localWTPartUsageLink);

      if ((localWTPart.getNumber().compareToIgnoreCase(paramWTPart2.getNumber()) == 0) && (str.compareToIgnoreCase(paramString) == 0) && (d == paramDouble)) {
        localVector.addElement(localWTPartUsageLink);
      }
    }
    return localVector;
  }

  public static Vector getPartUsageLink(WTPart paramWTPart1, WTPart paramWTPart2, String paramString1, double paramDouble, String paramString2)
    throws WTException
  {
    Vector localVector = new Vector();
    if ((paramWTPart1 == null) || (paramWTPart2 == null)) {
      return null;
    }

    ConfigSpec localConfigSpec = ConfigHelper.service.getDefaultConfigSpecFor(WTPartMaster.class);
    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartsWithAllOccurrences(paramWTPart1, localConfigSpec);
    if ((localQueryResult != null) && (localQueryResult.size() <= 0)) {
      return null;
    }

    while (localQueryResult.hasMoreElements())
    {
      Persistable[] arrayOfPersistable = (Persistable[])localQueryResult.nextElement();
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)arrayOfPersistable[0];

      WTPartMaster localWTPartMaster = (WTPartMaster)localWTPartUsageLink.getUses();
      WTPart localWTPart = getLatestPartByPartMaster(localWTPartMaster);

      String str1 = getUnitOfUsagelink(localWTPartUsageLink);

      double d = getQuantityOfUsagelink(localWTPartUsageLink);

      LineNumber localLineNumber = localWTPartUsageLink.getLineNumber();
      String str2 = "";
      if (localLineNumber != null) {
        str2 = localLineNumber.toString();
      }

      if ((localWTPart.getNumber().compareToIgnoreCase(paramWTPart2.getNumber()) == 0) && (str1.compareToIgnoreCase(paramString1) == 0) && (d == paramDouble) && (str2.compareToIgnoreCase(paramString2) == 0)) {
        localVector.addElement(localWTPartUsageLink);
      }
    }
    return localVector;
  }

  public static Vector getPartUsageLink(WTPart paramWTPart1, WTPart paramWTPart2, String paramString1, double paramDouble, String paramString2, Vector paramVector)
    throws WTException
  {
    Vector localVector1 = new Vector();
    if ((paramWTPart1 == null) || (paramWTPart2 == null)) {
      return null;
    }

    WTPartConfigSpec localWTPartConfigSpec = WTPartHelper.service.findWTPartConfigSpec();
    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartsWithAllOccurrences(paramWTPart1, localWTPartConfigSpec);
    if ((localQueryResult != null) && (localQueryResult.size() <= 0)) {
      return null;
    }

    while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
    {
      Persistable[] arrayOfPersistable = (Persistable[])localQueryResult.nextElement();
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)arrayOfPersistable[0];

      WTPartMaster localWTPartMaster = (WTPartMaster)localWTPartUsageLink.getObject("uses");
      WTPart localWTPart = getLatestPartByPartMaster(localWTPartMaster);

      String str1 = getUnitOfUsagelink(localWTPartUsageLink);
      double d = getQuantityOfUsagelink(localWTPartUsageLink);

      LineNumber localLineNumber = localWTPartUsageLink.getLineNumber();
      String str2 = "";
      if (localLineNumber != null) {
        str2 = localLineNumber.toString();
      }

      Vector localVector2 = localWTPartUsageLink.getUsesOccurrenceVector();
      int i = 0;
      if (((localVector2 != null) && (paramVector == null)) || (
        (localVector2 == null) && (paramVector != null)))
        continue;
      if ((localVector2 == null) && (paramVector == null))
        i = 1;
      if (isUsageLinkOccurenceEqual(paramVector, localVector2)) {
        i = 1;
      }
      if (i == 0) {
        continue;
      }
      if ((localWTPart.getNumber().compareToIgnoreCase(paramWTPart2.getNumber()) == 0) && (str1.compareToIgnoreCase(paramString1) == 0) && (d == paramDouble) && (str2.compareToIgnoreCase(paramString2) == 0));
      localVector1.addElement(localWTPartUsageLink);
    }

    return localVector1;
  }

  public static int removeUsageLink(WTPart paramWTPart1, WTPart paramWTPart2, long paramLong, String paramString, double paramDouble, Vector paramVector, boolean paramBoolean)
    throws WTException
  {
    int i = 0;

    if ((paramWTPart1 == null) || (paramWTPart2 == null)) {
      return 0;
    }

    if (paramBoolean == true) {
      paramWTPart1 = (WTPart)VcUtil.checkoutObject(paramWTPart1);
    }

    ConfigSpec localConfigSpec = ConfigHelper.service.getDefaultConfigSpecFor(WTPartMaster.class);
    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartsWithAllOccurrences(paramWTPart1, localConfigSpec);

    while (localQueryResult.hasMoreElements())
    {
      Persistable[] arrayOfPersistable = (Persistable[])localQueryResult.nextElement();
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)arrayOfPersistable[0];

      WTPartMaster localWTPartMaster = (WTPartMaster)localWTPartUsageLink.getObject("uses");
      String str1 = localWTPartMaster.getNumber();
      String str2 = paramWTPart2.getNumber();

      if (VERBOSE) {
        System.out.println("pmnumber =" + str1 + "childnumber =" + str2);
      }

      if (str1.compareToIgnoreCase(str2) != 0)
        continue;
      if (VERBOSE)
        System.out.println("removedUsageLinkCount =" + i);
      Object localObject1;
      if (paramLong > 0L)
      {
        localObject1 = localWTPartUsageLink.getLineNumber();
        long l = 0L;
        if (localObject1 != null) {
          l = ((LineNumber)localObject1).getValue();
        }

        if (l != paramLong)
        {
          continue;
        }
      }
      if (paramString.length() != 0)
      {
        localObject1 = localWTPartUsageLink.getQuantity().getUnit().toString();

        if (((String)localObject1).compareToIgnoreCase(paramString) != 0)
        {
          continue;
        }
      }
      if (paramDouble > 0.0D)
      {
        double d = localWTPartUsageLink.getQuantity().getAmount();
        if (d != paramDouble)
          continue;
      }
      Object localObject2;
      if ((paramVector != null) && (paramVector.size() > 0))
      {
        localObject2 = localWTPartUsageLink.getUsesOccurrenceVector();
        if (!isUsageLinkOccurenceEqual(paramVector, (Vector)localObject2)) {
          continue;
        }

      }
      else if (VERBOSE) {
        System.out.println("occurrence is null!");
      }

      if (paramBoolean == true)
      {
        PersistenceHelper.manager.delete(localWTPartUsageLink);
      }
      else
      {
        localObject2 = new Transaction();
        try
        {
          ((Transaction)localObject2).start();

          PersistenceServerHelper.manager.lock(paramWTPart1, true);

          PersistenceServerHelper.manager.remove(localWTPartUsageLink);

          ((Transaction)localObject2).commit();
          localObject2 = null;
        }
        finally
        {
          if (localObject2 != null) {
            ((Transaction)localObject2).rollback();
          }
        }
      }
      i++;
    }

    if (paramBoolean == true) {
      VcUtil.checkinObject(paramWTPart1, "");
    }
    return i;
  }

  public static void outputWTPartUsageLinkList(Vector paramVector)
    throws WTException
  {
    if ((paramVector == null) || (paramVector.size() == 0)) {
      return;
    }

    System.out.println("開始輸出相關信息...");
    for (int i = 0; i < paramVector.size(); i++)
    {
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)paramVector.elementAt(i);

      System.out.println("WTPartUsageLink" + (i + 1));

      outputWTPartUsageLinkinfo(localWTPartUsageLink);
    }
  }

  public static WTPart createPart(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, Folder paramFolder, WTContainer paramWTContainer)
    throws WTException
  {
    WTPart localWTPart = null;
    localWTPart = WTPart.newWTPart();
    WTContainerRef localWTContainerRef = WTContainerRef.newWTContainerRef(paramWTContainer);

    String str = EnterpriseHelper.getNumber(localWTPart, localWTContainerRef);

    localWTPart = initializeWTPart(localWTPart, str, paramString1, paramString2, paramString3, paramString4, paramString5, paramFolder, paramWTContainer, null);

    localWTPart = (WTPart)PersistenceHelper.manager.store(localWTPart);

    localWTPart = (WTPart)WorkflowUtil.setLifeCycleState(localWTPart, paramString6);
    return localWTPart;
  }

  public static WTPart createPart(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, String paramString7, Folder paramFolder, WTContainer paramWTContainer)
    throws WTException
  {
    WTPart localWTPart = null;
    localWTPart = WTPart.newWTPart();

    localWTPart = initializeWTPart(localWTPart, paramString1, paramString2, paramString3, paramString4, paramString5, paramString6, paramFolder, paramWTContainer, null);

    localWTPart = (WTPart)PersistenceHelper.manager.store(localWTPart);

    localWTPart = (WTPart)WorkflowUtil.setLifeCycleState(localWTPart, paramString7);
    return localWTPart;
  }

  private static WTPart initializeWTPart(WTPart paramWTPart, String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, Folder paramFolder, WTContainer paramWTContainer, WTOrganization paramWTOrganization)
    throws WTException
  {
    PartType localPartType = null;
    ViewReference localViewReference = null;
    QuantityUnit localQuantityUnit = null;
    Source localSource = null;
    try
    {
      localPartType = PartType.toPartType(paramString3);
      localQuantityUnit = QuantityUnit.toQuantityUnit(paramString6);
      localSource = Source.toSource(paramString4);
      View localView = ViewHelper.service.getView(paramString5);
      localViewReference = ViewReference.newViewReference(localView);

      paramWTPart.setName(paramString2);
      paramWTPart.setNumber(paramString1);
      paramWTPart.setSource(localSource);
      paramWTPart.setView(localViewReference);
      paramWTPart.setDefaultUnit(localQuantityUnit);
      paramWTPart.setPartType(localPartType);
      paramWTPart.setContainer(paramWTContainer);
      if (paramFolder != null)
      {
        FolderHelper.assignLocation(paramWTPart, paramFolder);
      }
      if (paramWTOrganization != null)
        paramWTPart.setOrganization(paramWTOrganization);
    }
    catch (Exception localException)
    {
      throw new WTException(localException.getLocalizedMessage());
    }
    return paramWTPart;
  }

  public static boolean isPartExist(String paramString)
    throws WTException
  {
    WTPart localWTPart = null;
    localWTPart = getWTPartByNumber(paramString);

    return localWTPart != null;
  }

  public static boolean isEqual(Vector paramVector1, Vector paramVector2)
  {
    if (paramVector1.size() != paramVector2.size()) {
      return false;
    }

    for (int i = 0; i < paramVector1.size(); i++)
    {
      if (paramVector1.elementAt(i).toString() != paramVector2.elementAt(i).toString()) {
        return false;
      }
    }
    return true;
  }

  public static void outputWTPartUsageLinkinfo(WTPartUsageLink paramWTPartUsageLink)
    throws WTException
  {
    if (paramWTPartUsageLink == null) {
      return;
    }

    WTPart localWTPart = (WTPart)paramWTPartUsageLink.getObject("usedBy");
    System.out.println("\tpartparent number: " + localWTPart.getNumber());

    WTPartMaster localWTPartMaster = (WTPartMaster)paramWTPartUsageLink.getObject("uses");
    System.out.println("\tpgetQuantityOfUsagelinkartmaster number: " + localWTPartMaster.getNumber());

    LineNumber localLineNumber = paramWTPartUsageLink.getLineNumber();
    long l = 0L;
    if (localLineNumber != null) {
      l = localLineNumber.getValue();
    }
    System.out.println("\tlinenumber: " + l);

    String str1 = paramWTPartUsageLink.getQuantity().getUnit().toString();
    System.out.println("\tunit: " + str1);

    double d = paramWTPartUsageLink.getQuantity().getAmount();
    System.out.println("\tamount: " + d);

    Vector localVector = paramWTPartUsageLink.getUsesOccurrenceVector();
    if ((localVector == null) || (localVector.size() == 0)) {
      System.out.println("\tvecOccurence is null");
    }
    else
    {
      for (int i = 0; i < localVector.size(); i++)
      {
        String str2 = ((PartUsesOccurrence)localVector.elementAt(i)).getUsesName();
        System.out.println("\tOccurence:  " + str2);
      }
    }
  }

  public static boolean isUsageLinkOccurenceEqual(Vector paramVector1, Vector paramVector2)
  {
    Vector localVector1 = new Vector();
    Vector localVector2 = new Vector();

    if (paramVector1.size() != paramVector2.size()) {
      return false;
    }

    for (int i = 0; i < paramVector1.size(); i++)
    {
      PartUsesOccurrence localPartUsesOccurrence1 = (PartUsesOccurrence)paramVector1.elementAt(i);
      localVector1.add(localPartUsesOccurrence1.getUsesName());

      PartUsesOccurrence localPartUsesOccurrence2 = (PartUsesOccurrence)paramVector2.elementAt(i);
      String str = localPartUsesOccurrence2.getUsesName();

      if (str == null)
      {
        if (VERBOSE)
          System.out.println("str is null...");
        str = "";
      }
      localVector2.add(str);
    }

    localVector1 = StringUtil.sortStringVector(localVector1, true);

    localVector2 = StringUtil.sortStringVector(localVector2, true);

    return isVectorString(localVector1, localVector2);
  }

  public static boolean isVectorString(Vector paramVector1, Vector paramVector2)
  {
    if (paramVector1.size() == paramVector2.size())
    {
      for (int i = 0; i < paramVector1.size(); i++)
      {
        String str1 = (String)paramVector1.elementAt(i);
        String str2 = (String)paramVector2.elementAt(i);

        if (str1.compareTo(str2) != 0) {
          return false;
        }
      }
    }
    return false;
    return true;
  }

  public static Vector getRelatedDocListByPart(WTPart paramWTPart, boolean paramBoolean1, boolean paramBoolean2)
    throws WTException
  {
    if (paramWTPart == null) {
      return null;
    }
    Vector localVector = new Vector();
    QueryResult localQueryResult;
    Object localObject;
    if (paramBoolean1 == true)
    {
      localQueryResult = WTPartHelper.service.getDescribedByWTDocuments(paramWTPart);
      while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
      {
        localObject = (WTObject)localQueryResult.nextElement();
        if ((localObject instanceof WTDocument)) {
          localVector.addElement(localObject);
        }
      }
    }
    if (paramBoolean2 == true)
    {
      localQueryResult = PersistenceHelper.manager.navigate(paramWTPart, "references", WTPartReferenceLink.class, false);
      while ((localQueryResult != null) && (localQueryResult.hasMoreElements()))
      {
        localObject = (WTPartReferenceLink)localQueryResult.nextElement();

        WTDocumentMaster localWTDocumentMaster = (WTDocumentMaster)((WTPartReferenceLink)localObject).getReferences();

        WTDocument localWTDocument = DocUtil.getLatestWTDocument(localWTDocumentMaster);
        localVector.addElement(localWTDocument);
      }
    }
    return (Vector)localVector;
  }

  public static WTPart getWTPartByNumberAndView(String paramString1, String paramString2)
    throws WTException
  {
    WTPartMaster localWTPartMaster = getWTPartMasterByNumber(paramString1);
    if (localWTPartMaster == null) {
      return null;
    }
    return getWTPartByMasterAndView(localWTPartMaster, paramString2);
  }

  public static WTPart getWTPartByMasterAndView(WTPartMaster paramWTPartMaster, String paramString)
    throws WTException
  {
    Object localObject = null;
    View localView = ViewHelper.service.getView(paramString);
    WTPartConfigSpec localWTPartConfigSpec = WTPartHelper.service.findWTPartConfigSpec();
    WTPartStandardConfigSpec localWTPartStandardConfigSpec = localWTPartConfigSpec.getStandard();
    try
    {
      localWTPartStandardConfigSpec.setView(localView);
    }
    catch (WTPropertyVetoException localWTPropertyVetoException)
    {
      throw new WTException(localWTPropertyVetoException);
    }
    QueryResult localQueryResult = ConfigHelper.service.filteredIterationsOf(paramWTPartMaster, localWTPartStandardConfigSpec);
    while (localQueryResult.hasMoreElements())
    {
      WTPart localWTPart = (WTPart)localQueryResult.nextElement();
      ViewReference localViewReference = localWTPart.getView();
      String str = "";
      if (localViewReference != null)
        str = localViewReference.getName();
      if ((str.length() == 0) || (!str.equals(paramString)) || 
        (!localWTPart.isLatestIteration()))
        continue;
      localObject = localWTPart;
    }

    if (localObject == null)
      localObject = getLatestPartByPartMaster(paramWTPartMaster);
    return (WTPart)localObject;
  }

  public static EPMDocument getBuiltEPMDocByPart(WTPart paramWTPart)
    throws WTException
  {
    QueryResult localQueryResult = PersistenceHelper.manager.navigate(paramWTPart, "buildSource", EPMBuildRule.class, true);
    Persistable localPersistable;
    EPMDocument localEPMDocument;
    while (localQueryResult.hasMoreElements())
    {
      localPersistable = (Persistable)localQueryResult.nextElement();
      if (!(localPersistable instanceof EPMDocument))
        continue;
      localEPMDocument = (EPMDocument)localPersistable;
      return localEPMDocument;
    }

    localQueryResult = PersistenceHelper.manager.navigate(paramWTPart, "builtBy", EPMBuildHistory.class, true);
    while (localQueryResult.hasMoreElements())
    {
      localPersistable = (Persistable)localQueryResult.nextElement();
      if (!(localPersistable instanceof EPMDocument))
        continue;
      localEPMDocument = (EPMDocument)localPersistable;
      return localEPMDocument;
    }

    return null;
  }

  public static Vector getRelatedCADListByPart(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector = new Vector();
    if (paramWTPart == null)
    {
      return localVector;
    }

    QueryResult localQueryResult = WTPartHelper.service.getDescribedByDocuments(paramWTPart, true);
    while (localQueryResult.hasMoreElements())
    {
      Object localObject = localQueryResult.nextElement();
      if (!(localObject instanceof EPMDocument))
        continue;
      EPMDocument localEPMDocument1 = (EPMDocument)localObject;
      if (localEPMDocument1 == null)
        continue;
      EPMDocument localEPMDocument2 = EPMUtil.getLatestEPMDocByMaster((EPMDocumentMaster)localEPMDocument1.getMaster());
      localVector.add(localEPMDocument2);
    }

    return localVector;
  }

  public static Vector getActiveCADandReferenceDoc(WTPart paramWTPart, boolean paramBoolean)
    throws WTException
  {
    Vector localVector = new Vector();
    EPMDocument localEPMDocument1 = getBuiltEPMDocByPart(paramWTPart);
    if (localEPMDocument1 != null)
    {
      if (!ObjectUtil.isPersistableInobjVector(localVector, localEPMDocument1))
        localVector.add(localEPMDocument1);
      if (paramBoolean)
      {
        QuerySpec localQuerySpec = new QuerySpec(EPMReferenceLink.class);
        QueryResult localQueryResult = EPMStructureHelper.service.navigateReferencedBy((EPMDocumentMaster)localEPMDocument1.getMaster(), localQuerySpec, true);
        while (localQueryResult.hasMoreElements())
        {
          EPMDocument localEPMDocument2 = (EPMDocument)localQueryResult.nextElement();
          if ((!ObjectUtil.isPersistableInobjVector(localVector, localEPMDocument2)) && (localEPMDocument2.isLatestIteration()))
            localVector.add(localEPMDocument2);
        }
      }
    }
    return localVector;
  }

  public static Vector getPassiveCADandReferenceDoc(WTPart paramWTPart, boolean paramBoolean)
    throws WTException
  {
    Vector localVector = new Vector();
    QueryResult localQueryResult1 = PartDocHelper.service.getAssociatedDocuments(paramWTPart);
    WTObject localWTObject = null;
    EPMDocument localEPMDocument1 = null;
    while (localQueryResult1.hasMoreElements())
    {
      localWTObject = (WTObject)localQueryResult1.nextElement();
      if (!(localWTObject instanceof IteratedDescribeLink))
        continue;
      localEPMDocument1 = (EPMDocument)((IteratedDescribeLink)localWTObject).getDescribedBy();
      if (!ObjectUtil.isPersistableInobjVector(localVector, localEPMDocument1))
        localVector.add(localEPMDocument1);
      if (!paramBoolean)
        continue;
      QuerySpec localQuerySpec = new QuerySpec(EPMReferenceLink.class);
      QueryResult localQueryResult2 = EPMStructureHelper.service.navigateReferencedBy((EPMDocumentMaster)localEPMDocument1.getMaster(), localQuerySpec, true);
      while (localQueryResult2.hasMoreElements())
      {
        EPMDocument localEPMDocument2 = (EPMDocument)localQueryResult2.nextElement();
        if ((!ObjectUtil.isPersistableInobjVector(localVector, localEPMDocument2)) && (localEPMDocument2.isLatestIteration())) {
          localVector.add(localEPMDocument2);
        }
      }
    }

    return localVector;
  }

  public static WTPart getPartByActiveCADDocument(EPMDocument paramEPMDocument)
    throws WTException
  {
    WTPart localWTPart = null;
    QueryResult localQueryResult = PersistenceHelper.manager.navigate(paramEPMDocument, "buildTarget", EPMBuildRule.class, true);
    if ((localQueryResult != null) && (localQueryResult.size() > 0));
    while (localQueryResult.hasMoreElements())
    {
      Persistable localPersistable = (Persistable)localQueryResult.nextElement();
      if (!(localPersistable instanceof WTPart))
        continue;
      localWTPart = (WTPart)localPersistable;

      return getLatestPartByPartMaster((WTPartMaster)localWTPart.getMaster());

      localQueryResult = PersistenceHelper.manager.navigate(paramEPMDocument, "built", EPMBuildHistory.class, true);
      while (localQueryResult.hasMoreElements())
      {
        localPersistable = (Persistable)localQueryResult.nextElement();
        if (!(localPersistable instanceof WTPart))
          continue;
        localWTPart = (WTPart)localPersistable;
        return localWTPart;
      }
    }

    return localWTPart;
  }

  public static void removeFromWorkspace(WTPart paramWTPart)
    throws QueryException, WTException
  {
    String str = paramWTPart.getNumber();
    EPMWorkspace localEPMWorkspace = null;
    QuerySpec localQuerySpec = new QuerySpec(EPMWorkspace.class);
    QueryResult localQueryResult = PersistenceHelper.manager.find(localQuerySpec);
    WTUser localWTUser = (WTUser)SessionHelper.manager.getPrincipalReference().getObject();
    WTPrincipal localWTPrincipal = SessionHelper.manager.getPrincipal();
    SessionHelper.manager.setAdministrator();
    while (localQueryResult.hasMoreElements())
    {
      WTArrayList localWTArrayList = new WTArrayList();
      localEPMWorkspace = (EPMWorkspace)localQueryResult.nextElement();
      WTSet localWTSet = EPMWorkspaceHelper.manager.getObjectsInWorkspace(localEPMWorkspace, WTPart.class);
      Iterator localIterator = localWTSet.persistableIterator();
      while (localIterator.hasNext())
      {
        WTPart localWTPart = (WTPart)localIterator.next();
        if (localWTPart.getNumber().equals(str))
          localWTArrayList.add(localWTPart);
      }
      EPMWorkspaceHelper.manager.removeFromWorkspace(localEPMWorkspace, localWTArrayList);
    }
    SessionHelper.manager.setPrincipal(localWTPrincipal.getName());
  }

  public static Vector getFirstLevelSubPartListByPart(WTPart paramWTPart, String paramString)
    throws WTException
  {
    Vector localVector = new Vector();

    Object localObject1 = new LatestConfigSpec();
    Object localObject3;
    Object localObject4;
    if ((paramString != null) && (paramString.length() > 0))
    {
      localObject2 = ViewHelper.service.getView(paramString);
      localObject3 = WTPartHelper.service.findWTPartConfigSpec();
      localObject4 = ((WTPartConfigSpec)localObject3).getStandard();
      try
      {
        ((WTPartStandardConfigSpec)localObject4).setView((View)localObject2);
      }
      catch (WTPropertyVetoException localWTPropertyVetoException)
      {
        throw new WTException(localWTPropertyVetoException);
      }
      localObject1 = localObject4;
    }
    Object localObject2 = StructHelper.service.navigateUsesToIteration(paramWTPart, WTPartUsageLink.class, false, (ConfigSpec)localObject1);
    while ((localObject2 != null) && (((QueryResult)localObject2).hasMoreElements()))
    {
      localObject3 = (Persistable[])((QueryResult)localObject2).nextElement();

      localObject4 = (WTPartUsageLink)localObject3[0];

      Object localObject5 = localObject3[1];
      WTPart localWTPart = null;
      if ((localObject5 instanceof WTPartMaster))
      {
        localWTPart = getLatestPartByPartMaster((WTPartMaster)localObject5);
      }
      else
        localWTPart = (WTPart)localObject5;
      if ((localWTPart != null) && (!ObjectUtil.isPersistableInobjVector(localVector, localWTPart)))
        localVector.add(localWTPart);
    }
    return (Vector)(Vector)(Vector)(Vector)localVector;
  }

  public static Vector getFirstLevelSubPartListByPart(WTPart paramWTPart)
    throws WTException
  {
    Vector localVector = new Vector();

    Object localObject1 = new LatestConfigSpec();
    String str = "";
    ViewReference localViewReference = paramWTPart.getView();
    if (localViewReference != null)
      str = localViewReference.getName();
    Object localObject3;
    Object localObject4;
    if ((str != null) && (str.length() > 0))
    {
      localObject2 = ViewHelper.service.getView(str);
      localObject3 = WTPartHelper.service.findWTPartConfigSpec();
      localObject4 = ((WTPartConfigSpec)localObject3).getStandard();
      try
      {
        ((WTPartStandardConfigSpec)localObject4).setView((View)localObject2);
      }
      catch (WTPropertyVetoException localWTPropertyVetoException)
      {
        throw new WTException(localWTPropertyVetoException);
      }
      localObject1 = localObject4;
    }
    Object localObject2 = StructHelper.service.navigateUsesToIteration(paramWTPart, WTPartUsageLink.class, false, (ConfigSpec)localObject1);
    while ((localObject2 != null) && (((QueryResult)localObject2).hasMoreElements()))
    {
      localObject3 = (Persistable[])((QueryResult)localObject2).nextElement();

      localObject4 = (WTPartUsageLink)localObject3[0];

      Object localObject5 = localObject3[1];
      WTPart localWTPart = null;
      if ((localObject5 instanceof WTPartMaster))
      {
        localWTPart = getLatestPartByPartMaster((WTPartMaster)localObject5);
      }
      else
        localWTPart = (WTPart)localObject5;
      if ((localWTPart != null) && (!ObjectUtil.isPersistableInobjVector(localVector, localWTPart)))
        localVector.add(localWTPart);
    }
    return (Vector)(Vector)(Vector)(Vector)localVector;
  }

  public static Vector getPartUsageLink(WTPart paramWTPart1, WTPart paramWTPart2)
    throws WTException
  {
    Vector localVector = new Vector();
    if ((paramWTPart1 == null) || (paramWTPart2 == null)) {
      return null;
    }
    QueryResult localQueryResult = WTPartHelper.service.getUsesWTPartMasters(paramWTPart1);
    if ((localQueryResult != null) && (localQueryResult.size() <= 0)) {
      return null;
    }

    while (localQueryResult.hasMoreElements())
    {
      WTPartUsageLink localWTPartUsageLink = (WTPartUsageLink)localQueryResult.nextElement();
      WTPartMaster localWTPartMaster = (WTPartMaster)localWTPartUsageLink.getUses();
      WTPart localWTPart = getLatestPartByPartMaster(localWTPartMaster);
      if (localWTPart.getNumber().equalsIgnoreCase(paramWTPart2.getNumber())) {
        localVector.addElement(localWTPartUsageLink);
      }
    }
    return localVector;
  }

  public static boolean isLatestVersion(WTPart paramWTPart)
    throws WTException
  {
    ConfigSpec localConfigSpec = ConfigHelper.service.getConfigSpecFor(paramWTPart);
    QueryResult localQueryResult = ConfigHelper.service.filteredIterationsOf(paramWTPart.getMaster(), localConfigSpec);
    Iterated localIterated = (Iterated)localQueryResult.nextElement();

    return PersistenceHelper.isEquivalent(localIterated, paramWTPart);
  }

  public static QueryResult getSubPartsAndUsageLinks(WTPart paramWTPart)
    throws WTException
  {
    LatestConfigSpec localLatestConfigSpec = new LatestConfigSpec();
    QueryResult localQueryResult = WTPartHelper.service.getUsesWTParts(paramWTPart, localLatestConfigSpec);
    return localQueryResult;
  }

  public static QueryResult getSubPartsAndUsageLinks(WTPart paramWTPart, String paramString)
    throws WTException
  {
    View localView = null;
    if ((paramString != null) && (paramString.length() > 0))
      localView = ViewHelper.service.getView(paramString);
    WTPartConfigSpec localWTPartConfigSpec = WTPartHelper.service.findWTPartConfigSpec();
    WTPartStandardConfigSpec localWTPartStandardConfigSpec = localWTPartConfigSpec.getStandard();
    try
    {
      localWTPartStandardConfigSpec.setView(localView);
    }
    catch (WTPropertyVetoException localWTPropertyVetoException)
    {
      throw new WTException(localWTPropertyVetoException);
    }
    QueryResult localQueryResult = WTPartHelper.service.getUsesWTParts(paramWTPart, localWTPartStandardConfigSpec);
    return localQueryResult;
  }

  public static Hashtable getSubPartListByPart(WTPart paramWTPart, String paramString, Hashtable paramHashtable)
    throws WTException
  {
    Vector localVector = getFirstLevelSubPartListByPart(paramWTPart, paramString);

    for (int i = 0; i < localVector.size(); i++)
    {
      WTPart localWTPart = (WTPart)localVector.elementAt(i);
      paramHashtable.put(localWTPart.getNumber(), localWTPart);

      paramHashtable = getSubPartListByPart(localWTPart, paramString, paramHashtable);
    }
    return paramHashtable;
  }

  public static Vector getSubPartListByPart(WTPart paramWTPart, String paramString)
    throws WTException
  {
    Hashtable localHashtable = new Hashtable();
    localHashtable = getSubPartListByPart(paramWTPart, paramString, localHashtable);
    Collection localCollection = localHashtable.values();
    return new Vector(localCollection);
  }

  public static void main(String[] paramArrayOfString)
    throws WTException
  {
    ReferenceFactory localReferenceFactory = new ReferenceFactory();
    WTPart localWTPart = (WTPart)localReferenceFactory.getReference("wt.part.WTProduct:80492").getObject();
    System.out.println("part = " + localWTPart.getIdentity());

    Vector localVector = getRelatedDocListByPart(localWTPart);
    System.out.println("docVec = " + localVector.size());

    System.exit(0);
  }

  static
  {
    try
    {
      VERBOSE = WTProperties.getLocalProperties().getProperty("ext.com.part.verbose", false);
    }
    catch (Throwable localThrowable)
    {
      throw new ExceptionInInitializerError(localThrowable);
    }
  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章