Bug 3821 - Augmentation codecs may be loaded after codec creation.
[mdsal.git] / code-generator / binding-data-codec / src / main / java / org / opendaylight / yangtools / binding / data / codec / impl / MissingClassInLoadingStrategyException.java
diff --git a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/MissingClassInLoadingStrategyException.java b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/MissingClassInLoadingStrategyException.java
new file mode 100644 (file)
index 0000000..aca197e
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.data.codec.impl;
+
+import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
+
+/**
+ *
+ * Thrown when user schema for supplied binding class is available in present schema context, but
+ * binding class itself is not known to codecs because backing class loading strategy did not
+ * provided it.
+ *
+ */
+public class MissingClassInLoadingStrategyException extends MissingSchemaException {
+
+    private static final long serialVersionUID = 1L;
+
+    protected MissingClassInLoadingStrategyException(final String msg, final Throwable cause) {
+        super(msg, cause);
+    }
+
+    public static void check(final ClassLoadingStrategy strategy, final Class<?> childClass) {
+        try {
+            strategy.loadClass(childClass.getName());
+        } catch (final ClassNotFoundException e) {
+            final String message =
+                    String.format("User supplied class %s is not available in %s.", childClass.getName(), strategy);
+            throw new MissingClassInLoadingStrategyException(message, e);
+        }
+    }
+
+}