当前位置: 首页>>代码示例>>Java>>正文


Java X500Name.subtreeDepth方法代码示例

本文整理汇总了Java中sun.security.x509.X500Name.subtreeDepth方法的典型用法代码示例。如果您正苦于以下问题:Java X500Name.subtreeDepth方法的具体用法?Java X500Name.subtreeDepth怎么用?Java X500Name.subtreeDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.security.x509.X500Name的用法示例。


在下文中一共展示了X500Name.subtreeDepth方法的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.subtreeDepth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。