package org.opendaylight.controller.config.yangjmxgenerator.attribute;
import com.google.common.base.Preconditions;
+import org.opendaylight.controller.config.api.IdentityAttributeRef;
import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
import org.opendaylight.yangtools.sal.binding.model.api.Type;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import javax.management.openmbean.ArrayType;
TypeProviderWrapper typeProviderWrapper) {
super(leaf);
this.type = typeProviderWrapper.getType(leaf);
+
this.typeDefinition = leaf.getType();
this.typeProviderWrapper = typeProviderWrapper;
this.nullableDefault = leaf.getDefault();
@Override
public boolean equals(Object o) {
- if (this == o)
+ if (this == o) {
return true;
- if (o == null || getClass() != o.getClass())
+ }
+ if (o == null || getClass() != o.getClass()) {
return false;
- if (!super.equals(o))
+ }
+ if (!super.equals(o)) {
return false;
+ }
JavaAttribute that = (JavaAttribute) o;
if (nullableDefault != null ? !nullableDefault
- .equals(that.nullableDefault) : that.nullableDefault != null)
+ .equals(that.nullableDefault) : that.nullableDefault != null) {
return false;
+ }
if (nullableDescription != null ? !nullableDescription
.equals(that.nullableDescription)
- : that.nullableDescription != null)
+ : that.nullableDescription != null) {
return false;
- if (type != null ? !type.equals(that.type) : that.type != null)
+ }
+ if (type != null ? !type.equals(that.type) : that.type != null) {
return false;
+ }
return true;
}
return getCompositeTypeForUnion(baseTypeDefinition);
} else if (isDerivedType(baseType, getType())) {
return getCompositeType(baseType, baseTypeDefinition);
+ } else if (isIdentityRef()) {
+ return getCompositeTypeForIdentity();
}
return getSimpleType(getType());
}
+ 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);
OpenType<?> innerCompositeType;
if(isDerivedType(innerTypeBaseType, innerType)) {
- innerCompositeType = getCompositeType(innerTypeBaseType, baseInnerTypeDefinition);
+ innerCompositeType = baseInnerTypeDefinition instanceof UnionTypeDefinition ?
+ getCompositeTypeForUnion(baseInnerTypeDefinition) :
+ getCompositeType(innerTypeBaseType, baseInnerTypeDefinition);
} else {
innerCompositeType = SimpleTypeResolver.getSimpleType(innerType);
}
}
}
+ public OpenType<?> getCompositeTypeForIdentity() {
+ String[] itemNames = new String[]{IdentityAttributeRef.QNAME_ATTR_NAME};
+ String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();
+ OpenType<?>[] itemTypes = new OpenType[]{SimpleType.STRING};
+
+ try {
+ return new CompositeType(getUpperCaseCammelCase(), description, itemNames, itemNames, itemTypes);
+ } catch (OpenDataException e) {
+ throw new RuntimeException("Unable to create " + CompositeType.class + " with inner element of type "
+ + itemTypes, e);
+ }
+ }
+
private OpenType<?> getArrayType() {
String innerTypeFullyQName = getInnerType(getType());
SimpleType<?> innerSimpleType = SimpleTypeResolver.getSimpleType(innerTypeFullyQName);
}
private boolean isDerivedType(Type baseType, Type currentType) {
- return baseType.equals(currentType) == false;
+ return baseType.equals(currentType) == false;
}
private static String getInnerType(Type type) {