/** * Creates a new instance of <code>BulkAccessor</code>. * The created instance provides methods for setting/getting * specified properties at once. * * @param beanClass the class of the JavaBeans accessed * through the created object. * @param getters the names of setter methods for specified properties. * @param setters the names of getter methods for specified properties. * @param types the types of specified properties. * * @return The created BulkAccessor */ public static BulkAccessor create( Class beanClass, String[] getters, String[] setters, Class[] types) { return new BulkAccessorFactory( beanClass, getters, setters, types ).create(); } }
private ClassFile make(Method[] getters, Method[] setters) throws CannotCompileException { String className = targetBean.getName(); // set the name of bulk accessor. className = className + "_$$_bulkaccess_" + counter++; if ( className.startsWith( "java." ) ) { className = PACKAGE_NAME_PREFIX + className; } final ClassFile classfile = new ClassFile( false, className, BULKACESSOR_CLASS_NAME ); classfile.setAccessFlags( AccessFlag.PUBLIC ); addDefaultConstructor( classfile ); addGetter( classfile, getters ); addSetter( classfile, setters ); return classfile; }
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 ); } } }
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 ); } }
this.addUnwrapper( code, setterParamType );
BulkAccessor create() { Method[] getters = new Method[getterNames.length]; Method[] setters = new Method[setterNames.length]; findAccessors( targetBean, getterNames, setterNames, types, getters, setters ); Class beanClass; try { ClassFile classfile = make( getters, setters ); ClassLoader loader = this.getClassLoader(); if ( writeDirectory != null ) { FactoryHelper.writeFile( classfile, writeDirectory ); } beanClass = FactoryHelper.toClass( classfile, loader, getDomain() ); return ( BulkAccessor ) this.newInstance( beanClass ); } catch ( Exception e ) { throw new BulkAccessorException( e.getMessage(), e ); } }
this.addUnwrapper( classfile, code, setterParamType );
BulkAccessor create() { Method[] getters = new Method[getterNames.length]; Method[] setters = new Method[setterNames.length]; findAccessors( targetBean, getterNames, setterNames, types, getters, setters ); Class beanClass; try { ClassFile classfile = make( getters, setters ); ClassLoader loader = this.getClassLoader(); if ( writeDirectory != null ) { FactoryHelper.writeFile( classfile, writeDirectory ); } beanClass = FactoryHelper.toClass( classfile, loader, getDomain() ); return ( BulkAccessor ) this.newInstance( beanClass ); } catch ( Exception e ) { throw new BulkAccessorException( e.getMessage(), e ); } }
private ClassFile make(Method[] getters, Method[] setters) throws CannotCompileException { String className = targetBean.getName(); // set the name of bulk accessor. className = className + "_$$_bulkaccess_" + counter++; if ( className.startsWith( "java." ) ) { className = PACKAGE_NAME_PREFIX + className; } final ClassFile classfile = new ClassFile( false, className, BULKACESSOR_CLASS_NAME ); classfile.setAccessFlags( AccessFlag.PUBLIC ); addDefaultConstructor( classfile ); addGetter( classfile, getters ); addSetter( classfile, setters ); return classfile; }
/** * Creates a new instance of <code>BulkAccessor</code>. * The created instance provides methods for setting/getting * specified properties at once. * * @param beanClass the class of the JavaBeans accessed * through the created object. * @param getters the names of setter methods for specified properties. * @param setters the names of getter methods for specified properties. * @param types the types of specified properties. */ public static BulkAccessor create( Class beanClass, String[] getters, String[] setters, Class[] types) { BulkAccessorFactory factory = new BulkAccessorFactory( beanClass, getters, setters, types ); return factory.create(); } }
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 ); } } }
this.addUnwrapper( classfile, code, setterParamType );
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 ); } }
private ClassFile make(Method[] getters, Method[] setters) throws CannotCompileException { String className = targetBean.getName(); // set the name of bulk accessor. className = className + "_$$_bulkaccess_" + counter++; if ( className.startsWith( "java." ) ) { className = "org.javassist.tmp." + className; } ClassFile classfile = new ClassFile( false, className, BULKACESSOR_CLASS_NAME ); classfile.setAccessFlags( AccessFlag.PUBLIC ); addDefaultConstructor( classfile ); addGetter( classfile, getters ); addSetter( classfile, setters ); return classfile; }
/** * Creates a new instance of <code>BulkAccessor</code>. * The created instance provides methods for setting/getting * specified properties at once. * * @param beanClass the class of the JavaBeans accessed * through the created object. * @param getters the names of setter methods for specified properties. * @param setters the names of getter methods for specified properties. * @param types the types of specified properties. */ public static BulkAccessor create( Class beanClass, String[] getters, String[] setters, Class[] types) { BulkAccessorFactory factory = new BulkAccessorFactory( beanClass, getters, setters, types ); return factory.create(); } }
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 ); } } }
this.addUnwrapper( code, setterParamType );
private ClassFile make(Method[] getters, Method[] setters) throws CannotCompileException { String className = targetBean.getName(); // set the name of bulk accessor. className = className + "_$$_bulkaccess_" + counter++; if ( className.startsWith( "java." ) ) { className = "org.javassist.tmp." + className; } ClassFile classfile = new ClassFile( false, className, BULKACESSOR_CLASS_NAME ); classfile.setAccessFlags( AccessFlag.PUBLIC ); addDefaultConstructor( classfile ); addGetter( classfile, getters ); addSetter( classfile, setters ); return classfile; }
/** * Creates a new instance of <code>BulkAccessor</code>. * The created instance provides methods for setting/getting * specified properties at once. * * @param beanClass the class of the JavaBeans accessed * through the created object. * @param getters the names of setter methods for specified properties. * @param setters the names of getter methods for specified properties. * @param types the types of specified properties. * * @return The created BulkAccessor */ public static BulkAccessor create( Class beanClass, String[] getters, String[] setters, JavaTypeDescriptor[] types) { return new BulkAccessorFactory( beanClass, getters, setters, types ).create(); } }
private static void findAccessors( Class clazz, String[] getterNames, String[] setterNames, JavaTypeDescriptor[] 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].getJavaType() ) { throw new BulkAccessorException( "wrong return type: " + getterNames[i], i ); } getters[i] = getter; } if ( setterNames[i] != null ) { setParam[0] = types[i].getJavaType(); setters[i] = findAccessor( clazz, setterNames[i], setParam, i ); } } }