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