X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fattribute%2FTOAttribute.java;h=e563da1328a210f82b44f498b08fd9c73348cfd3;hb=refs%2Fchanges%2F99%2F11999%2F1;hp=6a540b50b21dab04433dcb349eb905a9a2cd303b;hpb=356f96ce57f8c099ce98e38b4053c075050bda10;p=controller.git diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/TOAttribute.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/TOAttribute.java index 6a540b50b2..e563da1328 100644 --- a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/TOAttribute.java +++ b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/TOAttribute.java @@ -11,7 +11,6 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper; import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl; import org.opendaylight.yangtools.sal.binding.model.api.Type; @@ -26,7 +25,9 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import javax.management.openmbean.CompositeType; import javax.management.openmbean.OpenDataException; import javax.management.openmbean.OpenType; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -72,18 +73,19 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { TypeProviderWrapper typeProviderWrapper, String packageName) { Class type = isAllowedType(dataSchemaNode); - if (type.equals(LeafSchemaNode.class)) + if (type.equals(LeafSchemaNode.class)) { return new JavaAttribute((LeafSchemaNode) dataSchemaNode, typeProviderWrapper); - else if (type.equals(ListSchemaNode.class)) + } else if (type.equals(ListSchemaNode.class)) { return ListAttribute.create((ListSchemaNode) dataSchemaNode, typeProviderWrapper, packageName); - else if (type.equals(LeafListSchemaNode.class)) + } else if (type.equals(LeafListSchemaNode.class)) { return ListAttribute.create((LeafListSchemaNode) dataSchemaNode, typeProviderWrapper); - else if (type.equals(ContainerSchemaNode.class)) + } else if (type.equals(ContainerSchemaNode.class)) { return TOAttribute.create((ContainerSchemaNode) dataSchemaNode, typeProviderWrapper, packageName); + } throw new IllegalStateException("This should never happen"); } @@ -91,8 +93,9 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { private static Class isAllowedType( DataSchemaNode dataSchemaNode) { for (Class allowedType : ALLOWED_CHILDREN) { - if (allowedType.isAssignableFrom(dataSchemaNode.getClass()) == true) + if (allowedType.isAssignableFrom(dataSchemaNode.getClass()) == true) { return allowedType; + } } throw new IllegalArgumentException("Illegal child node for TO: " + dataSchemaNode.getClass() + " allowed node types: " @@ -121,7 +124,7 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { .entrySet()) { capitalizedPropertiesToTypesMap.put( - ModuleMXBeanEntry.convertToJavaName(entry.getKey(), true), + TypeProviderWrapper.convertToJavaName(entry.getKey(), true), entry.getValue()); } return capitalizedPropertiesToTypesMap; @@ -133,7 +136,7 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { .entrySet()) { jmxPropertiesToTypesMap.put( - ModuleMXBeanEntry.convertToJavaName(entry.getKey(), false), + TypeProviderWrapper.convertToJavaName(entry.getKey(), false), entry.getValue()); } return jmxPropertiesToTypesMap; @@ -155,26 +158,32 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { @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; + } TOAttribute that = (TOAttribute) 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 (yangNameToAttributeMap != null ? !yangNameToAttributeMap .equals(that.yangNameToAttributeMap) - : that.yangNameToAttributeMap != null) + : that.yangNameToAttributeMap != null) { return false; + } return true; } @@ -209,22 +218,20 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { @Override public CompositeType getOpenType() { - String description = getNullableDescription() == null ? getAttributeYangName() - : getNullableDescription(); - final String[] itemNames = new String[yangNameToAttributeMap.keySet() - .size()]; - String[] itemDescriptions = itemNames; - FunctionImpl functionImpl = new FunctionImpl(itemNames); + String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription(); + + FunctionImpl functionImpl = new FunctionImpl(); Map jmxPropertiesToTypesMap = getJmxPropertiesToTypesMap(); OpenType[] itemTypes = Collections2.transform( jmxPropertiesToTypesMap.entrySet(), functionImpl).toArray( new OpenType[] {}); + String[] itemNames = functionImpl.getItemNames(); try { // TODO add package name to create fully qualified name for this // type CompositeType compositeType = new CompositeType( getUpperCaseCammelCase(), description, itemNames, - itemDescriptions, itemTypes); + itemNames, itemTypes); return compositeType; } catch (OpenDataException e) { throw new RuntimeException("Unable to create CompositeType for " @@ -236,20 +243,20 @@ public class TOAttribute extends AbstractAttribute implements TypedAttribute { return packageName; } - private static final class FunctionImpl implements - Function, OpenType> { - private final String[] itemNames; - int i = 0; +} - private FunctionImpl(String[] itemNames) { - this.itemNames = itemNames; - } +class FunctionImpl implements + Function, OpenType> { + private final List itemNames = new ArrayList<>(); - @Override - public OpenType apply(Entry input) { - AttributeIfc innerType = input.getValue(); - itemNames[i++] = input.getKey(); - return innerType.getOpenType(); - } + @Override + public OpenType apply(Entry input) { + AttributeIfc innerType = input.getValue(); + itemNames.add(input.getKey()); + return innerType.getOpenType(); + } + + public String[] getItemNames(){ + return itemNames.toArray(new String[itemNames.size()]); } }