List of usage examples for org.springframework.beans BeanWrapper getPropertyValue
@Nullable
Object getPropertyValue(String propertyName) throws BeansException;
From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java
private static Object extractProperty(BeanWrapper wrappedItem, String propertyName) { if (wrappedItem.getWrappedInstance() == null) { return null; } else if (propertyName == null) { return wrappedItem.getWrappedInstance().toString(); } else {/*from w w w . ja v a 2s . c o m*/ return wrappedItem.getPropertyValue(propertyName); } }
From source file:gov.nih.nci.calims2.taglib.form.OptionManager.java
/** * Gets the id of the given option.//from w w w . j av a 2s. co m * * @param option The option rom which the id should be gotten * @return Gets the id of the given option. */ String getIdForOption(Object option) { if (option instanceof Option) { return ((Option) option).getId(); } if (option instanceof I18nEnumeration) { return ((I18nEnumeration) option).getName(); } BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(option); return wrapper.getPropertyValue(idProperty).toString(); }
From source file:gov.nih.nci.calims2.taglib.form.OptionManager.java
/** * Generates a new Option object for the given option that may be of any class. * //from w w w .jav a2 s . c o m * @param option The given option * @param requestContext The current request context. * @return The new Option generated. */ Option getOptionForOption(Object option, RequestContext requestContext) { if (option instanceof Option) { Option newOption = ((Option) option).clone(); if (newOption.getLabelKey() != null) { newOption.setLabel(requestContext.getMessage(newOption.getLabelKey())); } return newOption; } if (option instanceof I18nEnumeration) { I18nEnumeration enumValue = (I18nEnumeration) option; return new Option(enumValue.getName(), enumValue.getLocalizedValue(requestContext.getLocale())); } BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(option); return new Option(wrapper.getPropertyValue(idProperty).toString(), wrapper.getPropertyValue(labelProperty).toString()); }
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 ww w . j a va2 s .co m*/ }
From source file:grails.util.GrailsClassUtils.java
public static Object getPropertyOrStaticPropertyOrFieldValue(BeanWrapper ref, Object obj, String name) { if (ref.isReadableProperty(name)) { return ref.getPropertyValue(name); }//w ww .ja va 2s. co m // Look for public fields if (isPublicField(obj, name)) { return getFieldValue(obj, name); } // Look for statics Class<?> clazz = obj.getClass(); if (isStaticProperty(clazz, name)) { return getStaticPropertyValue(clazz, name); } return null; }
From source file:jp.terasoluna.fw.web.struts.actions.FileDownloadUtil.java
/** * uEU_E??[h?B//from w w w. j a v a2 s . c o m * * @param result _E??[hf?[^?CX^X?B * @param request NGXg?B * @param response X|X?B */ @SuppressWarnings("unchecked") public static void download(Object result, HttpServletRequest request, HttpServletResponse response) { List<AbstractDownloadObject> downloadList = new ArrayList<AbstractDownloadObject>(); if (result instanceof AbstractDownloadObject) { downloadList.add((AbstractDownloadObject) result); } else { BeanWrapper wrapper = new BeanWrapperImpl(result); PropertyDescriptor[] propertyDescriptors = wrapper.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod == null) { continue; } Class type = readMethod.getReturnType(); if (AbstractDownloadObject.class.isAssignableFrom(type)) { downloadList .add((AbstractDownloadObject) wrapper.getPropertyValue(propertyDescriptor.getName())); } } } if (downloadList.isEmpty()) { return; } // _E??[hIuWFNg???O if (downloadList.size() != 1) { throw new SystemException(new IllegalStateException("Too many AbstractDownloadObject properties."), TOO_MANY_DOWNLOAD_ERROR); } try { download(downloadList.get(0), request, response, true); } catch (SocketException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage(), e); } } catch (IOException e) { if (log.isErrorEnabled()) { log.error("IOException has occurred while downloading", e); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java
/** * Appends all property values on the given {@link StringBuilder} */// ww w . j a v a2 s.c om private void appendPropertyValues(final StringBuilder sb, final Object bean) { if (bean == null) { sb.append("<null>"); return; } else if (bean instanceof String) { sb.append(bean); return; } BeanWrapper bw = new BeanWrapperImpl(bean); boolean first = true; for (PropertyDescriptor desc : bw.getPropertyDescriptors()) { if (desc.getWriteMethod() == null) { // Only log readable and writable properties continue; } if (first) { first = false; } else { sb.append(", "); } String name = desc.getName(); sb.append(name).append('='); Object value = bw.getPropertyValue(name); appendValue(sb, FormatObject.maskIfNeeded(name, value)); } }
From source file:org.apache.syncope.client.console.pages.ReportletConfModalPage.java
private ListView<String> buildPropView() { LoadableDetachableModel<List<String>> propViewModel = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override/* www.ja v a 2 s.c om*/ protected List<String> load() { List<String> result = new ArrayList<String>(); if (ReportletConfModalPage.this.reportletConf != null) { for (Field field : ReportletConfModalPage.this.reportletConf.getClass().getDeclaredFields()) { if (!ArrayUtils.contains(EXCLUDE_PROPERTIES, field.getName())) { result.add(field.getName()); } } } return result; } }; propView = new ListView<String>("propView", propViewModel) { private static final long serialVersionUID = 9101744072914090143L; @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void populateItem(final ListItem<String> item) { final String fieldName = item.getModelObject(); Label label = new Label("key", fieldName); item.add(label); Field field = null; try { field = ReportletConfModalPage.this.reportletConf.getClass().getDeclaredField(fieldName); } catch (Exception e) { LOG.error("Could not find field {} in class {}", fieldName, ReportletConfModalPage.this.reportletConf.getClass(), e); } if (field == null) { return; } FormAttributeField annotation = field.getAnnotation(FormAttributeField.class); BeanWrapper wrapper = PropertyAccessorFactory .forBeanPropertyAccess(ReportletConfModalPage.this.reportletConf); Panel panel; if (String.class.equals(field.getType()) && annotation != null && annotation.userSearch()) { panel = new UserSearchPanel.Builder("value").fiql((String) wrapper.getPropertyValue(fieldName)) .required(false).build(); // This is needed in order to manually update this.reportletConf with search panel selections panel.setDefaultModel(new Model<String>(fieldName)); } else if (String.class.equals(field.getType()) && annotation != null && annotation.groupSearch()) { panel = new GroupSearchPanel.Builder("value").fiql((String) wrapper.getPropertyValue(fieldName)) .required(false).build(); // This is needed in order to manually update this.reportletConf with search panel selections panel.setDefaultModel(new Model<String>(fieldName)); } else if (List.class.equals(field.getType())) { Class<?> listItemType = String.class; if (field.getGenericType() instanceof ParameterizedType) { listItemType = (Class<?>) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; } if (listItemType.equals(String.class) && annotation != null) { List<String> choices; switch (annotation.schema()) { case UserPlainSchema: choices = schemaRestClient.getPlainSchemaNames(AttributableType.USER); break; case UserDerivedSchema: choices = schemaRestClient.getDerSchemaNames(AttributableType.USER); break; case UserVirtualSchema: choices = schemaRestClient.getVirSchemaNames(AttributableType.USER); break; case GroupPlainSchema: choices = schemaRestClient.getPlainSchemaNames(AttributableType.GROUP); break; case GroupDerivedSchema: choices = schemaRestClient.getDerSchemaNames(AttributableType.GROUP); break; case GroupVirtualSchema: choices = schemaRestClient.getVirSchemaNames(AttributableType.GROUP); break; case MembershipPlainSchema: choices = schemaRestClient.getPlainSchemaNames(AttributableType.MEMBERSHIP); break; case MembershipDerivedSchema: choices = schemaRestClient.getDerSchemaNames(AttributableType.MEMBERSHIP); break; case MembershipVirtualSchema: choices = schemaRestClient.getVirSchemaNames(AttributableType.MEMBERSHIP); break; default: choices = Collections.emptyList(); } panel = new AjaxPalettePanel("value", new PropertyModel<List<String>>(ReportletConfModalPage.this.reportletConf, fieldName), new ListModel<String>(choices), true); } else if (listItemType.isEnum()) { panel = new CheckBoxMultipleChoiceFieldPanel("value", new PropertyModel(ReportletConfModalPage.this.reportletConf, fieldName), new ListModel(Arrays.asList(listItemType.getEnumConstants()))); } else { if (((List) wrapper.getPropertyValue(fieldName)).isEmpty()) { ((List) wrapper.getPropertyValue(fieldName)).add(null); } panel = new MultiFieldPanel("value", new PropertyModel<List>(ReportletConfModalPage.this.reportletConf, fieldName), buildSinglePanel(field.getType(), fieldName, "panel")); } } else { panel = buildSinglePanel(field.getType(), fieldName, "value"); } item.add(panel); } }; return propView; }
From source file:org.apache.syncope.client.console.pages.Schema.java
private <T extends AbstractSchemaModalPage> List<IColumn> getColumns(final WebMarkupContainer webContainer, final ModalWindow modalWindow, final AttributableType attributableType, final SchemaType schemaType, final Collection<String> fields) { List<IColumn> columns = new ArrayList<IColumn>(); for (final String field : fields) { final Field clazzField = ReflectionUtils.findField(schemaType.getToClass(), field); if (clazzField != null) { if (clazzField.getType().equals(Boolean.class) || clazzField.getType().equals(boolean.class)) { columns.add(new AbstractColumn<AbstractSchemaTO, String>(new ResourceModel(field)) { private static final long serialVersionUID = 8263694778917279290L; @Override/* w ww.ja v a 2s . c o m*/ public void populateItem(final Item<ICellPopulator<AbstractSchemaTO>> item, final String componentId, final IModel<AbstractSchemaTO> model) { BeanWrapper bwi = new BeanWrapperImpl(model.getObject()); Object obj = bwi.getPropertyValue(field); item.add(new Label(componentId, "")); item.add(new AttributeModifier("class", new Model<String>(obj.toString()))); } @Override public String getCssClass() { return "small_fixedsize"; } }); } else { IColumn column = new PropertyColumn(new ResourceModel(field), field, field) { private static final long serialVersionUID = 3282547854226892169L; @Override public String getCssClass() { String css = super.getCssClass(); if ("key".equals(field)) { css = StringUtils.isBlank(css) ? "medium_fixedsize" : css + " medium_fixedsize"; } return css; } }; columns.add(column); } } } columns.add(new AbstractColumn<AbstractSchemaTO, String>(new ResourceModel("actions", "")) { private static final long serialVersionUID = 2054811145491901166L; @Override public String getCssClass() { return "action"; } @Override public void populateItem(final Item<ICellPopulator<AbstractSchemaTO>> item, final String componentId, final IModel<AbstractSchemaTO> model) { final AbstractSchemaTO schemaTO = model.getObject(); final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference()); panel.addWithRoles(new ActionLink() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target) { modalWindow.setPageCreator(new ModalWindow.PageCreator() { private static final long serialVersionUID = -7834632442532690940L; @Override public Page createPage() { AbstractSchemaModalPage page = SchemaModalPageFactory .getSchemaModalPage(attributableType, schemaType); page.setSchemaModalPage(Schema.this.getPageReference(), modalWindow, schemaTO, false); return page; } }); modalWindow.show(target); } }, ActionType.EDIT, allowedReadRoles); panel.addWithRoles(new ActionLink() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target) { switch (schemaType) { case DERIVED: restClient.deleteDerSchema(attributableType, schemaTO.getKey()); break; case VIRTUAL: restClient.deleteVirSchema(attributableType, schemaTO.getKey()); break; default: restClient.deletePlainSchema(attributableType, schemaTO.getKey()); break; } info(getString(Constants.OPERATION_SUCCEEDED)); feedbackPanel.refresh(target); target.add(webContainer); } }, ActionType.DELETE, allowedDeleteRoles); item.add(panel); } }); return columns; }
From source file:org.apache.syncope.client.console.panels.BeanPanel.java
public BeanPanel(final String id, final IModel<T> bean, final Map<String, Pair<AbstractFiqlSearchConditionBuilder, List<SearchClause>>> sCondWrapper, final String... excluded) { super(id, bean); setOutputMarkupId(true);/*from w w w . java2s . co m*/ this.sCondWrapper = sCondWrapper; this.excluded = new ArrayList<>(Arrays.asList(excluded)); this.excluded.add("serialVersionUID"); this.excluded.add("class"); final LoadableDetachableModel<List<String>> model = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<String> load() { final List<String> result = new ArrayList<>(); if (BeanPanel.this.getDefaultModelObject() != null) { ReflectionUtils.doWithFields(BeanPanel.this.getDefaultModelObject().getClass(), new FieldCallback() { public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException { result.add(field.getName()); } }, new FieldFilter() { public boolean matches(final Field field) { return !BeanPanel.this.excluded.contains(field.getName()); } }); } return result; } }; add(new ListView<String>("propView", model) { private static final long serialVersionUID = 9101744072914090143L; @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void populateItem(final ListItem<String> item) { final String fieldName = item.getModelObject(); item.add(new Label("fieldName", new ResourceModel(fieldName, fieldName))); Field field = ReflectionUtils.findField(bean.getObject().getClass(), fieldName); if (field == null) { return; } final SearchCondition scondAnnot = field.getAnnotation(SearchCondition.class); final Schema schemaAnnot = field.getAnnotation(Schema.class); BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean.getObject()); Panel panel; if (scondAnnot != null) { final String fiql = (String) wrapper.getPropertyValue(fieldName); final List<SearchClause> clauses; if (StringUtils.isEmpty(fiql)) { clauses = new ArrayList<>(); } else { clauses = SearchUtils.getSearchClauses(fiql); } final AbstractFiqlSearchConditionBuilder builder; switch (scondAnnot.type()) { case "USER": panel = new UserSearchPanel.Builder(new ListModel<>(clauses)).required(false) .build("value"); builder = SyncopeClient.getUserSearchConditionBuilder(); break; case "GROUP": panel = new GroupSearchPanel.Builder(new ListModel<>(clauses)).required(false) .build("value"); builder = SyncopeClient.getGroupSearchConditionBuilder(); break; default: panel = new AnyObjectSearchPanel.Builder(scondAnnot.type(), new ListModel<>(clauses)) .required(false).build("value"); builder = SyncopeClient.getAnyObjectSearchConditionBuilder(null); } if (BeanPanel.this.sCondWrapper != null) { BeanPanel.this.sCondWrapper.put(fieldName, Pair.of(builder, clauses)); } } else if (List.class.equals(field.getType())) { Class<?> listItemType = String.class; if (field.getGenericType() instanceof ParameterizedType) { listItemType = (Class<?>) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; } if (listItemType.equals(String.class) && schemaAnnot != null) { SchemaRestClient schemaRestClient = new SchemaRestClient(); final List<AbstractSchemaTO> choices = new ArrayList<>(); for (SchemaType type : schemaAnnot.type()) { switch (type) { case PLAIN: choices.addAll( schemaRestClient.getSchemas(SchemaType.PLAIN, schemaAnnot.anyTypeKind())); break; case DERIVED: choices.addAll( schemaRestClient.getSchemas(SchemaType.DERIVED, schemaAnnot.anyTypeKind())); break; case VIRTUAL: choices.addAll( schemaRestClient.getSchemas(SchemaType.VIRTUAL, schemaAnnot.anyTypeKind())); break; default: } } panel = new AjaxPalettePanel.Builder<>().setName(fieldName) .build("value", new PropertyModel<>(bean.getObject(), fieldName), new ListModel<>( choices.stream().map(EntityTO::getKey).collect(Collectors.toList()))) .hideLabel(); } else if (listItemType.isEnum()) { panel = new AjaxPalettePanel.Builder<>().setName(fieldName) .build("value", new PropertyModel<>(bean.getObject(), fieldName), new ListModel(Arrays.asList(listItemType.getEnumConstants()))) .hideLabel(); } else { panel = new MultiFieldPanel.Builder<>(new PropertyModel<>(bean.getObject(), fieldName)) .build("value", fieldName, buildSinglePanel(bean.getObject(), field.getType(), fieldName, "panel")) .hideLabel(); } } else { panel = buildSinglePanel(bean.getObject(), field.getType(), fieldName, "value").hideLabel(); } item.add(panel.setRenderBodyOnly(true)); } }.setReuseItems(true).setOutputMarkupId(true)); }