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%2FListAttribute.java;fp=opendaylight%2Fconfig%2Fyang-jmx-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fattribute%2FListAttribute.java;h=083b0b53e9777c2391acafb65e72011267800183;hb=9fb64948564e252018f9b1e13e7cea2c92f991aa;hp=0000000000000000000000000000000000000000;hpb=1742b3894614be478c333a1043ced8ef1bc5dc84;p=controller.git diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/ListAttribute.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/ListAttribute.java new file mode 100644 index 0000000000..083b0b53e9 --- /dev/null +++ b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/ListAttribute.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yangjmxgenerator.attribute; + +import javax.management.openmbean.ArrayType; +import javax.management.openmbean.OpenDataException; +import javax.management.openmbean.OpenType; + +import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; + +public class ListAttribute extends AbstractAttribute { + + private final String nullableDescription, nullableDefault; + private final AttributeIfc innerAttribute; + + public static ListAttribute create(ListSchemaNode node, + TypeProviderWrapper typeProvider) { + + AttributeIfc innerAttribute = TOAttribute.create(node, typeProvider); + + return new ListAttribute(node, innerAttribute, node.getDescription()); + } + + public static ListAttribute create(LeafListSchemaNode node, + TypeProviderWrapper typeProvider) { + + AttributeIfc innerAttribute = new JavaAttribute(node, typeProvider); + + return new ListAttribute(node, innerAttribute, node.getDescription()); + } + + ListAttribute(DataSchemaNode attrNode, AttributeIfc innerAttribute, + String description) { + super(attrNode); + this.nullableDescription = description; + this.innerAttribute = innerAttribute; + this.nullableDefault = null; + } + + @Override + public String getNullableDescription() { + return nullableDescription; + } + + @Override + public String getNullableDefault() { + return nullableDefault; + } + + public AttributeIfc getInnerAttribute() { + return innerAttribute; + } + + @Override + public String toString() { + return "ListAttribute{" + getAttributeYangName() + "," + "to=" + + innerAttribute + '}'; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 + * result + + (nullableDescription != null ? nullableDescription.hashCode() + : 0); + result = 31 * result + + (nullableDefault != null ? nullableDefault.hashCode() : 0); + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; + + ListAttribute that = (ListAttribute) o; + + if (nullableDefault != null ? !nullableDefault + .equals(that.nullableDefault) : that.nullableDefault != null) + return false; + if (nullableDescription != null ? !nullableDescription + .equals(that.nullableDescription) + : that.nullableDescription != null) + return false; + + return true; + } + + @Override + public ArrayType getOpenType() { + OpenType inerOpenType = innerAttribute.getOpenType(); + try { + return new ArrayType<>(1, inerOpenType); + } catch (OpenDataException e) { + throw new RuntimeException("Unable to create " + ArrayType.class + + " with inner element of type " + inerOpenType, e); + } + } + +}