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 org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
11 import org.opendaylight.yangtools.binding.generator.util.Types;
12 import org.opendaylight.yangtools.sal.binding.model.api.Type;
13 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
17 import javax.management.openmbean.ArrayType;
18 import javax.management.openmbean.OpenDataException;
19 import javax.management.openmbean.OpenType;
20 import java.util.List;
22 public class ListAttribute extends AbstractAttribute implements TypedAttribute {
24 private final String nullableDescription, nullableDefault;
25 private final TypedAttribute innerAttribute;
27 public static ListAttribute create(ListSchemaNode node,
28 TypeProviderWrapper typeProvider, String packageName) {
30 TOAttribute innerAttribute = TOAttribute.create(node, typeProvider, packageName);
32 return new ListAttribute(node, innerAttribute, node.getDescription());
35 public static ListAttribute create(LeafListSchemaNode node,
36 TypeProviderWrapper typeProvider) {
38 JavaAttribute innerAttribute = new JavaAttribute(node, typeProvider);
40 return new ListAttribute(node, innerAttribute, node.getDescription());
43 ListAttribute(DataSchemaNode attrNode, TypedAttribute innerAttribute,
46 this.nullableDescription = description;
47 this.innerAttribute = innerAttribute;
48 this.nullableDefault = null;
52 public String getNullableDescription() {
53 return nullableDescription;
57 public String getNullableDefault() {
58 return nullableDefault;
61 public AttributeIfc getInnerAttribute() {
62 return innerAttribute;
66 public String toString() {
67 return "ListAttribute{" + getAttributeYangName() + "," + "to="
68 + innerAttribute + '}';
72 public int hashCode() {
73 int result = super.hashCode();
76 + (nullableDescription != null ? nullableDescription.hashCode()
79 + (nullableDefault != null ? nullableDefault.hashCode() : 0);
84 public boolean equals(Object o) {
87 if (o == null || getClass() != o.getClass())
92 ListAttribute that = (ListAttribute) o;
94 if (nullableDefault != null ? !nullableDefault
95 .equals(that.nullableDefault) : that.nullableDefault != null)
97 if (nullableDescription != null ? !nullableDescription
98 .equals(that.nullableDescription)
99 : that.nullableDescription != null)
107 public Type getType() {
108 return Types.parameterizedTypeFor(Types.typeForClass(List.class), innerAttribute.getType());
112 public ArrayType<?> getOpenType() {
113 OpenType<?> innerOpenType = innerAttribute.getOpenType();
114 return constructArrayType(innerOpenType);
117 static ArrayType<?> constructArrayType(OpenType<?> innerOpenType){
119 return new ArrayType<>(1, innerOpenType);
120 } catch (OpenDataException e) {
121 throw new RuntimeException("Unable to create " + ArrayType.class
122 + " with inner element of type " + innerOpenType, e);