Windchill 设置大版本的代码

    public static void setVersion(final Versioned versioned, String version)
            throws WTException {
        try {
            if (version == null || version.trim().length() == 0) {
                // If the version ID string is null then the load file did not
                // specify it.
                version = null;
                if (versioned.getVersionInfo() != null) {
                    // If the object already has a VersionInfo object then
                    // assume it is correct
                    // and no further action is needed. Otherwise, make a
                    // default VersionInfo object.
                    return;
                }
            }
            // Get the version series of the object.
            MultilevelSeries mls = null;
            final Mastered master = versioned.getMaster();
            if (master != null) {
                final String masterSeriesName = master.getSeries();
                if (masterSeriesName == null) {
                    if (versioned instanceof WTContained
                            && ((WTContained) versioned).getContainer() != null) {
                        // Retrieve the series based on the OIR in effect for
                        // the container and object type/soft type.
                        mls = VersionControlHelper
                                .getVersionIdentifierSeries(versioned);
                        wt.vc.VersionControlServerHelper.changeSeries(master,
                                mls.getUniqueSeriesName());
                    }
                } else {
                    // Series name was already set in the master, just use it.
                    mls = MultilevelSeries
                            .newMultilevelSeries(masterSeriesName);
                }
            }
            if (mls == null) {
                // Unable to get the series from the master, just use the
                // default series.
                mls = MultilevelSeries.newMultilevelSeries(
                        "wt.vc.VersionIdentifier", version);
            }
            if (version != null) {
                // Set the revision ID value if it was given in the load file.
                mls.setValueWithoutValidating(version.trim());
            }
            // Replace the default VID object (if there is one) with the correct
            // one.
            VersionIdentifier vid = VersionIdentifier.newVersionIdentifier(mls);
            VersionControlServerHelper.setVersionIdentifier(versioned, vid,
                    false /* validateIncreasing */);
        } catch (WTPropertyVetoException e) {
            LoadServerHelper.printMessage("\nsetVersion: " + e.getMessage());
            e.printStackTrace();
            throw new WTException(e);
        } catch (Exception e) {
            throw new WTException(e);
        }
    }

 代码由卡卡大神提供,特记录。

posted @ 2014-06-30 13:43  True.M  阅读(988)  评论(0编辑  收藏  举报