Java Code Examples for org.hibernate.util.ReflectHelper#isPublic()

The following examples show how to use org.hibernate.util.ReflectHelper#isPublic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicPropertyAccessor.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static BasicSetter getSetterOrNull(Class theClass, String propertyName) {

		if (theClass==Object.class || theClass==null) return null;

		Method method = setterMethod(theClass, propertyName);

		if (method!=null) {
			if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
			return new BasicSetter(theClass, method, propertyName);
		}
		else {
			BasicSetter setter = getSetterOrNull( theClass.getSuperclass(), propertyName );
			if (setter==null) {
				Class[] interfaces = theClass.getInterfaces();
				for ( int i=0; setter==null && i<interfaces.length; i++ ) {
					setter=getSetterOrNull( interfaces[i], propertyName );
				}
			}
			return setter;
		}

	}
 
Example 2
Source File: BasicPropertyAccessor.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static BasicGetter getGetterOrNull(Class theClass, String propertyName) {

		if (theClass==Object.class || theClass==null) return null;

		Method method = getterMethod(theClass, propertyName);

		if (method!=null) {
			if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
			return new BasicGetter(theClass, method, propertyName);
		}
		else {
			BasicGetter getter = getGetterOrNull( theClass.getSuperclass(), propertyName );
			if (getter==null) {
				Class[] interfaces = theClass.getInterfaces();
				for ( int i=0; getter==null && i<interfaces.length; i++ ) {
					getter=getGetterOrNull( interfaces[i], propertyName );
				}
			}
			return getter;
		}
	}
 
Example 3
Source File: DirectPropertyAccessor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Field getField(Class clazz, String name) throws PropertyNotFoundException {
	if ( clazz==null || clazz==Object.class ) {
		throw new PropertyNotFoundException("field not found: " + name); 
	}
	Field field;
	try {
		field = clazz.getDeclaredField(name);
	}
	catch (NoSuchFieldException nsfe) {
		field = getField( clazz, clazz.getSuperclass(), name );
	}
	if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
	return field;
}
 
Example 4
Source File: DirectPropertyAccessor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Field getField(Class root, Class clazz, String name) throws PropertyNotFoundException {
	if ( clazz==null || clazz==Object.class ) {
		throw new PropertyNotFoundException("field [" + name + "] not found on " + root.getName()); 
	}
	Field field;
	try {
		field = clazz.getDeclaredField(name);
	}
	catch (NoSuchFieldException nsfe) {
		field = getField( root, clazz.getSuperclass(), name );
	}
	if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
	return field;
}
 
Example 5
Source File: CGLIBLazyInitializer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
	if ( constructed ) {
		Object result = invoke( method, args, proxy );
		if ( result == INVOKE_IMPLEMENTATION ) {
			Object target = getImplementation();
			try {
				final Object returnValue;
				if ( ReflectHelper.isPublic( persistentClass, method ) ) {
					if ( ! method.getDeclaringClass().isInstance( target ) ) {
						throw new ClassCastException( target.getClass().getName() );
					}
					returnValue = method.invoke( target, args );
				}
				else {
					if ( !method.isAccessible() ) {
						method.setAccessible( true );
					}
					returnValue = method.invoke( target, args );
				}
				return returnValue == target ? proxy : returnValue;
			}
			catch ( InvocationTargetException ite ) {
				throw ite.getTargetException();
			}
		}
		else {
			return result;
		}
	}
	else {
		// while constructor is running
		if ( method.getName().equals( "getHibernateLazyInitializer" ) ) {
			return this;
		}
		else {
			throw new LazyInitializationException( "unexpected case hit, method=" + method.getName() );
		}
	}
}
 
Example 6
Source File: JavassistLazyInitializer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Object invoke(
		final Object proxy,
		final Method thisMethod,
		final Method proceed,
		final Object[] args) throws Throwable {
	if ( this.constructed ) {
		Object result;
		try {
			result = this.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();
               }
		}
		else {
			return result;
		}
	}
	else {
		// while constructor is running
		if ( thisMethod.getName().equals( "getHibernateLazyInitializer" ) ) {
			return this;
		}
		else {
			return proceed.invoke( proxy, args );
		}
	}
}