• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TypeDefinition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.opendaylight.yangtools.yang.model.api.TypeDefinition的典型用法代码示例。如果您正苦于以下问题:Java TypeDefinition类的具体用法?Java TypeDefinition怎么用?Java TypeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeDefinition类属于org.opendaylight.yangtools.yang.model.api包,在下文中一共展示了TypeDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: deserialize

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
/**
 * De-serializes a string.
 * @param typeDefinition - Type Definition
 * @param input - Input
 * @return De-serialized JSON string
 */
private Object deserialize(final TypeDefinition<?> typeDefinition, String input) {
    TypeDefinition<?> type = resolveBaseTypeFrom(typeDefinition);

    try {
        if ((type instanceof IdentityrefTypeDefinition) || (type instanceof InstanceIdentifierTypeDefinition)) {
            return null;
        } else {
            final TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> typeAwarecodec = TypeDefinitionAwareCodec
                    .from(type);
            if (typeAwarecodec != null) {
                return typeAwarecodec.deserialize(input);
            } else {
                return null;
            }
        }
    } catch (final ClassCastException e) {
        LOG.error(
                "ClassCastException was thrown when codec is invoked with parameter " + String.valueOf(input),
                e);
        return null;
    }
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:29,代码来源:NameResolver.java


示例2: getOpenType

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Override
public OpenType<?> getOpenType() {
    final TypeDefinition<?> baseTypeDefinition = getBaseType(this.typeProviderWrapper, this.typeDefinition);
    final Type baseType = this.typeProviderWrapper.getType(baseTypeDefinition, baseTypeDefinition);

    if (isArray()) {
        return getArrayType();
    } else if (isEnum()) {
        return getEnumType(baseTypeDefinition);
    } else if (isUnion()) {
        return getCompositeTypeForUnion(baseTypeDefinition);
    } else if (isDerivedType(baseType, getType())) {
        return getCompositeType(baseType, baseTypeDefinition);
    } else if (isIdentityRef()) {
        return getCompositeTypeForIdentity();
    }

    return getSimpleType(getType());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:JavaAttribute.java


示例3: getCompositeType

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private OpenType<?> getCompositeType(final Type baseType, final TypeDefinition<?> baseTypeDefinition) {

        final SimpleType<?> innerItemType = SimpleTypeResolver.getSimpleType(baseType);
        final String innerItemName = this.typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);

        final String[] itemNames = new String[]{innerItemName};
        final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();

        final OpenType<?>[] itemTypes = new OpenType[]{innerItemType};
        try {
            return new CompositeType(getUpperCaseCammelCase(), description, itemNames, itemNames, itemTypes);
        } catch (final OpenDataException e) {
            throw new RuntimeException("Unable to create " + CompositeType.class + " with inner element of type "
                    + itemTypes, e);
        }
    }
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:JavaAttribute.java


示例4: serialize

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Override
@SuppressWarnings("checkstyle:illegalCatch")
public final String serialize(final Object data) {
    for (final TypeDefinition<?> type : typeDefinition.getTypes()) {
        Codec<String, Object> codec = codecFor(type);
        if (codec == null) {
            LOG.debug("no codec found for {}", type);
            continue;
        }
        try {
            return codec.serialize(data);
        } catch (final Exception e) {
            LOG.debug("Data {} did not match for {}", data, type, e);
            // invalid - try the next union type.
        }
    }
    throw new IllegalArgumentException("Invalid data \"" + data + "\" for union type.");
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:19,代码来源:AbstractStringUnionCodec.java


示例5: createComplexUnion

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private T createComplexUnion(final TypedDataSchemaNode schema, final UnionTypeDefinition union) {
    final List<TypeDefinition<?>> types = union.getTypes();
    final List<T> codecs = new ArrayList<>(types.size());

    for (TypeDefinition<?> type : types) {
        T codec = cache.lookupSimple(type);
        if (codec == null) {
            codec = getSimpleCodecFor(type);
            if (codec == null) {
                codec = createComplexCodecFor(schema, type);
            }
        }

        codecs.add(verifyNotNull(codec, "Schema %s subtype %s has no codec", schema, type));
    }

    return unionCodec(union, codecs);
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:19,代码来源:AbstractCodecFactory.java


示例6: findSchemaNodeWithLeafrefType

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private LeafSchemaNode findSchemaNodeWithLeafrefType(final DataNodeContainer module, final String nodeName) {
    for (final DataSchemaNode childNode : module.getChildNodes()) {
        if (childNode instanceof DataNodeContainer) {
            LeafSchemaNode leafrefFromRecursion = findSchemaNodeWithLeafrefType((DataNodeContainer) childNode,
                    nodeName);
            if (leafrefFromRecursion != null) {
                return leafrefFromRecursion;
            }
        } else if (childNode.getQName().getLocalName().equals(nodeName) && childNode instanceof LeafSchemaNode) {
            final TypeDefinition<?> leafSchemaNodeType = ((LeafSchemaNode) childNode).getType();
            if (leafSchemaNodeType instanceof LeafrefTypeDefinition) {
                return (LeafSchemaNode) childNode;
            }
        }
    }
    return null;
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:18,代码来源:XmlStreamUtilsTest.java


示例7: testOrderingTypedef

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Test
public void testOrderingTypedef() throws Exception {
    final Set<TypeDefinition<?>> typedefs = bar.getTypeDefinitions();
    final String[] expectedOrder = { "int32-ext1", "int32-ext2", "string-ext1", "string-ext2", "string-ext3",
        "string-ext4", "invalid-string-pattern", "multiple-pattern-string", "my-decimal-type", "my-union",
        "my-union-ext", "nested-union2"
    };
    final String[] actualOrder = new String[typedefs.size()];

    int offset = 0;
    for (final TypeDefinition<?> type : typedefs) {
        actualOrder[offset] = type.getQName().getLocalName();
        offset++;
    }
    assertArrayEquals(expectedOrder, actualOrder);
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:17,代码来源:OrderingTest.java


示例8: testAddedByUsesLeafTypeQName

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Test
public void testAddedByUsesLeafTypeQName() throws Exception {
    final SchemaContext loadModules = TestUtils.loadModules(getClass().getResource("/added-by-uses-leaf-test")
            .toURI());
    assertEquals(2, loadModules.getModules().size());
    foo = TestUtils.findModule(loadModules, "foo").get();
    final Module imp = TestUtils.findModule(loadModules, "import-module").get();

    final LeafSchemaNode leaf = (LeafSchemaNode) ((ContainerSchemaNode) foo.getDataChildByName(QName.create(
            foo.getQNameModule(), "my-container")))
            .getDataChildByName(QName.create(foo.getQNameModule(), "my-leaf"));

    TypeDefinition<?> impType = null;
    final Set<TypeDefinition<?>> typeDefinitions = imp.getTypeDefinitions();
    for (final TypeDefinition<?> typeDefinition : typeDefinitions) {
        if (typeDefinition.getQName().getLocalName().equals("imp-type")) {
            impType = typeDefinition;
            break;
        }
    }

    assertNotNull(impType);
    assertEquals(leaf.getType().getQName(), impType.getQName());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:25,代码来源:GroupingTest.java


示例9: verifySingleQuotesExpression

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private static void verifySingleQuotesExpression(final SchemaContext schemaContext) {
    final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar"));
    assertTrue(dataNodeBar instanceof ContainerSchemaNode);
    final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
    final RevisionAwareXPath whenCondition = bar.getWhenCondition().get();
    assertEquals("/foo != 'bar'", whenCondition.toString());

    final Set<TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
    assertEquals(1, typeDefinitions.size());
    final TypeDefinition<?> type = typeDefinitions.iterator().next();
    assertTrue(type instanceof StringTypeDefinition);
    final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
    assertEquals(1, patternConstraints.size());
    final PatternConstraint pattern = patternConstraints.iterator().next();
    assertEquals("^'.*'$", pattern.getJavaPatternString());
    assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("'enclosed string in quotes'").matches());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:18,代码来源:Bug6180Test.java


示例10: test

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Test
public void test() throws Exception {
    final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872");
    assertNotNull(schema);

    final QNameModule bug2872module = QNameModule.create(URI.create("bug2872"), Revision.of("2016-06-08"));
    final QName foo = QName.create(bug2872module, "bar");

    final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
    assertTrue(dataSchemaNode instanceof LeafSchemaNode);
    final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;

    final TypeDefinition<?> type = myLeaf.getType();
    assertTrue(type instanceof EnumTypeDefinition);
    final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;

    final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
    assertEquals(2, values.size());

    final List<String> valueNames = new ArrayList<>();
    for (EnumTypeDefinition.EnumPair pair : values) {
        valueNames.add(pair.getName());
    }
    assertTrue(valueNames.contains("value-one"));
    assertTrue(valueNames.contains("value-two"));
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:27,代码来源:Bug2872Test.java


示例11: testDomainName

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Test
public void testDomainName() {
    Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
    Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
    StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name");
    assertNotNull(type.getBaseType());
    List<PatternConstraint> patterns = type.getPatternConstraints();
    assertEquals(1, patterns.size());
    String expectedPattern = "^((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
            + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.$";
    assertEquals(expectedPattern, patterns.get(0).getJavaPatternString());

    LengthConstraint lengths = type.getLengthConstraint().get();
    assertEquals(1, lengths.getAllowedRanges().asRanges().size());
    Range<Integer> length = lengths.getAllowedRanges().span();
    assertEquals(Integer.valueOf(1), length.lowerEndpoint());
    assertEquals(Integer.valueOf(253), length.upperEndpoint());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:19,代码来源:TypesResolutionTest.java


示例12: createComplexCodecFor

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private T createComplexCodecFor(final TypedDataSchemaNode schema, final TypeDefinition<?> type) {
    if (type instanceof UnionTypeDefinition) {
        return createComplexUnion(schema, (UnionTypeDefinition) type);
    } else if (type instanceof LeafrefTypeDefinition) {
        final TypeDefinition<?> target = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) type,
            schemaContext, schema);
        verifyNotNull(target, "Unable to find base type for leafref node %s type %s.", schema.getPath(),
                target);

        final T ret = getSimpleCodecFor(target);
        return ret != null ? ret : createComplexCodecFor(schema, target);
    } else if (type instanceof IdentityrefTypeDefinition) {
        return identityRefCodec((IdentityrefTypeDefinition) type, schema.getQName().getModule());
    } else {
        throw new IllegalArgumentException("Unsupported type " + type);
    }
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:18,代码来源:AbstractCodecFactory.java


示例13: testTypePath

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Test
public void testTypePath() throws ParseException {
    final Set<TypeDefinition<?>> types = bar.getTypeDefinitions();

    // int32-ext1
    final Int32TypeDefinition int32ext1 = (Int32TypeDefinition) TestUtils.findTypedef(types, "int32-ext1");
    final QName int32TypedefQName = QName.create(BAR, "int32-ext1");
    assertEquals(int32TypedefQName, int32ext1.getQName());

    final SchemaPath typeSchemaPath = int32ext1.getPath();
    final Iterable<QName> typePath = typeSchemaPath.getPathFromRoot();
    final Iterator<QName> typePathIt = typePath.iterator();
    assertEquals(int32TypedefQName, typePathIt.next());
    assertFalse(typePathIt.hasNext());

    // int32-ext1/int32
    final Int32TypeDefinition int32 = int32ext1.getBaseType();
    assertEquals(BaseTypes.int32Type(), int32);
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:20,代码来源:YangParserTest.java


示例14: testRestrictedTypeParentSchemaPathInDeviate

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
@Test
public void testRestrictedTypeParentSchemaPathInDeviate() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug7440");
    assertNotNull(schemaContext);

    final Revision revision = Revision.of("2016-12-23");
    final Module foo = schemaContext.findModule("foo", revision).get();
    final Module bar = schemaContext.findModule("bar", revision).get();

    final Set<Deviation> deviations = foo.getDeviations();
    assertEquals(1, deviations.size());
    final Deviation deviation = deviations.iterator().next();

    final List<DeviateDefinition> deviates = deviation.getDeviates();
    assertEquals(1, deviates.size());
    final DeviateDefinition deviateReplace = deviates.iterator().next();

    final SchemaPath deviatedTypePath = SchemaPath.create(true, QName.create(bar.getQNameModule(), "test-leaf"),
            QName.create(bar.getQNameModule(), "uint32"));

    final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
    assertEquals(deviatedTypePath, deviatedType.getPath());
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:24,代码来源:Bug7440Test.java


示例15: getBaseTypeForLeafRef

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
/**
 * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle
 * the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other
 * module as typedef which is then imported to referenced module.
 *
 * <p>
 * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful.
 */
public static TypeDefinition<?> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition,
        final SchemaContext schemaContext, final QName qname) {
    final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement();
    final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl(
        stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute());
    if (!strippedPathStatement.isAbsolute()) {
        return null;
    }

    final Optional<Module> parentModule = schemaContext.findModule(qname.getModule());
    Preconditions.checkArgument(parentModule.isPresent(), "Failed to find parent module for %s", qname);

    final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext,
        parentModule.get(), strippedPathStatement);
    final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode);
    if (targetTypeDefinition instanceof LeafrefTypeDefinition) {
        return getBaseTypeForLeafRef((LeafrefTypeDefinition) targetTypeDefinition, schemaContext, dataSchemaNode);
    }

    return targetTypeDefinition;
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:30,代码来源:SchemaContextUtil.java


示例16: findParentModuleOfReferencingType

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext,
        final SchemaNode schemaNode) {
    Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
    Preconditions.checkArgument(schemaNode instanceof TypedDataSchemaNode, "Unsupported node %s", schemaNode);

    TypeDefinition<?> nodeType = ((TypedDataSchemaNode) schemaNode).getType();
    if (nodeType.getBaseType() != null) {
        while (nodeType.getBaseType() != null) {
            nodeType = nodeType.getBaseType();
        }

        return schemaContext.findModule(nodeType.getQName().getModule()).orElse(null);
    }

    return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:17,代码来源:SchemaContextUtil.java


示例17: addKeyValue

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
/**
 * Adds a Key Value to the map for a specific uri value.
 * @param map - current QName to Object mapping
 * @param node - DataSchemaNode
 * @param uriValue - uri value to add
 * @throws Exception if error occurs during Uri decoding.
 */
private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue)
        throws Exception {
    Preconditions.checkNotNull(uriValue);
    Preconditions.checkArgument((node instanceof LeafSchemaNode));

    final String urlDecoded = urlPathArgDecode(uriValue);
    TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType();
    final TypeDefinition<?> baseType = resolveBaseTypeFrom(typedef);
    if (baseType instanceof LeafrefTypeDefinition) {
        typedef = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) baseType, globalSchema, node);
    }

    Object decoded = deserialize(typedef, urlDecoded);
    String additionalInfo = "";
    if (decoded == null) {
        if ((baseType instanceof IdentityrefTypeDefinition)) {
            decoded = toQName(urlDecoded);
            additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name.";
        }
    }

    if (decoded == null) {
        throw new Exception(uriValue + " from URI can't be resolved. " + additionalInfo);
    }

    map.put(node.getQName(), decoded);
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:35,代码来源:NameResolver.java


示例18: resolveBaseTypeFrom

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
/**
 * Resolves the Base Type of a TypeDefinition
 * @param type - TypeDefinition
 * @return Base type for the TypeDefinition
 */
private TypeDefinition<?> resolveBaseTypeFrom(final TypeDefinition<?> type) {
    TypeDefinition<?> superType = type;
    while (superType.getBaseType() != null) {
        superType = superType.getBaseType();
    }
    return superType;
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:13,代码来源:NameResolver.java


示例19: getBaseType

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
/**
 * Returns the most base type
 */
private TypeDefinition<?> getBaseType(final TypeProviderWrapper typeProviderWrapper, TypeDefinition<?> baseType) {
    while(baseType.getBaseType()!=null) {
        baseType = baseType.getBaseType();
    }
    return baseType;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:JavaAttribute.java


示例20: getEnumType

import org.opendaylight.yangtools.yang.model.api.TypeDefinition; //导入依赖的package包/类
private OpenType<?> getEnumType(final TypeDefinition<?> baseType) {
    final String fullyQualifiedName = this.typeProviderWrapper.getType(this.node, getTypeDefinition()).getFullyQualifiedName();
    final String[] items = {"instance"};
    final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();

    try {
        return new CompositeType(fullyQualifiedName, description, items, items, new OpenType[]{SimpleType.STRING});
    } catch (final OpenDataException e) {
        throw new RuntimeException("Unable to create enum type" + fullyQualifiedName + " as open type", e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:JavaAttribute.java



注:本文中的org.opendaylight.yangtools.yang.model.api.TypeDefinition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EmbeddedDatabaseFactoryBean类代码示例发布时间:2022-05-23
下一篇:
Java PolynomialGF2mSmallM类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap