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=cbeb5c3b297415bacf1a74596abbbf8d4fb9d207;hb=ebd9aba9e844229de613a2b60b5d21119fcee968;hp=96656338df130f30ef569fbb54537727ff9a0b3a;hpb=bab3649670c33b3b12a49c59fc1c5cabcbcb924e;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 96656338df..cbeb5c3b29 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,8 +11,9 @@ 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; import org.opendaylight.yangtools.yang.model.api.AugmentationTarget; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; @@ -24,16 +25,19 @@ 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; -public class TOAttribute extends AbstractAttribute { +public class TOAttribute extends AbstractAttribute implements TypedAttribute { private final String nullableDescription, nullableDefault; private final Map yangNameToAttributeMap; private final Map attributeNameMap; + private final String packageName; private static final Set> ALLOWED_CHILDREN = Sets .newHashSet(); @@ -45,7 +49,7 @@ public class TOAttribute extends AbstractAttribute { } public static TOAttribute create( - T containerSchemaNode, TypeProviderWrapper typeProviderWrapper) { + T containerSchemaNode, TypeProviderWrapper typeProviderWrapper, String packageName) { // Transfer Object: get the leaves Map map = new HashMap<>(); Map attributeNameMap = new HashMap<>(); @@ -55,18 +59,18 @@ public class TOAttribute extends AbstractAttribute { String yangName = dataSchemaNode.getQName().getLocalName(); map.put(yangName, createInnerAttribute(dataSchemaNode, - typeProviderWrapper)); + typeProviderWrapper, packageName)); } catch (IllegalArgumentException e) { throw new IllegalStateException("Unable to create TO", e); } } return new TOAttribute(containerSchemaNode, map, attributeNameMap, - containerSchemaNode.getDescription()); + containerSchemaNode.getDescription(), packageName); } private static AttributeIfc createInnerAttribute( DataSchemaNode dataSchemaNode, - TypeProviderWrapper typeProviderWrapper) { + TypeProviderWrapper typeProviderWrapper, String packageName) { Class type = isAllowedType(dataSchemaNode); if (type.equals(LeafSchemaNode.class)) @@ -74,13 +78,13 @@ public class TOAttribute extends AbstractAttribute { typeProviderWrapper); else if (type.equals(ListSchemaNode.class)) return ListAttribute.create((ListSchemaNode) dataSchemaNode, - typeProviderWrapper); + typeProviderWrapper, packageName); else if (type.equals(LeafListSchemaNode.class)) return ListAttribute.create((LeafListSchemaNode) dataSchemaNode, typeProviderWrapper); else if (type.equals(ContainerSchemaNode.class)) return TOAttribute.create((ContainerSchemaNode) dataSchemaNode, - typeProviderWrapper); + typeProviderWrapper, packageName); throw new IllegalStateException("This should never happen"); } @@ -98,12 +102,13 @@ public class TOAttribute extends AbstractAttribute { private TOAttribute(DataSchemaNode attrNode, Map transferObject, - Map attributeNameMap, String nullableDescription) { + Map attributeNameMap, String nullableDescription, String packageName) { super(attrNode); yangNameToAttributeMap = transferObject; this.attributeNameMap = attributeNameMap; this.nullableDescription = nullableDescription; nullableDefault = null; + this.packageName = packageName; } public Map getAttributeNameMap() { @@ -117,7 +122,7 @@ public class TOAttribute extends AbstractAttribute { .entrySet()) { capitalizedPropertiesToTypesMap.put( - ModuleMXBeanEntry.convertToJavaName(entry.getKey(), true), + TypeProviderWrapper.convertToJavaName(entry.getKey(), true), entry.getValue()); } return capitalizedPropertiesToTypesMap; @@ -129,7 +134,7 @@ public class TOAttribute extends AbstractAttribute { .entrySet()) { jmxPropertiesToTypesMap.put( - ModuleMXBeanEntry.convertToJavaName(entry.getKey(), false), + TypeProviderWrapper.convertToJavaName(entry.getKey(), false), entry.getValue()); } return jmxPropertiesToTypesMap; @@ -197,24 +202,28 @@ public class TOAttribute extends AbstractAttribute { + yangNameToAttributeMap + '}'; } + @Override + public Type getType() { + // TODO: ReferencedTypeImpl from Types + return new ReferencedTypeImpl(packageName, getUpperCaseCammelCase()); + } + @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 " @@ -222,20 +231,24 @@ public class TOAttribute extends AbstractAttribute { } } - private static final class FunctionImpl implements - Function, OpenType> { - private final String[] itemNames; - int i = 0; + public String getPackageName() { + return packageName; + } + +} - 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()]); } }