/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2005-2016 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.db;

import java.net.URL;
import java.net.URLClassLoader;

/**
 * The class loader for domain objects.
 *
 * @todo implement code enhancer
 * @todo implement dynamic fields
 * @todo implement class reload
 */
public class JpaClassLoader extends URLClassLoader {

	public JpaClassLoader() {
		super(new URL[0], Thread.currentThread().getContextClassLoader());
	}

	@Override
	protected Class<?> findClass(String name) throws ClassNotFoundException {
		try {
			return super.findClass(name);
		} catch (ClassNotFoundException e) {
			Class<?> model = findModelClass(name);
			if (model != null)
				return model;
			throw e;
		}
	}

	/**
	 * try to find domain or repository class in cache.
	 *
	 */
	private Class<?> findModelClass(String className) {
		if (!className.startsWith("java.lang.") || className.contains("$"))
			return null;
		String name = className.substring(className.lastIndexOf('.') + 1);
		Class<?> klass = JpaScanner.findRepository(name);
		if (klass == null) {
			return JpaScanner.findModel(name);
		}
		return klass;
	}
}

@@ -726,207 +726,55 @@
 b;%0A%0A
-import java.net.URL;%0Aimport java.net.URLClassLoader;%0A%0A/**%0A * The class loader for domain objects.%0A *%0A * @todo implement code enhancer%0A * @todo implement dynamic fields%0A * @todo implement class reload
+/**%0A * The class loader for domain objects.%0A * 
 %0A */
@@ -810,19 +810,16 @@
 extends 
-URL
 ClassLoa
@@ -858,26 +858,13 @@
 %7B%0A%09%09
-super(new URL%5B0%5D, 
+this(
 Thre
@@ -912,16 +912,82 @@
 ));%0A%09%7D%0A%0A
+%09public JpaClassLoader(ClassLoader parent) %7B%0A%09%09super(parent);%0A%09%7D%0A%0A
 %09@Overri
@@ -1147,16 +1147,22 @@
 e) %7B%0A%09%09%09
+final 
 Class%3C?%3E
@@ -1213,16 +1213,18 @@
 != null)
+ %7B
 %0A%09%09%09%09ret
@@ -1234,16 +1234,21 @@
  model;%0A
+%09%09%09%7D%0A
 %09%09%09throw
@@ -1448,16 +1448,18 @@
 ns(%22$%22))
+ %7B
 %0A%09%09%09retu
@@ -1469,16 +1469,26 @@
 null;%0A%09%09
+%7D%0A%09%09final 
 String n
@@ -1548,16 +1548,22 @@
 + 1);%0A%09%09
+final 
 Class%3C?%3E

Refactor jpa class loader