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.yangtools.binding.generator.util.Types;
16 import org.opendaylight.yangtools.sal.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(ListSchemaNode node,
27 TypeProviderWrapper typeProvider, String packageName) {
29 TOAttribute innerAttribute = TOAttribute.create(node, typeProvider, packageName);
31 return new ListAttribute(node, innerAttribute, node.getDescription());
34 public static ListAttribute create(LeafListSchemaNode node,
35 TypeProviderWrapper typeProvider) {
37 JavaAttribute innerAttribute = new JavaAttribute(node, typeProvider);
39 return new ListAttribute(node, innerAttribute, node.getDescription());
42 ListAttribute(DataSchemaNode attrNode, TypedAttribute innerAttribute,
45 this.nullableDescription = description;
46 this.innerAttribute = innerAttribute;
47 this.nullableDefault = null;
51 public String getNullableDescription() {
52 return nullableDescription;
56 public String getNullableDefault() {
57 return nullableDefault;
60 public AttributeIfc getInnerAttribute() {
61 return innerAttribute;
65 public String toString() {
66 return "ListAttribute{" + getAttributeYangName() + "," + "to="
67 + innerAttribute + '}';
71 public int hashCode() {
72 int result = super.hashCode();
75 + (nullableDescription != null ? nullableDescription.hashCode()
78 + (nullableDefault != null ? nullableDefault.hashCode() : 0);
83 public boolean equals(Object o) {
87 if (o == null || getClass() != o.getClass()) {
90 if (!super.equals(o)) {
94 ListAttribute that = (ListAttribute) o;
96 if (nullableDefault != null ? !nullableDefault
97 .equals(that.nullableDefault) : that.nullableDefault != null) {
100 if (nullableDescription != null ? !nullableDescription
101 .equals(that.nullableDescription)
102 : that.nullableDescription != null) {
111 public Type getType() {
112 return Types.parameterizedTypeFor(Types.typeForClass(List.class), innerAttribute.getType());
116 public ArrayType<?> getOpenType() {
117 OpenType<?> innerOpenType = innerAttribute.getOpenType();
118 return constructArrayType(innerOpenType);
121 static ArrayType<?> constructArrayType(OpenType<?> innerOpenType){
123 return new ArrayType<>(1, innerOpenType);
124 } catch (OpenDataException e) {
125 throw new RuntimeException("Unable to create " + ArrayType.class
126 + " with inner element of type " + innerOpenType, e);