private static Field getField(Class clazz, String name) throws PropertyNotFoundException { if ( clazz==null || clazz==Object.class ) { throw new PropertyNotFoundException("field not found: " + name); // TODO: we should report what class we started searching for the property - right now it will always end on Object.class. } Field field; try { field = clazz.getDeclaredField(name); } catch (NoSuchFieldException nsfe) { field = getField( clazz.getSuperclass(), name ); } if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true); return field; }
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; }
public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { if ( isAbstractClass(clazz) ) return null; try { Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if ( !isPublic(clazz, constructor) ) { constructor.setAccessible(true); } return constructor; } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } }
public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { if ( isAbstractClass(clazz) ) return null; try { Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if ( !isPublic(clazz, constructor) ) { constructor.setAccessible(true); } return constructor; } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } }
final Object returnValue; try { if (ReflectHelper.isPublic(persistentClass, thisMethod)) { if (!thisMethod.getDeclaringClass().isInstance(target)) { throw new ClassCastException(target.getClass().getName());
public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException { final Constructor[] candidates = clazz.getConstructors(); for ( int i=0; i<candidates.length; i++ ) { final Constructor constructor = candidates[i]; final Class[] params = constructor.getParameterTypes(); if ( params.length==types.length ) { boolean found = true; for ( int j=0; j<params.length; j++ ) { final boolean ok = params[j].isAssignableFrom( types[j].getReturnedClass() ) || ( types[j] instanceof PrimitiveType && params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass() ); if (!ok) { found = false; break; } } if (found) { if ( !isPublic(clazz, constructor) ) constructor.setAccessible(true); return constructor; } } } throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() ); }
public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException { final Constructor[] candidates = clazz.getConstructors(); for ( int i=0; i<candidates.length; i++ ) { final Constructor constructor = candidates[i]; final Class[] params = constructor.getParameterTypes(); if ( params.length==types.length ) { boolean found = true; for ( int j=0; j<params.length; j++ ) { final boolean ok = params[j].isAssignableFrom( types[j].getReturnedClass() ) || ( types[j] instanceof PrimitiveType && params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass() ); if (!ok) { found = false; break; } } if (found) { if ( !isPublic(clazz, constructor) ) constructor.setAccessible(true); return constructor; } } } throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() ); }
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; } }
final Object returnValue; try { if ( ReflectHelper.isPublic( persistentClass, thisMethod ) ) { if ( ! thisMethod.getDeclaringClass().isInstance( target ) ) { throw new ClassCastException( target.getClass().getName() );
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; } }
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; } }
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; } }
Object target = getImplementation(); final Object returnValue; if ( ReflectHelper.isPublic(persistentClass, method) ) { returnValue = methodProxy.invoke(target, args);
try { final Object returnValue; if ( ReflectHelper.isPublic( persistentClass, method ) ) { if ( ! method.getDeclaringClass().isInstance( target ) ) { throw new ClassCastException( target.getClass().getName() );