List of usage examples for org.springframework.beans BeanWrapperImpl isWritableProperty
@Override public boolean isWritableProperty(String propertyName)
From source file:org.wallride.web.support.ControllerUtils.java
public static MultiValueMap<String, String> convertBeanForQueryParams(Object target, ConversionService conversionService) { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(target); beanWrapper.setConversionService(conversionService); MultiValueMap<String, String> queryParams = new LinkedMultiValueMap(); for (PropertyDescriptor pd : beanWrapper.getPropertyDescriptors()) { if (beanWrapper.isWritableProperty(pd.getName())) { Object pv = beanWrapper.getPropertyValue(pd.getName()); if (pv != null) { if (pv instanceof Collection) { if (!CollectionUtils.isEmpty((Collection) pv)) { for (Object element : (Collection) pv) { queryParams.set(pd.getName(), convertPropertyValueForString(target, pd, element)); }/* w ww .j a v a 2 s .c om*/ } } else { queryParams.set(pd.getName(), convertPropertyValueForString(target, pd, pv)); } } } } return queryParams; }
From source file:io.spring.initializr.generator.ProjectRequest.java
/** * Initializes this instance with the defaults defined in the specified * {@link InitializrMetadata}./* ww w .j a va 2 s. c o m*/ * @param metadata the initializr metadata */ public void initialize(InitializrMetadata metadata) { BeanWrapperImpl bean = new BeanWrapperImpl(this); metadata.defaults().forEach((key, value) -> { if (bean.isWritableProperty(key)) { // We want to be able to infer a package name if none has been // explicitly set if (!key.equals("packageName")) { bean.setPropertyValue(key, value); } } }); }
From source file:org.archive.crawler.restlet.BeanBrowseResource.java
/** * Constructs a nested Map data structure with the information represented * by this Resource. The result is particularly suitable for use with with * {@link XmlMarshaller}.//w w w . j a va2 s . c o m * * @return the nested Map data structure */ protected BeansModel makeDataModel() { Object bean = null; String problem = null; boolean editable = false; Object target = null; if (StringUtils.isNotBlank(beanPath)) { try { int firstDot = beanPath.indexOf("."); String beanName = firstDot < 0 ? beanPath : beanPath.substring(0, firstDot); Object namedBean = appCtx.getBean(beanName); if (firstDot < 0) { target = namedBean; bean = makePresentableMapFor(null, target, beanPath); } else { BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean); String propPath = beanPath.substring(firstDot + 1); target = bwrap.getPropertyValue(propPath); Class<?> type = bwrap.getPropertyType(propPath); if (bwrap.isWritableProperty(propPath) && (bwrap.getDefaultEditor(type) != null || type == String.class) && !Collection.class.isAssignableFrom(type)) { editable = true; bean = makePresentableMapFor(null, target); } else { bean = makePresentableMapFor(null, target, beanPath); } } } catch (BeansException e) { problem = e.toString(); } } Collection<Object> nestedNames = new LinkedList<Object>(); Set<Object> alreadyWritten = new HashSet<Object>(); addPresentableNestedNames(nestedNames, appCtx.getBean("crawlController"), alreadyWritten); for (String name : appCtx.getBeanDefinitionNames()) { addPresentableNestedNames(nestedNames, appCtx.getBean(name), alreadyWritten); } return new BeansModel(cj.getShortName(), new Reference(getRequest().getResourceRef().getBaseRef(), "..").getTargetRef().toString(), beanPath, bean, editable, problem, target, nestedNames); }
From source file:com.smhdemo.common.datasource.generate.factory.custom.CustomDataSourceFactory.java
@SuppressWarnings("rawtypes") @Override/* w w w . j av a 2 s . c o m*/ public DataSourceServiceable createService(Base alqcDataSource) { if (!(alqcDataSource instanceof Custom)) { logger.error("Custom??"); throw new BaseRuntimeException("Custom??", new Object[] { alqcDataSource.getClass() }); } Custom customDataSource = (Custom) alqcDataSource; // ??? String serviceClassName = customDataSource.getServiceClass(); DataSourceServiceable service; try { Class serviceClass = Class.forName(serviceClassName); service = (DataSourceServiceable) serviceClass.newInstance(); } catch (Exception e) { logger.error("?Custom??", e); BaseRuntimeException ex = new BaseRuntimeException("?Custom??", e); ex.setArgs(new Object[] { serviceClassName }); throw ex; } try { // Spring?? BeanWrapperImpl bw = new BeanWrapperImpl(service); // CustomDataSourceDefinition CustomDataSourceDefinition def = getDefinitionByServiceClass(serviceClassName); // "propertyMap"? Map<String, Object> propMap = new HashMap<String, Object>(); // ? Iterator pdi = def.getPropertyDefinitions().iterator(); while (pdi.hasNext()) { Map pd = (Map) pdi.next(); String name = (String) pd.get(CustomDataSourceDefinition.PARAM_NAME); Object deflt = pd.get(CustomDataSourceDefinition.PARAM_DEFAULT); Object value = customDataSource.getPropertyMap().get(name); if (value == null && deflt != null) { value = deflt; } // ? if (value != null) { if (bw.isWritableProperty(name)) { bw.setPropertyValue(name, value); } propMap.put(name, value); } } if (bw.isWritableProperty(PROPERTY_MAP)) { bw.setPropertyValue(PROPERTY_MAP, propMap); } } catch (Exception e) { logger.error("Custom??", e); BaseRuntimeException ex = new BaseRuntimeException("Custom??", e); ex.setArgs(new Object[] { serviceClassName }); throw ex; } return service; }
From source file:com.sshdemo.common.extendds.generate.factory.custom.CustomDataSourceFactory.java
@SuppressWarnings("rawtypes") @Override/* w w w.j av a 2 s . c o m*/ public EwcmsDataSourceServiceable createService(BaseDS alqcDataSource) { if (!(alqcDataSource instanceof CustomDS)) { logger.error("Custom??"); throw new BaseRuntimeException("Custom??", new Object[] { alqcDataSource.getClass() }); } CustomDS customDataSource = (CustomDS) alqcDataSource; // ??? String serviceClassName = customDataSource.getServiceClass(); EwcmsDataSourceServiceable service; try { Class serviceClass = Class.forName(serviceClassName); service = (EwcmsDataSourceServiceable) serviceClass.newInstance(); } catch (Exception e) { logger.error("?Custom??", e); BaseRuntimeException ex = new BaseRuntimeException("?Custom??", e); ex.setArgs(new Object[] { serviceClassName }); throw ex; } try { // Spring?? BeanWrapperImpl bw = new BeanWrapperImpl(service); // CustomDataSourceDefinition CustomDataSourceDefinition def = getDefinitionByServiceClass(serviceClassName); // "propertyMap"? Map<String, Object> propMap = new HashMap<String, Object>(); // ? Iterator pdi = def.getPropertyDefinitions().iterator(); while (pdi.hasNext()) { Map pd = (Map) pdi.next(); String name = (String) pd.get(CustomDataSourceDefinition.PARAM_NAME); Object deflt = pd.get(CustomDataSourceDefinition.PARAM_DEFAULT); Object value = customDataSource.getPropertyMap().get(name); if (value == null && deflt != null) { value = deflt; } // ? if (value != null) { if (bw.isWritableProperty(name)) { bw.setPropertyValue(name, value); } propMap.put(name, value); } } if (bw.isWritableProperty(PROPERTY_MAP)) { bw.setPropertyValue(PROPERTY_MAP, propMap); } } catch (Exception e) { logger.error("Custom??", e); BaseRuntimeException ex = new BaseRuntimeException("Custom??", e); ex.setArgs(new Object[] { serviceClassName }); throw ex; } return service; }