Search in sources :

Example 1 with UnionTypeDefinition

use of org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition in project controller by opendaylight.

the class JavaAttribute method getCompositeTypeForUnion.

private OpenType<?> getCompositeTypeForUnion(final TypeDefinition<?> baseTypeDefinition) {
    Preconditions.checkArgument(baseTypeDefinition instanceof UnionTypeDefinition, "Expected %s instance but was %s", UnionTypeDefinition.class, baseTypeDefinition);
    final List<TypeDefinition<?>> types = ((UnionTypeDefinition) baseTypeDefinition).getTypes();
    final String[] itemNames = new String[types.size() + 1];
    final OpenType<?>[] itemTypes = new OpenType[itemNames.length];
    addArtificialPropertyToUnionCompositeType(baseTypeDefinition, itemNames, itemTypes);
    final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();
    int i = 1;
    for (final TypeDefinition<?> innerTypeDefinition : types) {
        final Type innerType = this.typeProviderWrapper.getType(innerTypeDefinition, innerTypeDefinition);
        final TypeDefinition<?> baseInnerTypeDefinition = getBaseType(this.typeProviderWrapper, innerTypeDefinition);
        final Type innerTypeBaseType = this.typeProviderWrapper.getType(baseInnerTypeDefinition, baseInnerTypeDefinition);
        OpenType<?> innerCompositeType;
        if (isDerivedType(innerTypeBaseType, innerType)) {
            innerCompositeType = baseInnerTypeDefinition instanceof UnionTypeDefinition ? getCompositeTypeForUnion(baseInnerTypeDefinition) : getCompositeType(innerTypeBaseType, baseInnerTypeDefinition);
        } else {
            innerCompositeType = SimpleTypeResolver.getSimpleType(innerType);
        }
        itemNames[i] = this.typeProviderWrapper.getJMXParamForUnionInnerType(innerTypeDefinition);
        itemTypes[i++] = innerCompositeType;
    }
    final String[] descriptions = itemNames.clone();
    descriptions[0] = DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION;
    try {
        return new CompositeType(getUpperCaseCammelCase(), description, itemNames, descriptions, itemTypes);
    } catch (final OpenDataException e) {
        throw new RuntimeException("Unable to create " + CompositeType.class + " with inner elements " + Arrays.toString(itemTypes), e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) IdentityrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition) EnumTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition) TypeDefinition(org.opendaylight.yangtools.yang.model.api.TypeDefinition) CompositeType(javax.management.openmbean.CompositeType) Type(org.opendaylight.mdsal.binding.model.api.Type) SimpleType(javax.management.openmbean.SimpleType) OpenType(javax.management.openmbean.OpenType) ArrayType(javax.management.openmbean.ArrayType) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

ArrayType (javax.management.openmbean.ArrayType)1 CompositeType (javax.management.openmbean.CompositeType)1 OpenDataException (javax.management.openmbean.OpenDataException)1 OpenType (javax.management.openmbean.OpenType)1 SimpleType (javax.management.openmbean.SimpleType)1 Type (org.opendaylight.mdsal.binding.model.api.Type)1 TypeDefinition (org.opendaylight.yangtools.yang.model.api.TypeDefinition)1 EnumTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition)1 IdentityrefTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition)1 UnionTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition)1