89c9fa239625bff1a4144a765bbe89241aa1bd04
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / impl / GeneratedClassLoadingStrategy.java
1 /*
2  * Copyright (c) 2014 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.yangtools.sal.binding.generator.impl;
9
10 import org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils;
11 import org.opendaylight.yangtools.sal.binding.model.api.Type;
12
13 public abstract class GeneratedClassLoadingStrategy {
14
15     private static final GeneratedClassLoadingStrategy TCCL_STRATEGY = new TCCLClassLoadingStrategy();
16
17     public Class<?> loadClass(Type type) throws ClassNotFoundException {
18         return loadClass(type.getFullyQualifiedName());
19     }
20
21     public abstract Class<?> loadClass(String fullyQualifiedName) throws ClassNotFoundException;
22
23     public static final GeneratedClassLoadingStrategy getTCCLClassLoadingStrategy() {
24         return TCCL_STRATEGY;
25     }
26
27     private static final class TCCLClassLoadingStrategy extends GeneratedClassLoadingStrategy {
28
29         @Override
30         public Class<?> loadClass(String fullyQualifiedName) throws ClassNotFoundException {
31             return ClassLoaderUtils.loadClassWithTCCL(fullyQualifiedName);
32         }
33     }
34 }