Binding2 runtime - Codecs impl #2
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / java / org / opendaylight / mdsal / binding / javav2 / dom / codec / impl / context / base / MissingClassInLoadingStrategyException.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.base;
10
11 import com.google.common.annotations.Beta;
12 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.MissingSchemaException;
13 import org.opendaylight.mdsal.binding.javav2.generator.api.ClassLoadingStrategy;
14
15 /**
16  * Thrown when user schema for supplied binding class is available in present schema context, but
17  * binding class itself is not known to codecs because backing class loading strategy did not
18  * provided it.
19  */
20 @Beta
21 public class MissingClassInLoadingStrategyException extends MissingSchemaException {
22
23     private static final long serialVersionUID = 1L;
24
25     protected MissingClassInLoadingStrategyException(final String msg, final Throwable cause) {
26         super(msg, cause);
27     }
28
29     public static void check(final ClassLoadingStrategy strategy, final Class<?> childClass) {
30         try {
31             strategy.loadClass(childClass.getName());
32         } catch (final ClassNotFoundException e) {
33             final String message =
34                     String.format("User supplied class %s is not available in %s.", childClass.getName(), strategy);
35             throw new MissingClassInLoadingStrategyException(message, e);
36         }
37     }
38
39 }