@SuppressWarnings("unchecked") private static Method findAccessor(Class clazz, String name, Class[] params, int index) throws BulkAccessorException { try { final Method method = clazz.getDeclaredMethod( name, params ); if ( Modifier.isPrivate( method.getModifiers() ) ) { throw new BulkAccessorException( "private property", index ); } return method; } catch ( NoSuchMethodException e ) { throw new BulkAccessorException( "cannot find an accessor", index ); } } }
private static String setterName(Throwable t, BulkAccessor accessor) { if (t instanceof BulkAccessorException ) { return accessor.getSetters()[ ( (BulkAccessorException) t ).getIndex() ]; } else { return "?"; } }
/** * Constructs an exception. */ public BulkAccessorException(String message) { super(message); index = -1; initCause(null); }
/** * Constructs an exception. * * @param index the index of the property that causes an exception. */ public BulkAccessorException(Throwable cause, int index) { this("Property " + index); this.index = index; initCause(cause); }
private static String getterName(Throwable t, BulkAccessor accessor) { if (t instanceof BulkAccessorException ) { return accessor.getGetters()[ ( (BulkAccessorException) t ).getIndex() ]; } else { return "?"; } } }
private static void findAccessors( Class clazz, String[] getterNames, String[] setterNames, Class[] types, Method[] getters, Method[] setters) { final int length = types.length; if ( setterNames.length != length || getterNames.length != length ) { throw new BulkAccessorException( "bad number of accessors" ); } final Class[] getParam = new Class[0]; final Class[] setParam = new Class[1]; for ( int i = 0; i < length; i++ ) { if ( getterNames[i] != null ) { final Method getter = findAccessor( clazz, getterNames[i], getParam, i ); if ( getter.getReturnType() != types[i] ) { throw new BulkAccessorException( "wrong return type: " + getterNames[i], i ); } getters[i] = getter; } if ( setterNames[i] != null ) { setParam[0] = types[i]; setters[i] = findAccessor( clazz, setterNames[i], setParam, i ); } } }
/** * Constructs an exception. */ public BulkAccessorException(String message) { super(message); index = -1; initCause(null); }
int index = 0; if (t instanceof BulkAccessorException) { index = ( (BulkAccessorException) t ).getIndex();
BulkAccessor create() { final Method[] getters = new Method[getterNames.length]; final Method[] setters = new Method[setterNames.length]; findAccessors( targetBean, getterNames, setterNames, types, getters, setters ); final Class beanClass; try { final ClassFile classfile = make( getters, setters ); final ClassLoader loader = this.getClassLoader(); if ( writeDirectory != null ) { FactoryHelper.writeFile( classfile, writeDirectory ); } beanClass = FactoryHelper.toClass( classfile, null, loader, getDomain() ); return (BulkAccessor) this.newInstance( beanClass ); } catch ( Exception e ) { throw new BulkAccessorException( e.getMessage(), e ); } }
/** * Constructs an exception. * * @param index the index of the property that causes an exception. */ public BulkAccessorException(Throwable cause, int index) { this("Property " + index); this.index = index; initCause(cause); }
private static String setterName(Throwable t, BulkAccessor accessor) { if (t instanceof BulkAccessorException ) { return accessor.getSetters()[ ( (BulkAccessorException) t ).getIndex() ]; } else { return "?"; } }
@SuppressWarnings("unchecked") private static Method findAccessor(Class clazz, String name, Class[] params, int index) throws BulkAccessorException { try { final Method method = clazz.getDeclaredMethod( name, params ); if ( Modifier.isPrivate( method.getModifiers() ) ) { throw new BulkAccessorException( "private property", index ); } return method; } catch ( NoSuchMethodException e ) { throw new BulkAccessorException( "cannot find an accessor", index ); } } }
/** * Constructs an exception. */ public BulkAccessorException(String message, Throwable cause) { super(message); index = -1; initCause(cause); }
private static String getterName(Throwable t, BulkAccessor accessor) { if (t instanceof BulkAccessorException ) { return accessor.getGetters()[ ( (BulkAccessorException) t ).getIndex() ]; } else { return "?"; } } }
private static Method findAccessor( Class clazz, String name, Class[] params, int index) throws BulkAccessorException { try { Method method = clazz.getDeclaredMethod( name, params ); if ( Modifier.isPrivate( method.getModifiers() ) ) { throw new BulkAccessorException( "private property", index ); } return method; } catch ( NoSuchMethodException e ) { throw new BulkAccessorException( "cannot find an accessor", index ); } } }
/** * Constructs an exception. */ public BulkAccessorException(String message, Throwable cause) { super(message); index = -1; initCause(cause); }
private static String setterName(Throwable t, BulkAccessor accessor) { if (t instanceof BulkAccessorException ) { return accessor.getSetters()[ ( (BulkAccessorException) t ).getIndex() ]; } else { return "?"; } }
private static Method findAccessor( Class clazz, String name, Class[] params, int index) throws BulkAccessorException { try { Method method = clazz.getDeclaredMethod( name, params ); if ( Modifier.isPrivate( method.getModifiers() ) ) { throw new BulkAccessorException( "private property", index ); } return method; } catch ( NoSuchMethodException e ) { throw new BulkAccessorException( "cannot find an accessor", index ); } } }
private static String getterName(Throwable t, BulkAccessor accessor) { if (t instanceof BulkAccessorException ) { return accessor.getGetters()[ ( (BulkAccessorException) t ).getIndex() ]; } else { return "?"; } } }
private static void findAccessors( Class clazz, String[] getterNames, String[] setterNames, Class[] types, Method[] getters, Method[] setters) { int length = types.length; if ( setterNames.length != length || getterNames.length != length ) { throw new BulkAccessorException( "bad number of accessors" ); } Class[] getParam = new Class[0]; Class[] setParam = new Class[1]; for ( int i = 0; i < length; i++ ) { if ( getterNames[i] != null ) { Method getter = findAccessor( clazz, getterNames[i], getParam, i ); if ( getter.getReturnType() != types[i] ) { throw new BulkAccessorException( "wrong return type: " + getterNames[i], i ); } getters[i] = getter; } if ( setterNames[i] != null ) { setParam[0] = types[i]; setters[i] = findAccessor( clazz, setterNames[i], setParam, i ); } } }