/** * Creates an instance of {@link RepositoryBrowser} from a form submission. * * @deprecated since 2008-06-19. * Use {@link #createInstance(Class, StaplerRequest, JSONObject, String)}. */ @Deprecated public static <T extends RepositoryBrowser> T createInstance(Class<T> type, StaplerRequest req, String fieldName) throws FormException { List<Descriptor<RepositoryBrowser<?>>> list = filter(type); String value = req.getParameter(fieldName); if(value==null || value.equals("auto")) return null; // TODO: There was a TODO in the original code, which presumes passing something meaningful to the newInstance() JSON param // Now we just pass empty JSON in order to make the code compliant with the defined interface final JSONObject emptyJSON = new JSONObject(); return type.cast(list.get(Integer.parseInt(value)).newInstance(req, emptyJSON)); }
/** * {@inheritDoc} * * @return * null to avoid setting an instance of {@link JobProperty} to the target project (or just use {@link OptionalJobProperty}) */ @Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { // JobPropertyDescriptors are bit different in that we allow them even without any user-visible configuration parameter, // so replace the lack of form data by an empty one. if(formData.isNullObject()) formData=new JSONObject(); return super.newInstance(req, formData); }
private static List<ListViewColumn> createDefaultInitialColumnList(List<Descriptor<ListViewColumn>> descriptors) { // OK, set up default list of columns: // create all instances ArrayList<ListViewColumn> r = new ArrayList<ListViewColumn>(); final JSONObject emptyJSON = new JSONObject(); for (Descriptor<ListViewColumn> d : descriptors) try { if (d instanceof ListViewColumnDescriptor) { ListViewColumnDescriptor ld = (ListViewColumnDescriptor) d; if (!ld.shownByDefault()) { continue; // skip this } } ListViewColumn lvc = d.newInstance(null, emptyJSON); if (!lvc.shownByDefault()) { continue; // skip this } r.add(lvc); } catch (FormException e) { LOGGER.log(Level.WARNING, "Failed to instantiate "+d.clazz,e); } return r; }
protected final <T extends Describable<T>> List<T> buildDescribable(StaplerRequest req, List<? extends Descriptor<T>> descriptors) throws FormException, ServletException { JSONObject data = req.getSubmittedForm(); List<T> r = new Vector<T>(); for (Descriptor<T> d : descriptors) { String safeName = d.getJsonSafeClassName(); if (req.getParameter(safeName) != null) { T instance = d.newInstance(req, data.getJSONObject(safeName)); r.add(instance); } } return r; }
@Override public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) { if (jsonSource instanceof JSONObject) { JSONObject json = (JSONObject) jsonSource; if (isApplicable(targetTypeErasure, json)) { LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {targetTypeErasure.getName(), json}); try { return Jenkins.getActiveInstance().getDescriptor(targetTypeErasure).newInstance(Stapler.getCurrentRequest(), json); } catch (Exception x) { LOGGER.log(Level.WARNING, "falling back to default instantiation " + targetTypeErasure.getName() + " " + json, x); } } } else { LOGGER.log(Level.FINER, "ignoring non-object {0}", jsonSource); } return oldInterceptor.onConvert(targetType, targetTypeErasure, jsonSource); }
@Override public Object instantiate(Class actualType, JSONObject json) { if (isApplicable(actualType, json)) { LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {actualType.getName(), json}); try { final Descriptor descriptor = Jenkins.getActiveInstance().getDescriptor(actualType); if (descriptor != null) { return descriptor.newInstance(Stapler.getCurrentRequest(), json); } else { LOGGER.log(Level.WARNING, "Descriptor not found. Falling back to default instantiation " + actualType.getName() + " " + json); } } catch (Exception x) { LOGGER.log(Level.WARNING, "falling back to default instantiation " + actualType.getName() + " " + json, x); // If nested objects are not using newInstance, bindJSON will wind up throwing the same exception anyway, // so logging above will result in a duplicated stack trace. // However if they *are* then this is the only way to find errors in that newInstance. // Normally oldInterceptor.instantiate will just return DEFAULT, not actually do anything, // so we cannot try calling the default instantiation and then decide which problem to report. } } return oldInterceptor.instantiate(actualType, json); }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. * @param config Submitted configuration for Radio List * @return new instance or {@code null} if none was selected in the radio list * @throws FormException Data submission error */ @CheckForNull public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }
return verifyNewInstance(newInstance(req)); } else { if (req==null) {
items.add(d.newInstance(req, jo)); } else { LOGGER.log(Level.WARNING, "Received unexpected form data element: {0}", jo);
instance = (T)((ReconfigurableDescribable)existing).reconfigure(req,o); else instance = d.newInstance(req, o); } else { if (existing instanceof ReconfigurableDescribable)
@Override public CreationMating newInstance( StaplerRequest req, JSONObject formData) throws FormException { CreationMating ref = super.newInstance(req, formData); return ref; }
public static <T extends Describable<T>> List<T> newInstancesFromHeteroList(StaplerRequest req, Object formData, Collection<? extends Descriptor<T>> descriptors) throws FormException { List<T> items = new ArrayList<T>(); if (formData != null) { for (Object o : JSONArray.fromObject(formData)) { JSONObject jo = (JSONObject) o; String kind = jo.getString("kind"); items.add(find(descriptors, kind).newInstance(req, jo)); } } return items; }
private static void readItem(StaplerRequest req, JSONObject obj, List<SCM> dest) throws FormException { String staplerClass = obj.getString("stapler-class"); Descriptor<SCM> d = (Descriptor<SCM>) Hudson.getInstance().getDescriptor(staplerClass); dest.add(d.newInstance(req, obj)); } }
@Override public T newInstance(StaplerRequest req) throws FormException { initPython(); if (pexec.isImplemented(10)) { return (T) pexec.execPython("new_instance", req); } else { return super.newInstance(req); } }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }
/** * Creates a new instance of a {@link Describable} from the structured form * submission data posted by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if (config.isNullObject()) { return null; // none was selected } int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(), config); }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }