Fix race conditions between config-manager and persister.
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / attribute / DependencyAttribute.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yangjmxgenerator.attribute;
9
10 import javax.management.ObjectName;
11 import javax.management.openmbean.OpenType;
12 import javax.management.openmbean.SimpleType;
13
14 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
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
19 public class DependencyAttribute extends AbstractAttribute implements
20         TypedAttribute {
21
22     private final Dependency dependency;
23     private final String nullableDescription, nullableDefault;
24
25     public DependencyAttribute(DataSchemaNode attrNode,
26             ServiceInterfaceEntry sie, boolean mandatory,
27             String nullableDescription) {
28         super(attrNode);
29         dependency = new Dependency(sie, mandatory);
30         this.nullableDescription = nullableDescription;
31         nullableDefault = null;
32     }
33
34     @Override
35     public Type getType() {
36         return Types.typeForClass(ObjectName.class);
37     }
38
39     public Dependency getDependency() {
40         return dependency;
41     }
42
43     @Override
44     public String getNullableDescription() {
45         return nullableDescription;
46     }
47
48     @Override
49     public String getNullableDefault() {
50         return nullableDefault;
51     }
52
53     @Override
54     public boolean equals(Object o) {
55         if (this == o)
56             return true;
57         if (o == null || getClass() != o.getClass())
58             return false;
59         if (!super.equals(o))
60             return false;
61
62         DependencyAttribute that = (DependencyAttribute) o;
63
64         if (dependency != null ? !dependency.equals(that.dependency)
65                 : that.dependency != null)
66             return false;
67         if (nullableDefault != null ? !nullableDefault
68                 .equals(that.nullableDefault) : that.nullableDefault != null)
69             return false;
70         if (nullableDescription != null ? !nullableDescription
71                 .equals(that.nullableDescription)
72                 : that.nullableDescription != null)
73             return false;
74
75         return true;
76     }
77
78     @Override
79     public int hashCode() {
80         int result = super.hashCode();
81         result = 31 * result + (dependency != null ? dependency.hashCode() : 0);
82         result = 31
83                 * result
84                 + (nullableDescription != null ? nullableDescription.hashCode()
85                         : 0);
86         result = 31 * result
87                 + (nullableDefault != null ? nullableDefault.hashCode() : 0);
88         return result;
89     }
90
91     @Override
92     public String toString() {
93         return "DependencyAttribute{" + getAttributeYangName() + ","
94                 + "dependency=" + dependency + '}';
95     }
96
97     @Override
98     public OpenType<?> getOpenType() {
99         return SimpleType.OBJECTNAME;
100     }
101
102     public static class Dependency {
103         private final ServiceInterfaceEntry sie;
104         private final boolean mandatory;
105
106         public Dependency(ServiceInterfaceEntry sie, boolean mandatory) {
107             this.sie = sie;
108             this.mandatory = mandatory;
109         }
110
111         public ServiceInterfaceEntry getSie() {
112             return sie;
113         }
114
115         public boolean isMandatory() {
116             return mandatory;
117         }
118
119         @Override
120         public boolean equals(Object o) {
121             if (this == o)
122                 return true;
123             if (o == null || getClass() != o.getClass())
124                 return false;
125
126             Dependency that = (Dependency) o;
127
128             if (mandatory != that.mandatory)
129                 return false;
130             if (!sie.equals(that.sie))
131                 return false;
132
133             return true;
134         }
135
136         @Override
137         public int hashCode() {
138             int result = sie.hashCode();
139             result = 31 * result + (mandatory ? 1 : 0);
140             return result;
141         }
142     }
143
144 }