當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertyAccessorFactory.forBeanPropertyAccess方法代碼示例

本文整理匯總了Java中org.springframework.beans.PropertyAccessorFactory.forBeanPropertyAccess方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertyAccessorFactory.forBeanPropertyAccess方法的具體用法?Java PropertyAccessorFactory.forBeanPropertyAccess怎麽用?Java PropertyAccessorFactory.forBeanPropertyAccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.PropertyAccessorFactory的用法示例。


在下文中一共展示了PropertyAccessorFactory.forBeanPropertyAccess方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: add

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
@Override
public Object add(Object object) {
	SqlModel<Object> sqlModel = sqlBuilder.insertSelectiveSql(object);
	checkSqlModel(sqlModel);
	
	SqlParameterSource paramSource =  new BeanPropertySqlParameterSource(object);
	KeyHolder generatedKeyHolder =  new  GeneratedKeyHolder();
	namedPjdbcTemplate.update(sqlModel.getSql(), paramSource, generatedKeyHolder);
	Number num = generatedKeyHolder.getKey();
	
	String[] primaryKeys = sqlModel.getPrimaryKeys();
	if(primaryKeys != null && primaryKeys.length > 0){
		BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(object);
		beanWrapper.setPropertyValue(primaryKeys[0], num);
	}
	
	return object;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:19,代碼來源:NamedJdbcDao.java

示例2: initJob

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
protected void initJob(TriggerFiredBundle bundle, Object job) {
	// The following code is copied from SpringBeanJobFactory in spring-context-support-4.2.5.RELEASE
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
	if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
		pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:24,代碼來源:YadaQuartzJobFactory.java

示例3: delete

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
public <T> int delete(T t) throws DataAccessException {
    StringBuilder sql = new StringBuilder();
    sql.append(DELETE).append(SPACE).append(FROM).append(SPACE).append(t.getClass().getSimpleName().toLowerCase()).append(SPACE);
    sql.append(WHERE).append(SPACE).append(IDENTICAL).append(SPACE);
    PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(t.getClass());
    BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(t);
    for (int i = 0; i < pds.length; i++) {
        PropertyDescriptor pd = pds[i];
        String name = pd.getName();
        if (!CLASS.equals(name) && beanWrapper.isReadableProperty(name) && beanWrapper.getPropertyValue(name) != null) {
            sql.append(AND).append(SPACE).append(CamelCaseUtils.underscoreName(name)).append(SPACE);
            sql.append(EQUAL).append(SPACE).append(COLON).append(name).append(SPACE);
        }
    }
    return namedJdbcTemplate.update(sql.toString(), new BeanPropertySqlParameterSource(t));
}
 
開發者ID:mynah,項目名稱:oblatum,代碼行數:17,代碼來源:MappingJdbcTemplate.java

示例4: applyMapOntoInstance

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * Injects the properties from the given Map to the given object. Additionally, a bean factory can be passed in for
 * copying property editors inside the injector.
 * 
 * @param instance bean instance to configure
 * @param properties
 * @param beanFactory
 */
public static void applyMapOntoInstance(Object instance, Map<String, ?> properties, AbstractBeanFactory beanFactory) {
	if (properties != null && !properties.isEmpty()) {
		BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(instance);
		beanWrapper.setAutoGrowNestedPaths(true);

		// configure bean wrapper (using method from Spring 2.5.6)
		if (beanFactory != null) {
			beanFactory.copyRegisteredEditorsTo(beanWrapper);
		}
		for (Iterator<?> iterator = properties.entrySet().iterator(); iterator.hasNext();) {
			Map.Entry<String, ?> entry = (Map.Entry<String, ?>) iterator.next();
			String propertyName = entry.getKey();
			if (beanWrapper.isWritableProperty(propertyName)) {
				beanWrapper.setPropertyValue(propertyName, entry.getValue());
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:27,代碼來源:CMUtils.java

示例5: execute

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * This implementation applies the passed-in job data map as bean property
 * values, and delegates to {@code executeInternal} afterwards.
 * @see #executeInternal
 */
@Override
public final void execute(JobExecutionContext context) throws JobExecutionException {
	try {
		// Reflectively adapting to differences between Quartz 1.x and Quartz 2.0...
		Scheduler scheduler = (Scheduler) ReflectionUtils.invokeMethod(getSchedulerMethod, context);
		Map<?, ?> mergedJobDataMap = (Map<?, ?>) ReflectionUtils.invokeMethod(getMergedJobDataMapMethod, context);

		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
		MutablePropertyValues pvs = new MutablePropertyValues();
		pvs.addPropertyValues(scheduler.getContext());
		pvs.addPropertyValues(mergedJobDataMap);
		bw.setPropertyValues(pvs, true);
	}
	catch (SchedulerException ex) {
		throw new JobExecutionException(ex);
	}
	executeInternal(context);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:QuartzJobBean.java

示例6: createJobInstance

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = super.createJobInstance(bundle);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
	if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(getJobDetailDataMap(bundle));
		pvs.addPropertyValues(getTriggerDataMap(bundle));
		if (this.ignoredUnknownProperties != null) {
			for (String propName : this.ignoredUnknownProperties) {
				if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
					pvs.removePropertyValue(propName);
				}
			}
			bw.setPropertyValues(pvs);
		}
		else {
			bw.setPropertyValues(pvs, true);
		}
	}
	return job;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:SpringBeanJobFactory.java

示例7: copyPropertiesToBean

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * Copy the properties of the supplied {@link Annotation} to the supplied target bean.
 * Any properties defined in {@code excludedProperties} will not be copied.
 * <p>A specified value resolver may resolve placeholders in property values, for example.
 * @param ann the annotation to copy from
 * @param bean the bean instance to copy to
 * @param valueResolver a resolve to post-process String property values (may be {@code null})
 * @param excludedProperties the names of excluded properties, if any
 * @see org.springframework.beans.BeanWrapper
 */
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
	Set<String> excluded =  new HashSet<String>(Arrays.asList(excludedProperties));
	Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
	for (Method annotationProperty : annotationProperties) {
		String propertyName = annotationProperty.getName();
		if ((!excluded.contains(propertyName)) && bw.isWritableProperty(propertyName)) {
			Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
			if (valueResolver != null && value instanceof String) {
				value = valueResolver.resolveStringValue((String) value);
			}
			bw.setPropertyValue(propertyName, value);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:AnnotationBeanUtils.java

示例8: getObject

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
@Override
public Object getObject() throws BeansException {
	BeanWrapper target = this.targetBeanWrapper;
	if (target != null) {
		if (logger.isWarnEnabled() && this.targetBeanName != null &&
				this.beanFactory instanceof ConfigurableBeanFactory &&
				((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) {
			logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " +
					"reference - obtained value for property '" + this.propertyPath + "' may be outdated!");
		}
	}
	else {
		// Fetch prototype target bean...
		Object bean = this.beanFactory.getBean(this.targetBeanName);
		target = PropertyAccessorFactory.forBeanPropertyAccess(bean);
	}
	return target.getPropertyValue(this.propertyPath);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:PropertyPathFactoryBean.java

示例9: getId

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public ID getId(T entity) {
	Class<?> domainClass = getJavaType();
	while (domainClass != Object.class) {
		for (Field field : domainClass.getDeclaredFields()) {
			if (field.getAnnotation(Id.class) != null) {
				try {
					return (ID) field.get(entity);
				}
				catch (IllegalArgumentException | IllegalAccessException e) {
					BeanWrapper beanWrapper = PropertyAccessorFactory
							.forBeanPropertyAccess(entity);
					return (ID) beanWrapper.getPropertyValue(field.getName());
				}
			}
		}
		domainClass = domainClass.getSuperclass();
	}
	throw new IllegalStateException("id not found");
}
 
開發者ID:tkob,項目名稱:spring-data-gclouddatastore,代碼行數:22,代碼來源:GcloudDatastoreEntityInformation.java

示例10: createDefinitionsFactory

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
@Override
protected DefinitionsFactory createDefinitionsFactory(ApplicationContext applicationContext,
		LocaleResolver resolver) {

	if (definitionsFactoryClass != null) {
		DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
		if (factory instanceof ApplicationContextAware) {
			((ApplicationContextAware) factory).setApplicationContext(applicationContext);
		}
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
		if (bw.isWritableProperty("localeResolver")) {
			bw.setPropertyValue("localeResolver", resolver);
		}
		if (bw.isWritableProperty("definitionDAO")) {
			bw.setPropertyValue("definitionDAO", createLocaleDefinitionDao(applicationContext, resolver));
		}
		return factory;
	}
	else {
		return super.createDefinitionsFactory(applicationContext, resolver);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:TilesConfigurer.java

示例11: doRenderFromCollection

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * Renders the inner '{@code option}' tags using the supplied {@link Collection} of
 * objects as the source. The value of the {@link #valueProperty} field is used
 * when rendering the '{@code value}' of the '{@code option}' and the value of the
 * {@link #labelProperty} property is used when rendering the label.
 */
private void doRenderFromCollection(Collection<?> optionCollection, TagWriter tagWriter) throws JspException {
	for (Object item : optionCollection) {
		BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
		Object value;
		if (this.valueProperty != null) {
			value = wrapper.getPropertyValue(this.valueProperty);
		}
		else if (item instanceof Enum) {
			value = ((Enum<?>) item).name();
		}
		else {
			value = item;
		}
		Object label = (this.labelProperty != null ? wrapper.getPropertyValue(this.labelProperty) : item);
		renderOption(tagWriter, item, value, label);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:OptionWriter.java

示例12: writeObjectEntry

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
private void writeObjectEntry(TagWriter tagWriter, String valueProperty,
		String labelProperty, Object item, int itemIndex) throws JspException {

	BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
	Object renderValue;
	if (valueProperty != null) {
		renderValue = wrapper.getPropertyValue(valueProperty);
	}
	else if (item instanceof Enum) {
		renderValue = ((Enum<?>) item).name();
	}
	else {
		renderValue = item;
	}
	Object renderLabel = (labelProperty != null ? wrapper.getPropertyValue(labelProperty) : item);
	writeElementTag(tagWriter, item, renderValue, renderLabel, itemIndex);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:AbstractMultiCheckedElementTag.java

示例13: copyPropertiesToBean

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * Copy the properties of the supplied {@link Annotation} to the supplied target bean.
 * Any properties defined in {@code excludedProperties} will not be copied.
 * <p>A specified value resolver may resolve placeholders in property values, for example.
 * @param ann the annotation to copy from
 * @param bean the bean instance to copy to
 * @param valueResolver a resolve to post-process String property values (may be {@code null})
 * @param excludedProperties the names of excluded properties, if any
 * @see org.springframework.beans.BeanWrapper
 */
public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) {
	Set<String> excluded = new HashSet<String>(Arrays.asList(excludedProperties));
	Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
	for (Method annotationProperty : annotationProperties) {
		String propertyName = annotationProperty.getName();
		if (!excluded.contains(propertyName) && bw.isWritableProperty(propertyName)) {
			Object value = ReflectionUtils.invokeMethod(annotationProperty, ann);
			if (valueResolver != null && value instanceof String) {
				value = valueResolver.resolveStringValue((String) value);
			}
			bw.setPropertyValue(propertyName, value);
		}
	}
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:26,代碼來源:AnnotationBeanUtils.java

示例14: createActivationSpec

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
@Override
public ActivationSpec createActivationSpec(ResourceAdapter adapter, JmsActivationSpecConfig config) {
	Class<?> activationSpecClassToUse = this.activationSpecClass;
	if (activationSpecClassToUse == null) {
		activationSpecClassToUse = determineActivationSpecClass(adapter);
		if (activationSpecClassToUse == null) {
			throw new IllegalStateException("Property 'activationSpecClass' is required");
		}
	}

	ActivationSpec spec = (ActivationSpec) BeanUtils.instantiateClass(activationSpecClassToUse);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(spec);
	if (this.defaultProperties != null) {
		bw.setPropertyValues(this.defaultProperties);
	}
	populateActivationSpecProperties(bw, config);
	return spec;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:StandardJmsActivationSpecFactory.java

示例15: writeObjectEntry

import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
 * Copy & Paste, 無修正.
 */
private void writeObjectEntry(TagWriter tagWriter, String valueProperty, String labelProperty, Object item,
		int itemIndex) throws JspException {

	BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
	Object renderValue;
	if (valueProperty != null) {
		renderValue = wrapper.getPropertyValue(valueProperty);
	} else if (item instanceof Enum) {
		renderValue = ((Enum<?>) item).name();
	} else {
		renderValue = item;
	}
	Object renderLabel = (labelProperty != null ? wrapper.getPropertyValue(labelProperty) : item);
	writeElementTag(tagWriter, item, renderValue, renderLabel, itemIndex);
}
 
開發者ID:pengqiuyuan,項目名稱:g2,代碼行數:19,代碼來源:BSAbstractMultiCheckedElementTag.java


注:本文中的org.springframework.beans.PropertyAccessorFactory.forBeanPropertyAccess方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。