/*
 * Copyright 2011 SpringSource
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.grails.plugins.tomcat;

import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

/**
 *
 * A class loader that searches the parent
 *
 * @author Graeme Rocher
 * @since 1.4
 */
public class ParentDelegatingClassLoader extends ClassLoader{

    private Method findClassMethod;

    protected ParentDelegatingClassLoader(ClassLoader parent) {
        super(parent);
        findClassMethod = ReflectionUtils.findMethod(ClassLoader.class, "findClass", String.class);
        ReflectionUtils.makeAccessible(findClassMethod);
    }

    @Override
    protected Class<?> findClass(String className) throws ClassNotFoundException {
        return (Class<?>) ReflectionUtils.invokeMethod(findClassMethod, getParent(), className);
    }
}

@@ -676,16 +676,68 @@
 Utils;%0A%0A
+import java.lang.reflect.InvocationTargetException;%0A
 import j
@@ -1318,85 +1318,287 @@
     
-return (Class%3C?%3E) ReflectionUtils.invokeMethod(findClassMethod, getParent(), 
+try %7B%0A            return (Class%3C?%3E) findClassMethod.invoke(getParent(), className);%0A        %7D catch (IllegalAccessException e) %7B%0A            throw new ClassNotFoundException(className);%0A        %7D catch (InvocationTargetException e) %7B%0A            throw new ClassNotFoundException(
 clas
@@ -1601,20 +1601,30 @@
 className);%0A
+        %7D%0A
     %7D%0A%7D%0A

fix for classloader issue when a class is not found