2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yangjmxgenerator.attribute;
10 import java.util.List;
11 import javax.management.openmbean.ArrayType;
12 import javax.management.openmbean.OpenDataException;
13 import javax.management.openmbean.OpenType;
14 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
15 import org.opendaylight.mdsal.binding.generator.util.Types;
16 import org.opendaylight.mdsal.binding.model.api.Type;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 public class ListAttribute extends AbstractAttribute implements TypedAttribute {
23 private final String nullableDescription, nullableDefault;
24 private final TypedAttribute innerAttribute;
26 public static ListAttribute create(final ListSchemaNode node,
27 final TypeProviderWrapper typeProvider, final String packageName) {
29 final TOAttribute innerAttribute = TOAttribute.create(node, typeProvider, packageName);
31 return new ListAttribute(node, innerAttribute, node.getDescription());
34 public static ListAttribute create(final LeafListSchemaNode node,
35 final TypeProviderWrapper typeProvider) {
37 final JavaAttribute innerAttribute = new JavaAttribute(node, typeProvider);
39 return new ListAttribute(node, innerAttribute, node.getDescription());
42 ListAttribute(final DataSchemaNode attrNode, final TypedAttribute innerAttribute,
43 final String description) {
45 this.nullableDescription = description;
46 this.innerAttribute = innerAttribute;
47 this.nullableDefault = null;
51 public String getNullableDescription() {
52 return this.nullableDescription;
56 public String getNullableDefault() {
57 return this.nullableDefault;
60 public AttributeIfc getInnerAttribute() {
61 return this.innerAttribute;
65 public String toString() {
66 return "ListAttribute{" + getAttributeYangName() + "," + "to="
67 + this.innerAttribute + '}';
71 public int hashCode() {
72 int result = super.hashCode();
75 + (this.nullableDescription != null ? this.nullableDescription.hashCode()
77 result = (31 * result)
78 + (this.nullableDefault != null ? this.nullableDefault.hashCode() : 0);
83 public boolean equals(final Object o) {
87 if ((o == null) || (getClass() != o.getClass())) {
90 if (!super.equals(o)) {
94 final ListAttribute that = (ListAttribute) o;
96 if (this.nullableDefault != null ? !this.nullableDefault
97 .equals(that.nullableDefault) : that.nullableDefault != null) {
100 if (this.nullableDescription != null ? !this.nullableDescription
101 .equals(that.nullableDescription)
102 : that.nullableDescription != null) {
111 public Type getType() {
112 return Types.parameterizedTypeFor(Types.typeForClass(List.class), this.innerAttribute.getType());
116 public ArrayType<?> getOpenType() {
117 final OpenType<?> innerOpenType = this.innerAttribute.getOpenType();
118 return constructArrayType(innerOpenType);
121 static ArrayType<?> constructArrayType(final OpenType<?> innerOpenType){
123 return new ArrayType<>(1, innerOpenType);
124 } catch (final OpenDataException e) {
125 throw new RuntimeException("Unable to create " + ArrayType.class
126 + " with inner element of type " + innerOpenType, e);