variables.factory = new Factory() class Factory { def _construct(Object[] args) { Class[] types = new Class[args.size() / 2] Object[] params = new Object[args.size() / 2] for (int i = 1; i < args.size(); i += 2) { if (args[i] == null || args[i] == "") { args[i] = args[i + 1].getClass() } else if (args[i] instanceof java.lang.Class) { // already set } else if (args[i] instanceof java.lang.CharSequence) { args[i] = getClass().forName(args[i].toString()) } else { args[i] = args[i].getClass() } types[(i - 1).intdiv(2)] = args[i] params[(i - 1).intdiv(2)] = args[i + 1] } getClass().getClassLoader().loadClass(args[0]).getConstructor(types).newInstance(params) } // CFML is stupid and doesn't understand varargs def construct(a) { _construct(a) } def construct(a,b,c) { _construct(a,b,c) } def construct(a,b,c,d,e) { _construct(a,b,c,d,e) } def construct(a,b,c,d,e,f,g) { _construct(a,b,c,d,e,f,g) } def construct(a,b,c,d,e,f,g,h,i) { _construct(a,b,c,d,e,f,g,h,i) } def construct(a,b,c,d,e,f,g,h,i,j,k) { _construct(a,b,c,d,e,f,g,h,i,j,k) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w) } def construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y) { _construct(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y) } }