Example usage for org.hibernate.internal.util ReflectHelper isPublic

List of usage examples for org.hibernate.internal.util ReflectHelper isPublic

Introduction

In this page you can find the example usage for org.hibernate.internal.util ReflectHelper isPublic.

Prototype

public static boolean isPublic(Class clazz, Member member) 

Source Link

Document

Is this member publicly accessible.

Usage

From source file:org.grails.orm.hibernate.proxy.GroovyAwareJavassistLazyInitializer.java

License:Apache License

public Object invoke(final Object proxy, final Method thisMethod, final Method proceed, final Object[] args)
        throws Throwable {
    // while constructor is running
    if (thisMethod.getName().equals("getHibernateLazyInitializer")) {
        return this;
    }//from   w w  w  . ja va  2  s. c  om

    Object result = groovyObjectMethodHandler.handleInvocation(proxy, thisMethod, args);
    if (groovyObjectMethodHandler.wasHandled(result)) {
        return result;
    }

    if (constructed) {
        try {
            result = invoke(thisMethod, args, proxy);
        } catch (Throwable t) {
            throw new Exception(t.getCause());
        }
        if (result == INVOKE_IMPLEMENTATION) {
            Object target = getImplementation();
            final Object returnValue;
            try {
                if (ReflectHelper.isPublic(persistentClass, thisMethod)) {
                    if (!thisMethod.getDeclaringClass().isInstance(target)) {
                        throw new ClassCastException(target.getClass().getName());
                    }
                    returnValue = thisMethod.invoke(target, args);
                } else {
                    if (!thisMethod.isAccessible()) {
                        thisMethod.setAccessible(true);
                    }
                    returnValue = thisMethod.invoke(target, args);
                }
                return returnValue == target ? proxy : returnValue;
            } catch (InvocationTargetException ite) {
                throw ite.getTargetException();
            }
        }
        return result;
    }

    return proceed.invoke(proxy, args);
}