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

The following examples show how to use org.hibernate.internal.util.ReflectHelper#ensureAccessibility() . 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: EntityTuplizerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Constructor<? extends EntityTuplizer> getProperConstructor(
		Class<? extends EntityTuplizer> clazz,
		Class[] constructorArgs) {
	Constructor<? extends EntityTuplizer> constructor = null;
	try {
		constructor = clazz.getDeclaredConstructor( constructorArgs );
		try {
			ReflectHelper.ensureAccessibility( constructor );
		}
		catch ( SecurityException e ) {
			constructor = null;
		}
	}
	catch ( NoSuchMethodException ignore ) {
	}

	return constructor;
}
 
Example 2
Source File: ComponentTuplizerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Constructor<? extends ComponentTuplizer> getProperConstructor(Class<? extends ComponentTuplizer> clazz) {
	Constructor<? extends ComponentTuplizer> constructor = null;
	try {
		constructor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
		try {
			ReflectHelper.ensureAccessibility( constructor );
		}
		catch ( SecurityException e ) {
			constructor = null;
		}
	}
	catch ( NoSuchMethodException ignore ) {
	}

	return constructor;
}
 
Example 3
Source File: SetterMethodImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Method resolveMethod() {
	try {
		final Method method = declaringClass.getDeclaredMethod( methodName, argumentType );
		ReflectHelper.ensureAccessibility( method );
		return method;
	}
	catch (NoSuchMethodException e) {
		throw new PropertyAccessSerializationException(
				"Unable to resolve setter method on deserialization : " + declaringClass.getName() + "#"
						+ methodName + "(" + argumentType.getName() + ")"
		);
	}
}
 
Example 4
Source File: GetterMethodImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Method resolveMethod() {
	try {
		final Method method = declaringClass.getDeclaredMethod( methodName );
		ReflectHelper.ensureAccessibility( method );
		return method;
	}
	catch (NoSuchMethodException e) {
		throw new PropertyAccessSerializationException(
				"Unable to resolve getter method on deserialization : " + declaringClass.getName() + "#" + methodName
		);
	}
}
 
Example 5
Source File: AbstractFieldSerialForm.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Field resolveField() {
	try {
		final Field field = declaringClass.getDeclaredField( fieldName );
		ReflectHelper.ensureAccessibility( field );
		return field;
	}
	catch (NoSuchFieldException e) {
		throw new PropertyAccessSerializationException(
				"Unable to resolve field on deserialization : " + declaringClass.getName() + "#" + fieldName
		);
	}
}
 
Example 6
Source File: PersistenceUtilHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public FieldAttributeAccess(Field field) {
	this.name = field.getName();
	try {
		ReflectHelper.ensureAccessibility( field );
	}
	catch (Exception e) {
		this.field = null;
		return;
	}
	this.field = field;
}
 
Example 7
Source File: PersistenceUtilHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public MethodAttributeAccess(String attributeName, Method method) {
	this.name = attributeName;
	try {
		ReflectHelper.ensureAccessibility( method );
	}
	catch (Exception e) {
		this.method = null;
		return;
	}
	this.method = method;
}
 
Example 8
Source File: CallbackBuilderLegacyImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked", "WeakerAccess"})
public Callback[] resolveEmbeddableCallbacks(Class entityClass, Property embeddableProperty, CallbackType callbackType, ReflectionManager reflectionManager) {

	final String embeddableClassName = embeddableProperty.getType().getReturnedClass().getName();
	final XClass embeddableXClass = reflectionManager.classForName( embeddableClassName );
	final Getter embeddableGetter = embeddableProperty.getGetter( entityClass );
	final boolean debugEnabled = log.isDebugEnabled();
	final List<Callback> callbacks = new ArrayList<>();
	final List<String> callbacksMethodNames = new ArrayList<>();
	XClass currentClazz = embeddableXClass;
	do {
		Callback callback = null;
		List<XMethod> methods = currentClazz.getDeclaredMethods();
		for ( final XMethod xMethod : methods ) {
			if ( xMethod.isAnnotationPresent( callbackType.getCallbackAnnotation() ) ) {
				Method method = reflectionManager.toMethod( xMethod );
				final String methodName = method.getName();
				if ( !callbacksMethodNames.contains( methodName ) ) {
					//overridden method, remove the superclass overridden method
					if ( callback == null ) {
						callback = new EmbeddableCallback( embeddableGetter, method, callbackType );
						Class returnType = method.getReturnType();
						Class[] args = method.getParameterTypes();
						if ( returnType != Void.TYPE || args.length != 0 ) {
							throw new RuntimeException(
									"Callback methods annotated on the bean class must return void and take no arguments: "
											+ callbackType.getCallbackAnnotation().getName() + " - " + xMethod
							);
						}
						ReflectHelper.ensureAccessibility( method );
						if ( debugEnabled ) {
							log.debugf(
									"Adding %s as %s callback for entity %s",
									methodName,
									callbackType.getCallbackAnnotation().getSimpleName(),
									embeddableXClass.getName()
							);
						}
						callbacks.add( 0, callback ); //superclass first
						callbacksMethodNames.add( 0, methodName );
					}
					else {
						throw new PersistenceException(
								"You can only annotate one callback method with "
										+ callbackType.getCallbackAnnotation().getName() + " in bean class: " + embeddableXClass.getName()
						);
					}
				}
			}
		}

		do {
			currentClazz = currentClazz.getSuperclass();
		}
		while ( currentClazz != null && !currentClazz.isAnnotationPresent( MappedSuperclass.class ) );
	}
	while ( currentClazz != null );

	return callbacks.toArray( new Callback[callbacks.size()] );
}