public MethodAttributeAccess(String attributeName, Method method) { this.name = attributeName; try { ReflectHelper.ensureAccessibility( method ); } catch (Exception e) { this.method = null; return; } this.method = method; }
public FieldAttributeAccess(Field field) { this.name = field.getName(); try { ReflectHelper.ensureAccessibility( field ); } catch (Exception e) { this.field = null; return; } this.field = field; }
@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; }
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; }
public static Object getFieldByReflection(Object entity, String fieldName) { try { Field field = entity.getClass().getDeclaredField( fieldName ); ReflectHelper.ensureAccessibility( field ); return field.get( entity ); } catch (NoSuchFieldException | IllegalAccessException e) { fail( "Fail to get field '" + fieldName + "' in entity " + entity + ": " + e.getMessage() ); } return null; }
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 ); } } }
@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() + ")" ); } } }
@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 ); } } }
public static Field findField(Class containerClass, String propertyName) { if ( containerClass == null ) { throw new IllegalArgumentException( "Class on which to find field [" + propertyName + "] cannot be null" ); } else if ( containerClass == Object.class ) { throw new IllegalArgumentException( "Illegal attempt to locate field [" + propertyName + "] on Object.class" ); } Field field = locateField( containerClass, propertyName ); if ( field == null ) { throw new PropertyNotFoundException( String.format( Locale.ROOT, "Could not locate field name [%s] on class [%s]", propertyName, containerClass.getName() ) ); } ensureAccessibility( field ); return field; }
public static Method setterMethodOrNull(final Class containerClass, final String propertyName, final Class propertyType) { Class checkClass = containerClass; Method setter = null; // check containerClass, and then its super types (if any) while ( setter == null && checkClass != null ) { if ( checkClass.equals( Object.class ) ) { break; } setter = setterOrNull( checkClass, propertyName, propertyType ); // if no setter found yet, check all implemented interfaces if ( setter == null ) { setter = setterOrNull( checkClass.getInterfaces(), propertyName, propertyType ); } else { ensureAccessibility( setter ); } checkClass = checkClass.getSuperclass(); } return setter; // might be null }
/** * Retrieve the default (no arg) constructor from the given class. * * @param clazz The class for which to retrieve the default ctor. * @return The default constructor. * @throws PropertyNotFoundException Indicates there was not publicly accessible, no-arg constructor (todo : why PropertyNotFoundException???) */ public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws PropertyNotFoundException { if ( isAbstractClass( clazz ) ) { return null; } try { Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE ); ensureAccessibility( constructor ); return constructor; } catch ( NoSuchMethodException nme ) { throw new PropertyNotFoundException( "Object class [" + clazz.getName() + "] must declare a default (no-argument) constructor" ); } }
public static Method findGetterMethod(Class containerClass, String propertyName) { Class checkClass = containerClass; Method getter = null; // check containerClass, and then its super types (if any) while ( getter == null && checkClass != null ) { if ( checkClass.equals( Object.class ) ) { break; } getter = getGetterOrNull( checkClass, propertyName ); // if no getter found yet, check all implemented interfaces if ( getter == null ) { getter = getGetterOrNull( checkClass.getInterfaces(), propertyName ); } checkClass = checkClass.getSuperclass(); } if ( getter == null ) { throw new PropertyNotFoundException( String.format( Locale.ROOT, "Could not locate getter method for property [%s#%s]", containerClass.getName(), propertyName ) ); } ensureAccessibility( getter ); return getter; }
ensureAccessibility( candidate ); constructor = candidate;
try { ReflectHelper.ensureAccessibility( field ); field.set( null, attribute );
final Constructor<? extends BeanContainer> ctor = containerClass.getDeclaredConstructor( ctorArgType ); try { ReflectHelper.ensureAccessibility( ctor ); return ctor.newInstance( ctorArgType.cast( beanManagerRef ) );
); ReflectHelper.ensureAccessibility( method ); if ( debugEnabled ) { log.debugf(
); ReflectHelper.ensureAccessibility( method ); if ( debugEnabled ) { log.debugf( ); ReflectHelper.ensureAccessibility( method ); if ( debugEnabled ) { log.debugf(
public MethodAttributeAccess(String attributeName, Method method) { this.name = attributeName; try { ReflectHelper.ensureAccessibility( method ); } catch (Exception e) { this.method = null; return; } this.method = method; }
public FieldAttributeAccess(Field field) { this.name = field.getName(); try { ReflectHelper.ensureAccessibility( field ); } catch (Exception e) { this.field = null; return; } this.field = field; }
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 ); } } }