private static String loadSoleArgumentKey(StepDescriptor d) { try { String[] names = new ClassDescriptor(d.clazz).loadConstructorParamNames(); return names.length == 1 ? names[0] : null; } catch (NoStaplerConstructorException e) { return null; } }
private static String[] loadConstructorParamNames(Class<?> clazz) { return new ClassDescriptor(clazz).loadConstructorParamNames(); }
private static String[] loadConstructorParamNames(Class<?> clazz) { return new ClassDescriptor(clazz).loadConstructorParamNames(); }
new ClassDescriptor(type).loadConstructorParamNames();
new ClassDescriptor(type).loadConstructorParamNames();
public <T> T bindParameters(Class<T> type, String prefix, int index) { String[] names = new ClassDescriptor(type).loadConstructorParamNames(); // the actual arguments to invoke the constructor with. Object[] args = new Object[names.length]; // constructor Constructor<T> c = findConstructor(type, names.length); Class[] types = c.getParameterTypes(); // convert parameters for( int i=0; i<names.length; i++ ) { String[] values = getParameterValues(prefix + names[i]); String param; if(values!=null) param = values[index]; else param = null; Converter converter = Stapler.lookupConverter(types[i]); if (converter==null) throw new IllegalArgumentException("Unable to convert to "+types[i]); args[i] = converter.convert(types[i],param); } return invokeConstructor(c, args); }
public <T> T bindParameters(Class<T> type, String prefix, int index) { String[] names = new ClassDescriptor(type).loadConstructorParamNames(); // the actual arguments to invoke the constructor with. Object[] args = new Object[names.length]; // constructor Constructor<T> c = findConstructor(type, names.length); Class[] types = c.getParameterTypes(); // convert parameters for( int i=0; i<names.length; i++ ) { String[] values = getParameterValues(prefix + names[i]); String param; if(values!=null) param = values[index]; else param = null; Converter converter = Stapler.lookupConverter(types[i]); if (converter==null) throw new IllegalArgumentException("Unable to convert to "+types[i]); args[i] = converter.convert(types[i],param); } return invokeConstructor(c, args); }
/** * Called after the actual type of the binding is figured out. */ private Object instantiate(Class actualType, JSONObject j) { Object r = bindInterceptor.instantiate(actualType,j); if (r!=BindInterceptor.DEFAULT) return r; for (BindInterceptor bi : getWebApp().bindInterceptors) { r = bi.instantiate(actualType,j); if (r!=BindInterceptor.DEFAULT) return r; } if (actualType==JSONObject.class || actualType==JSON.class) return actualType.cast(j); String[] names = new ClassDescriptor(actualType).loadConstructorParamNames(); // the actual arguments to invoke the constructor with. Object[] args = new Object[names.length]; // constructor Constructor c = findConstructor(actualType, names.length); Class[] types = c.getParameterTypes(); Type[] genTypes = c.getGenericParameterTypes(); // convert parameters for( int i=0; i<names.length; i++ ) { try { args[i] = bindJSON(genTypes[i],types[i],j.get(names[i])); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Failed to convert the "+names[i]+" parameter of the constructor "+c,e); } } Object o = injectSetters(invokeConstructor(c, args), j, Arrays.asList(names)); o = bindResolve(o,j); return o; }
/** * Called after the actual type of the binding is figured out. */ private Object instantiate(Class actualType, JSONObject j) { Object r = bindInterceptor.instantiate(actualType,j); if (r!=BindInterceptor.DEFAULT) return r; for (BindInterceptor bi : getWebApp().bindInterceptors) { r = bi.instantiate(actualType,j); if (r!=BindInterceptor.DEFAULT) return r; } if (actualType==JSONObject.class || actualType==JSON.class) return actualType.cast(j); String[] names = new ClassDescriptor(actualType).loadConstructorParamNames(); // the actual arguments to invoke the constructor with. Object[] args = new Object[names.length]; // constructor Constructor c = findConstructor(actualType, names.length); Class[] types = c.getParameterTypes(); Type[] genTypes = c.getGenericParameterTypes(); // convert parameters for( int i=0; i<names.length; i++ ) { try { args[i] = bindJSON(genTypes[i],types[i],j.get(names[i])); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Failed to convert the "+names[i]+" parameter of the constructor "+c,e); } } Object o = injectSetters(invokeConstructor(c, args), j, Arrays.asList(names)); o = bindResolve(o,j); return o; }