b4bd6eb6a7782af3aeeb98aec5f88aad3256b232
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / rpc / RpcContextIdentifier.java
1 /*
2  * Copyright (c) 2014 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.sal.binding.api.rpc;
9
10 import org.opendaylight.yangtools.concepts.Immutable;
11 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
12 import org.opendaylight.yangtools.yang.binding.RpcService;
13
14 public final  class RpcContextIdentifier implements Immutable{
15
16     public final Class<? extends RpcService> rpcService;
17     public final Class<? extends BaseIdentity> routingContext;
18
19     private RpcContextIdentifier(Class<? extends RpcService> rpcService, Class<? extends BaseIdentity> routingContext) {
20         this.rpcService = rpcService;
21         this.routingContext = routingContext;
22     }
23
24     public Class<? extends RpcService> getRpcService() {
25         return rpcService;
26     }
27
28     public Class<? extends BaseIdentity> getRoutingContext() {
29         return routingContext;
30     }
31
32     public static final RpcContextIdentifier contextForGlobalRpc(Class<? extends RpcService> serviceType) {
33         return new RpcContextIdentifier(serviceType, null);
34     }
35
36     public static final RpcContextIdentifier contextFor(Class<? extends RpcService> serviceType,Class<? extends BaseIdentity> routingContext) {
37         return new RpcContextIdentifier(serviceType, routingContext);
38     }
39
40     @Override
41     public int hashCode() {
42         final int prime = 31;
43         int result = 1;
44         result = prime * result + ((routingContext == null) ? 0 : routingContext.hashCode());
45         result = prime * result + ((rpcService == null) ? 0 : rpcService.hashCode());
46         return result;
47     }
48
49     @Override
50     public boolean equals(Object obj) {
51         if (this == obj)
52             return true;
53         if (obj == null)
54             return false;
55         if (getClass() != obj.getClass())
56             return false;
57         RpcContextIdentifier other = (RpcContextIdentifier) obj;
58         if (routingContext == null) {
59             if (other.routingContext != null)
60                 return false;
61         } else if (!routingContext.equals(other.routingContext))
62             return false;
63         if (rpcService == null) {
64             if (other.rpcService != null)
65                 return false;
66         } else if (!rpcService.equals(other.rpcService))
67             return false;
68         return true;
69     }
70
71 }