List of usage examples for org.springframework.beans BeanWrapper setPropertyValue
void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ProjectLayersPanel.java
private HelpDataModel getHelpContent() { HelpDataModel helpContent = new HelpDataModel(); BeanWrapper wrapper = new BeanWrapperImpl(helpContent); // get annotation preference from file system try {/*from w w w. ja va 2 s. c o m*/ for (Entry<Object, Object> entry : repository.loadHelpContents().entrySet()) { String property = entry.getKey().toString(); if (wrapper.isWritableProperty(property)) { if (HelpDataModel.class.getDeclaredField(property) .getGenericType() instanceof ParameterizedType) { List<String> value = Arrays .asList(StringUtils.replaceChars(entry.getValue().toString(), "[]", "").split(",")); if (!value.get(0).equals("")) { wrapper.setPropertyValue(property, value); } } else { wrapper.setPropertyValue(property, entry.getValue()); } } } } // no preference found catch (Exception e) { } return helpContent; }
From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ProjectLayersPanel.java
private String getHelpContent(String aField) { String helpFieldContent = ""; HelpDataModel helpContent = new HelpDataModel(); BeanWrapper wrapper = new BeanWrapperImpl(helpContent); // get annotation preference from file system try {/*www . j a v a 2s . c o m*/ for (Entry<Object, Object> entry : repository.loadHelpContents().entrySet()) { String property = entry.getKey().toString(); if (wrapper.isWritableProperty(property)) { if (HelpDataModel.class.getDeclaredField(property) .getGenericType() instanceof ParameterizedType) { List<String> value = Arrays .asList(StringUtils.replaceChars(entry.getValue().toString(), "[]", "").split(",")); if (!value.get(0).equals("")) { wrapper.setPropertyValue(property, value); } } else { if (property.equals(aField)) { helpFieldContent = entry.getValue().toString(); } wrapper.setPropertyValue(property, entry.getValue()); } } } } // no preference found catch (Exception e) { } return helpFieldContent; }
From source file:edu.duke.cabig.c3pr.web.ajax.CommonAjaxFacade.java
@SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null;/*from w w w .j a v a 2 s. c o m*/ try { dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { // only for nested props String[] individualProps = property.split("\\."); String temp = ""; for (int i = 0; i < individualProps.length - 1; i++) { temp += (i != 0 ? "." : "") + individualProps[i]; Object o = source.getPropertyValue(temp); if (destination.getPropertyValue(temp) == null) { try { destination.setPropertyValue(temp, o.getClass().newInstance()); } catch (BeansException e) { log.error(e.getMessage()); } catch (InstantiationException e) { log.error(e.getMessage()); } catch (IllegalAccessException e) { log.error(e.getMessage()); } } } destination.setPropertyValue(property, source.getPropertyValue(property)); } return dst; }
From source file:edu.duke.cabig.c3pr.web.ajax.InvestigatorAjaxFacade.java
@SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null;// w w w .j ava2 s . c o m try { // it doesn't seem like this cast should be necessary dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { destination.setPropertyValue(property, source.getPropertyValue(property)); } return dst; }
From source file:edu.duke.cabig.c3pr.web.ajax.ResearchStaffAjaxFacade.java
/** * Builds the reduced version of the passed in objects in order to pas a light weight version to the UI. * Used for auto-completers in general./*from www. ja va 2 s . c o m*/ * * @param <T> the generic type * @param src the src * @param properties the properties * @return the t */ @SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null; try { // it doesn't seem like this cast should be necessary dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { destination.setPropertyValue(property, source.getPropertyValue(property)); } return dst; }
From source file:edu.duke.cabig.c3pr.web.ajax.StudyAjaxFacade.java
@SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null;/* www . j a va 2 s .co m*/ try { // it doesn't seem like this cast should be necessary dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { // only for nested props String[] individualProps = property.split("\\."); String temp = ""; for (int i = 0; i < individualProps.length - 1; i++) { temp += (i != 0 ? "." : "") + individualProps[i]; Object o = source.getPropertyValue(temp); if (destination.getPropertyValue(temp) == null) { try { destination.setPropertyValue(temp, o.getClass().newInstance()); } catch (BeansException e) { log.error(e.getMessage()); } catch (InstantiationException e) { log.error(e.getMessage()); } catch (IllegalAccessException e) { log.error(e.getMessage()); } } } // for single and nested props destination.setPropertyValue(property, source.getPropertyValue(property)); } return dst; }
From source file:edu.duke.cabig.c3pr.web.ajax.UserAjaxFacade.java
@SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null;//from www . j a va2s.c o m try { // it doesn't seem like this cast should be necessary dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { // only for nested props String[] individualProps = property.split("\\."); String temp = ""; String myTemp = ""; try { for (int i = 0; i < individualProps.length - 1; i++) { temp += (i != 0 ? "." : "") + individualProps[i]; Object o = source.getPropertyValue(temp); if (temp.charAt(temp.length() - 1) == ']') { myTemp = temp.substring(0, temp.length() - 3); if (destination.getPropertyValue(myTemp) == null) { destination.setPropertyValue(myTemp, ArrayList.class.newInstance().add(o.getClass().newInstance())); } if (((ArrayList) destination.getPropertyValue(myTemp)).size() == 0) { ((ArrayList) destination.getPropertyValue(myTemp)).add(o.getClass().newInstance()); } } else { if (destination.getPropertyValue(temp) == null) { destination.setPropertyValue(temp, o.getClass().newInstance()); } } } } catch (BeansException e) { log.error(e.getMessage()); } catch (InstantiationException e) { log.error(e.getMessage()); } catch (IllegalAccessException e) { log.error(e.getMessage()); } // for single and nested props destination.setPropertyValue(property, source.getPropertyValue(property)); } /*for (String property : properties) { destination.setPropertyValue(property, source.getPropertyValue(property)); }*/ return dst; }
From source file:edu.northwestern.bioinformatics.studycalendar.web.admin.AdministerUserCommand.java
private void copyBoundProperties(User src, User dst) { BeanWrapper srcW = new BeanWrapperImpl(src); BeanWrapper dstW = new BeanWrapperImpl(dst); for (PropertyDescriptor srcProp : srcW.getPropertyDescriptors()) { if (srcProp.getReadMethod() == null || srcProp.getWriteMethod() == null) { continue; }// ww w .jav a2s.c o m Object srcValue = srcW.getPropertyValue(srcProp.getName()); if (srcValue != null) { dstW.setPropertyValue(srcProp.getName(), srcValue); } } }
From source file:gr.abiss.calipso.controller.AbstractServiceBasedRestController.java
protected void copyBeanProperties(final Object source, final Object target, final Iterable<String> properties) { final BeanWrapper src = new BeanWrapperImpl(source); final BeanWrapper trg = new BeanWrapperImpl(target); for (final String propertyName : properties) { trg.setPropertyValue(propertyName, src.getPropertyValue(propertyName)); }/*from w w w. j av a 2 s.c om*/ }
From source file:org.apache.syncope.client.console.pages.ReportletConfModalPage.java
public ReportletConfModalPage(final AbstractReportletConf reportletConf, final ModalWindow window, final PageReference pageRef) { this.reportletConf = reportletConf; final Form form = new Form(FORM); add(form);//from w ww . ja v a2 s . c o m propertiesContainer = new WebMarkupContainer("container"); propertiesContainer.setOutputMarkupId(true); form.add(propertiesContainer); name = new AjaxTextFieldPanel("name", "name", this.reportletConf == null ? new Model<String>() : new PropertyModel<String>(this.reportletConf, "name")); name.setOutputMarkupId(true); name.addRequiredLabel(); form.add(name); final AjaxDropDownChoicePanel<String> reportletClass = new AjaxDropDownChoicePanel<String>("reportletClass", "reportletClass", new IModel<String>() { private static final long serialVersionUID = -2316468110411802130L; @Override public String getObject() { return ReportletConfModalPage.this.reportletConf == null ? null : ReportletConfModalPage.this.reportletConf.getClass().getName(); } @Override public void setObject(final String object) { try { Class<?> reportletClass = Class.forName(object); ReportletConfModalPage.this.reportletConf = (AbstractReportletConf) reportletClass .newInstance(); propertiesContainer.replace(buildPropView()); } catch (Exception e) { LOG.error("Cannot find or initialize {}", object, e); } } @Override public void detach() { } }); reportletClass.setStyleSheet("long_dynamicsize"); reportletClass.setChoices(reportRestClient.getReportletConfClasses()); ((DropDownChoice) reportletClass.getField()).setNullValid(true); reportletClass.addRequiredLabel(); reportletClass.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = 5538299138211283825L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice) reportletClass.getField()).setNullValid(false); target.add(reportletClass.getField()); target.add(propertiesContainer); } }); form.add(reportletClass); propertiesContainer.add(buildPropView()); final AjaxButton submit = new AjaxButton(APPLY, new ResourceModel(APPLY)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final BeanWrapper wrapper = PropertyAccessorFactory .forBeanPropertyAccess(ReportletConfModalPage.this.reportletConf); wrapper.setPropertyValue("name", name.getField().getInput()); // Iterate over properties in order to find UserSearchPanel instances and manually update // this.reportletConf with select search criteria - this is needed because UserSearchPanel // does not comply with usual Wicket model paradigm. ReportletConfModalPage.this.propView.visitChildren(new IVisitor<Component, Void>() { @Override public void component(final Component component, final IVisit<Void> ivisit) { if (component instanceof UserSearchPanel) { // using component.getDefaultModelObjectAsString() to fetch field name (set above) wrapper.setPropertyValue(component.getDefaultModelObjectAsString(), ((UserSearchPanel) component).buildFIQL()); } } }); ((ReportModalPage) pageRef.getPage()) .setModalReportletConf(ReportletConfModalPage.this.reportletConf); window.close(target); } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; form.add(submit); final AjaxButton cancel = new ClearIndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL), pageRef) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); }