+ public boolean isIdentityRef() {
+ return typeDefinition instanceof IdentityrefTypeDefinition;
+ }
+
+ private OpenType<?> getCompositeTypeForUnion(TypeDefinition<?> baseTypeDefinition) {
+ Preconditions.checkArgument(baseTypeDefinition instanceof UnionTypeDefinition,
+ "Expected %s instance but was %s", UnionTypeDefinition.class, baseTypeDefinition);
+
+ List<TypeDefinition<?>> types = ((UnionTypeDefinition) baseTypeDefinition).getTypes();
+
+ String[] itemNames = new String[types.size()+1];
+ OpenType<?>[] itemTypes = new OpenType[itemNames.length];
+
+ addArtificialPropertyToUnionCompositeType(baseTypeDefinition, itemNames, itemTypes);
+
+ String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();
+
+ int i = 1;
+ for (TypeDefinition<?> innerTypeDefinition : types) {
+
+ Type innerType = typeProviderWrapper.getType(innerTypeDefinition, innerTypeDefinition);
+
+ TypeDefinition<?> baseInnerTypeDefinition = getBaseType(typeProviderWrapper, innerTypeDefinition);
+ Type innerTypeBaseType = 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] = typeProviderWrapper.getJMXParamForUnionInnerType(innerTypeDefinition);
+ itemTypes[i++] = innerCompositeType;
+ }
+
+ String[] descriptions = Arrays.copyOf(itemNames, itemNames.length);
+ descriptions[0] = DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION;
+
+ try {
+ return new CompositeType(getUpperCaseCammelCase(), description, itemNames, descriptions, itemTypes);
+ } catch (OpenDataException e) {
+ throw new RuntimeException("Unable to create " + CompositeType.class + " with inner elements "
+ + Arrays.toString(itemTypes), e);
+ }
+ }
+
+ public static final Class<Character> TYPE_OF_ARTIFICIAL_UNION_PROPERTY = char.class;
+
+ private void addArtificialPropertyToUnionCompositeType(TypeDefinition<?> baseTypeDefinition, String[] itemNames, OpenType<?>[] itemTypes) {
+ String artificialPropertyName = typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);
+ itemNames[0] = artificialPropertyName;
+
+ OpenType<?> artificialPropertyType = getArrayOpenTypeForSimpleType(TYPE_OF_ARTIFICIAL_UNION_PROPERTY.getName(),
+ SimpleTypeResolver.getSimpleType(TYPE_OF_ARTIFICIAL_UNION_PROPERTY.getName()));
+ itemTypes[0] = artificialPropertyType;
+ }
+