X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fattribute%2FJavaAttribute.java;h=d830e97678db5d7f4f5b26c8db70daf212472d48;hp=6a90439bb2af4b0b3da9287ff6b850bfbf5a9f65;hb=cd50f92c60580b546a696aab7c3ff4fbf3f9a5f0;hpb=38f87458be5fd29ad412e7f49e98e7d011a94254 diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java index 6a90439bb2..d830e97678 100644 --- a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java +++ b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java @@ -21,6 +21,7 @@ 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.EnumTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; @@ -60,6 +61,11 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute { return base instanceof UnionTypeDefinition; } + public boolean isEnum() { + TypeDefinition base = getBaseType(typeProviderWrapper, typeDefinition); + return base instanceof EnumTypeDefinition; + } + public TypeDefinition getTypeDefinition() { return typeDefinition; } @@ -149,8 +155,8 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute { if (isArray()) { return getArrayType(); - } else if (isEnum(baseType)) { - return getSimpleType(baseType); + } else if (isEnum()) { + return getEnumType(baseTypeDefinition); } else if (isUnion()) { return getCompositeTypeForUnion(baseTypeDefinition); } else if (isDerivedType(baseType, getType())) { @@ -162,6 +168,18 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute { return getSimpleType(getType()); } + private OpenType getEnumType(final TypeDefinition baseType) { + final String fullyQualifiedName = typeProviderWrapper.getType(node, getTypeDefinition()).getFullyQualifiedName(); + final String[] items = {"instance"}; + String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription(); + + try { + return new CompositeType(fullyQualifiedName, description, items, items, new OpenType[]{SimpleType.STRING}); + } catch (OpenDataException e) { + throw new RuntimeException("Unable to create enum type" + fullyQualifiedName + " as open type", e); + } + } + public boolean isIdentityRef() { return typeDefinition instanceof IdentityrefTypeDefinition; } @@ -223,10 +241,6 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute { itemTypes[0] = artificialPropertyType; } - private boolean isEnum(Type baseType) { - return baseType.getFullyQualifiedName().equals(Enum.class.getName()); - } - private OpenType getSimpleType(Type type) { SimpleType simpleType = SimpleTypeResolver.getSimpleType(type); return simpleType;