Merge "Add Mycilla code to odlguice"
[odlguice.git] / inject / inject-guice / src / main / java / org / opendaylight / infrautils / inject / guice / AbstractCheckedModule.java
1 /*
2  * Copyright (c) 2017 Red Hat, 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.infrautils.inject.guice;
9
10 import com.google.inject.AbstractModule;
11 import com.google.inject.Binder;
12 import org.opendaylight.infrautils.inject.ModuleSetupRuntimeException;
13
14 /**
15  * Convenience Guice module support class with configure method that allows
16  * throwing checked exceptions, which are caught and re-thrown as unchecked
17  * {@link ModuleSetupRuntimeException}.
18  *
19  * @author Michael Vorburger.ch
20  */
21 public abstract class AbstractCheckedModule extends AbstractModule {
22
23     /**
24      * Configures a {@link Binder} via the exposed methods.
25      *
26      * @throws ModuleSetupRuntimeException if binding failed
27      */
28     @Override
29     @SuppressWarnings("checkstyle:IllegalCatch")
30     protected final void configure() throws ModuleSetupRuntimeException {
31         try {
32             checkedConfigure();
33         } catch (Exception e) {
34             throw new ModuleSetupRuntimeException(e);
35         }
36     }
37
38     protected abstract void checkedConfigure() throws Exception;
39
40 }