Migrate entity ownership to JDT annotations
[mdsal.git] / entityownership / mdsal-eos-common-api / src / main / java / org / opendaylight / mdsal / eos / common / api / CandidateAlreadyRegisteredException.java
1 /*
2  * Copyright (c) 2015 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.mdsal.eos.common.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.concepts.Path;
14
15 /**
16  * Thrown when a Candidate has already been registered for a given Entity. This could be due to a component doing a
17  * duplicate registration or two different components within the same process trying to register a Candidate.
18  */
19 public class CandidateAlreadyRegisteredException extends Exception {
20     private static final long serialVersionUID = 1L;
21
22     private final @NonNull GenericEntity<?> entity;
23
24     public <T extends Path<T>> CandidateAlreadyRegisteredException(@NonNull final GenericEntity<T> entity) {
25         super("Candidate has already been registered for " + entity);
26         this.entity = requireNonNull(entity, "entity should not be null");
27     }
28
29     /**
30      * Gets the entity for which a Candidate has already been registered in the current process.
31      *
32      * @param <T> the instance identifier path type
33      *
34      * @return the entity.
35      */
36     @SuppressWarnings("unchecked")
37     public <T extends Path<T>> @NonNull GenericEntity<T> getEntity() {
38         return (GenericEntity<T>) entity;
39     }
40 }