當前位置: 首頁>>代碼示例>>Java>>正文


Java X500Name.commonAncestor方法代碼示例

本文整理匯總了Java中sun.security.x509.X500Name.commonAncestor方法的典型用法代碼示例。如果您正苦於以下問題:Java X500Name.commonAncestor方法的具體用法?Java X500Name.commonAncestor怎麽用?Java X500Name.commonAncestor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sun.security.x509.X500Name的用法示例。


在下文中一共展示了X500Name.commonAncestor方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hops

import sun.security.x509.X500Name; //導入方法依賴的package包/類
/**
 * get hop distance of one GeneralName from another in links where
 * the names need not have an ancestor/descendant relationship.
 * For example, the hop distance from ou=D,ou=C,o=B,c=US to
 * ou=F,ou=E,ou=C,o=B,c=US is 3: D->C, C->E, E->F.  The hop distance
 * from ou=C,o=B,c=US to ou=D,ou=C,o=B,c=US is -1: C->D
 *
 * @param base GeneralName
 * @param test GeneralName to be tested against base
 * @param incomparable the value to return if the names are
 *  incomparable
 * @return distance of test name from base measured in hops in the
 *         namespace hierarchy, where 0 means exact match.  Result
 *         is positive if path is some number of up hops followed by
 *         some number of down hops; result is negative if path is
 *         some number of down hops.
 */
static int hops(GeneralNameInterface base, GeneralNameInterface test,
                int incomparable)
{
    int baseRtest = base.constrains(test);
    switch (baseRtest) {
    case GeneralNameInterface.NAME_DIFF_TYPE:
        if (debug != null) {
            debug.println("Builder.hops(): Names are different types");
        }
        return incomparable;
    case GeneralNameInterface.NAME_SAME_TYPE:
        /* base and test are in different subtrees */
        break;
    case GeneralNameInterface.NAME_MATCH:
        /* base matches test */
        return 0;
    case GeneralNameInterface.NAME_WIDENS:
        /* base is ancestor of test */
        return (test.subtreeDepth()-base.subtreeDepth());
    case GeneralNameInterface.NAME_NARROWS:
        /* base is descendant of test */
        return (test.subtreeDepth()-base.subtreeDepth());
    default: // should never occur
        return incomparable;
    }

    /* names are in different subtrees */
    if (base.getType() != GeneralNameInterface.NAME_DIRECTORY) {
        if (debug != null) {
            debug.println("Builder.hops(): hopDistance not implemented " +
                "for this name type");
        }
        return incomparable;
    }
    X500Name baseName = (X500Name)base;
    X500Name testName = (X500Name)test;
    X500Name commonName = baseName.commonAncestor(testName);
    if (commonName == null) {
        if (debug != null) {
            debug.println("Builder.hops(): Names are in different " +
                "namespaces");
        }
        return incomparable;
    } else {
        int commonDistance = commonName.subtreeDepth();
        int baseDistance = baseName.subtreeDepth();
        int testDistance = testName.subtreeDepth();
        return (baseDistance + testDistance - (2 * commonDistance));
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:68,代碼來源:Builder.java


注:本文中的sun.security.x509.X500Name.commonAncestor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。