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 javax.management.openmbean.ArrayType;
11 import javax.management.openmbean.OpenDataException;
12 import javax.management.openmbean.OpenType;
14 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
19 public class ListAttribute extends AbstractAttribute {
21 private final String nullableDescription, nullableDefault;
22 private final AttributeIfc innerAttribute;
24 public static ListAttribute create(ListSchemaNode node,
25 TypeProviderWrapper typeProvider) {
27 AttributeIfc innerAttribute = TOAttribute.create(node, typeProvider);
29 return new ListAttribute(node, innerAttribute, node.getDescription());
32 public static ListAttribute create(LeafListSchemaNode node,
33 TypeProviderWrapper typeProvider) {
35 AttributeIfc innerAttribute = new JavaAttribute(node, typeProvider);
37 return new ListAttribute(node, innerAttribute, node.getDescription());
40 ListAttribute(DataSchemaNode attrNode, AttributeIfc innerAttribute,
43 this.nullableDescription = description;
44 this.innerAttribute = innerAttribute;
45 this.nullableDefault = null;
49 public String getNullableDescription() {
50 return nullableDescription;
54 public String getNullableDefault() {
55 return nullableDefault;
58 public AttributeIfc getInnerAttribute() {
59 return innerAttribute;
63 public String toString() {
64 return "ListAttribute{" + getAttributeYangName() + "," + "to="
65 + innerAttribute + '}';
69 public int hashCode() {
70 int result = super.hashCode();
73 + (nullableDescription != null ? nullableDescription.hashCode()
76 + (nullableDefault != null ? nullableDefault.hashCode() : 0);
81 public boolean equals(Object o) {
84 if (o == null || getClass() != o.getClass())
89 ListAttribute that = (ListAttribute) o;
91 if (nullableDefault != null ? !nullableDefault
92 .equals(that.nullableDefault) : that.nullableDefault != null)
94 if (nullableDescription != null ? !nullableDescription
95 .equals(that.nullableDescription)
96 : that.nullableDescription != null)
103 public ArrayType<?> getOpenType() {
104 OpenType<?> inerOpenType = innerAttribute.getOpenType();
106 return new ArrayType<>(1, inerOpenType);
107 } catch (OpenDataException e) {
108 throw new RuntimeException("Unable to create " + ArrayType.class
109 + " with inner element of type " + inerOpenType, e);