use of org.opendaylight.yangtools.yang.model.api.TypeDefinition 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);
}
}
Aggregations