Merge "Reuse AbstractListenerRegistration"
[controller.git] / opendaylight / config / config-api / src / main / java / org / opendaylight / controller / config / api / IdentityAttributeRef.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.api;
9
10 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
11
12 import java.beans.ConstructorProperties;
13
14 public final class IdentityAttributeRef {
15
16     public static final String QNAME_ATTR_NAME = "qNameOfIdentity";
17
18     private final String qNameOfIdentity;
19
20     @ConstructorProperties(QNAME_ATTR_NAME)
21     public IdentityAttributeRef(String qNameOfIdentity) {
22         if (qNameOfIdentity == null) {
23             throw new NullPointerException("Parameter " + QNAME_ATTR_NAME + " is null");
24         }
25         this.qNameOfIdentity = qNameOfIdentity;
26     }
27
28     public String getqNameOfIdentity() {
29         return qNameOfIdentity;
30     }
31
32     public <T extends BaseIdentity> Class<? extends T> resolveIdentity(DependencyResolver resolver, Class<T> baseIdentity) {
33         return resolver.resolveIdentity(this, baseIdentity);
34     }
35
36     public <T extends BaseIdentity> void validateIdentity(DependencyResolver resolver, Class<T> baseIdentity, JmxAttribute jmxAttribute) {
37         resolver.validateIdentity(this, baseIdentity, jmxAttribute);
38     }
39
40     @Override
41     public String toString() {
42         final StringBuffer sb = new StringBuffer("IdentityAttributeRef{");
43         sb.append("qNameOfIdentity='").append(qNameOfIdentity).append('\'');
44         sb.append('}');
45         return sb.toString();
46     }
47
48     @Override
49     public boolean equals(Object o) {
50         if (this == o) {
51             return true;
52         }
53         if (!(o instanceof IdentityAttributeRef)) {
54             return false;
55         }
56
57         IdentityAttributeRef that = (IdentityAttributeRef) o;
58
59         if (!qNameOfIdentity.equals(that.qNameOfIdentity)) {
60             return false;
61         }
62
63         return true;
64     }
65
66     @Override
67     public int hashCode() {
68         return qNameOfIdentity.hashCode();
69     }
70
71 }