Issue fix for config subsystem
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / util / LookupBeansUtil.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.manager.impl.util;
9
10 import java.util.Set;
11
12 import javax.management.InstanceNotFoundException;
13 import javax.management.ObjectName;
14
15 import org.opendaylight.controller.config.api.LookupRegistry;
16
17 public class LookupBeansUtil {
18
19     private LookupBeansUtil() {
20     }
21
22     public static ObjectName lookupConfigBean(LookupRegistry lookupRegistry,
23             String moduleName, String instanceName)
24             throws InstanceNotFoundException {
25         Set<ObjectName> objectNames = lookupRegistry.lookupConfigBeans(
26                 moduleName, instanceName);
27         if (objectNames.isEmpty()) {
28             throw new InstanceNotFoundException("No instance found");
29         } else if (objectNames.size() > 1) {
30             throw new InstanceNotFoundException("Too many instances found");
31         }
32         return objectNames.iterator().next();
33     }
34
35 }