org.springframework.beans.PropertyAccessorFactory Java Examples

The following examples show how to use org.springframework.beans.PropertyAccessorFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertyPathFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@Nullable
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...
		Assert.state(this.beanFactory != null, "No BeanFactory available");
		Assert.state(this.targetBeanName != null, "No target bean name specified");
		Object bean = this.beanFactory.getBean(this.targetBeanName);
		target = PropertyAccessorFactory.forBeanPropertyAccess(bean);
	}
	Assert.state(this.propertyPath != null, "No property path specified");
	return target.getPropertyValue(this.propertyPath);
}
 
Example #2
Source File: CompositeBinder.java    From jdal with Apache License 2.0 6 votes vote down vote up
public void autobind(Object view) {
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(getModel());
	PropertyAccessor  viewPropertyAccessor = new DirectFieldAccessor(view);
	// iterate on model properties
	for (PropertyDescriptor pd : bw.getPropertyDescriptors()) {
		String propertyName = pd.getName();
		if ( !ignoredProperties.contains(propertyName) && viewPropertyAccessor.isReadableProperty(propertyName)) {
			Object control = viewPropertyAccessor.getPropertyValue(propertyName);
			if (control != null) {
				if (log.isDebugEnabled()) 
					log.debug("Found control: " + control.getClass().getSimpleName() + 
							" for property: " + propertyName);
				bind(control, propertyName);
			}
		}
	}
}
 
Example #3
Source File: OptionWriter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example #4
Source File: AbstractMultiCheckedElementTag.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: OptionWriter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Render 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);
	}
}
 
Example #6
Source File: AnnotatedElementAccessor.java    From jdal with Apache License 2.0 6 votes vote down vote up
public static Object getValue(AnnotatedElement element, Object target) {
	if (element instanceof Field) {
		ReflectionUtils.makeAccessible((Field) element); 
		return ReflectionUtils.getField((Field) element, target);
	}
	else if (element instanceof Method) {
		Method method = (Method) element;
		String name = method.getName();
		
		if (name.startsWith("set")) {
			return PropertyAccessorFactory.forBeanPropertyAccess(target).getPropertyValue(getPropertyName(name));
		}
	}
	
	return null;
}
 
Example #7
Source File: PropertyPathFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: ResourceInitializationUtil.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Handle Spring-initialization of resoures produced by the UIMA framework.
 */
public static Resource initResource(Resource aResource, ApplicationContext aApplicationContext) {
  AutowireCapableBeanFactory beanFactory = aApplicationContext.getAutowireCapableBeanFactory();

  if (aResource instanceof PrimitiveAnalysisEngine_impl) {
    PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(aResource);

    // Access the actual AnalysisComponent and initialize it
    AnalysisComponent analysisComponent = (AnalysisComponent) pa
            .getPropertyValue("mAnalysisComponent");
    initializeBean(beanFactory, analysisComponent, aResource.getMetaData().getName());
    pa.setPropertyValue("mAnalysisComponent", analysisComponent);

    return aResource;
  } else {
    return (Resource) beanFactory.initializeBean(aResource, aResource.getMetaData().getName());
  }
}
 
Example #9
Source File: AnnotationBeanUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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, @Nullable StringValueResolver valueResolver,
		String... excludedProperties) {

	Set<String> excluded = (excludedProperties.length == 0 ? Collections.emptySet() :
			new HashSet<>(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);
		}
	}
}
 
Example #10
Source File: StandardJmsActivationSpecFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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;
}
 
Example #11
Source File: MapItemSqlParameterSourceProvider.java    From CogStack-Pipeline with Apache License 2.0 6 votes vote down vote up
/**
 * Provide parameter values in an {@link MapSqlParameterSource} based on values from
 * the provided item.
 * Supports accessing nested maps or arrays.
 *  e.g. :map1.level1.level2
 *    or :map1.array1[10].level2
 * However it assume keys for the maps are all String.
 * @param item the item to use for parameter values
 */
@Override
public SqlParameterSource createSqlParameterSource(T item) {
  BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
  if (beanWrapper.isReadableProperty(mapPropertyName)) {
      Map<String, Object> map = (Map<String, Object>) beanWrapper.getPropertyValue(mapPropertyName);
      if (shouldFlattenMap) {
        Map<String, Object> flattenMap = new HashMap<String, Object>();
        flatten(map, flattenMap, "");
        return new MapSqlParameterSource(flattenMap);
      } else {
        return new MapSqlParameterSource(map);
      }
  }
  return new MapSqlParameterSource();
}
 
Example #12
Source File: SpringBeanJobFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
	if (isEligibleForPropertyPopulation(job)) {
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.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);
		}
	}
	return job;
}
 
Example #13
Source File: AnnotationBeanUtils.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example #14
Source File: AbstractMultiCheckedElementTag.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void writeObjectEntry(TagWriter tagWriter, @Nullable String valueProperty,
		@Nullable 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);
}
 
Example #15
Source File: OptionWriter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Render 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);
	}
}
 
Example #16
Source File: PropertyPathFactoryBean.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #17
Source File: AnnotationBeanUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example #18
Source File: FormUtils.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Add a link on primary and dependent JComboBoxes by property name. 
 * When selection changes on primary use propertyName to get a Collection and fill dependent JComboBox with it
 * @param primary JComboBox when selection changes
 * @param dependent JComboBox that are filled with collection	
 * @param propertyName the property name for get the collection from primary selected item
 * @param addNull if true, add a null as first combobox item
 */
@SuppressWarnings("rawtypes")
public static void link(final JComboBox primary, final JComboBox dependent, final String propertyName, 
		final boolean addNull) {
	
	primary.addActionListener(new ActionListener() {
	
		public void actionPerformed(ActionEvent e) {
			Object selected = primary.getSelectedItem();
			if (selected != null) {
				BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(selected);
				if (wrapper.isWritableProperty(propertyName)) {
					Collection collection = (Collection) wrapper.getPropertyValue(propertyName);
					Vector<Object> vector = new Vector<Object>(collection);
					if (addNull) vector.add(0, null);
					DefaultComboBoxModel model = new DefaultComboBoxModel(vector);
					dependent.setModel(model);
				}
				else {
					log.error("Can't write on propety '" + propertyName + "' of class: '" + selected.getClass() + "'");
				}
			}
		}
	});
}
 
Example #19
Source File: TilesConfigurer.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #20
Source File: ReportletWizardBuilder.java    From syncope with Apache License 2.0 6 votes vote down vote up
@Override
protected Serializable onApplyInternal(final ReportletWrapper modelObject) {
    if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) {
        BeanWrapper confWrapper = PropertyAccessorFactory.forBeanPropertyAccess(modelObject.getConf());
        modelObject.getSCondWrapper().forEach((fieldName, pair) -> {
            confWrapper.setPropertyValue(fieldName, SearchUtils.buildFIQL(pair.getRight(), pair.getLeft()));
        });
        ImplementationTO reportlet = ImplementationRestClient.read(
                IdRepoImplementationType.REPORTLET, modelObject.getImplementationKey());
        try {
            reportlet.setBody(MAPPER.writeValueAsString(modelObject.getConf()));
            ImplementationRestClient.update(reportlet);
        } catch (Exception e) {
            throw new WicketRuntimeException(e);
        }
    }

    ReportTO reportTO = ReportRestClient.read(report);
    if (modelObject.isNew()) {
        reportTO.getReportlets().add(modelObject.getImplementationKey());
    }

    ReportRestClient.update(reportTO);
    return modelObject;
}
 
Example #21
Source File: DefaultRetryTemplateConverterTest.java    From distributed-lock with MIT License 6 votes vote down vote up
private void assertRetryTemplateConstruction(final RetryTemplate retryTemplate, final long timeout, final long backOff) {
  final var wrapper = PropertyAccessorFactory.forDirectFieldAccess(retryTemplate);

  assertThat(wrapper.getPropertyValue("retryPolicy")).isInstanceOf(CompositeRetryPolicy.class);
  assertThat((RetryPolicy[]) wrapper.getPropertyValue("retryPolicy.policies"))
    .hasSize(2)
    .anyMatch(policy1 -> {
      if (policy1 instanceof TimeoutRetryPolicy) {
        final var timeoutRetryPolicy = (TimeoutRetryPolicy) policy1;
        assertThat(timeoutRetryPolicy.getTimeout()).isEqualTo(timeout);
        return true;
      }
      return false;
    })
    .anyMatch(policy2 -> {
      if (policy2 instanceof SimpleRetryPolicy) {
        final var simpleRetryPolicy = (SimpleRetryPolicy) policy2;
        assertThat(simpleRetryPolicy.getMaxAttempts()).isEqualTo(Integer.MAX_VALUE);
        return true;
      }
      return false;
    });

  assertThat(wrapper.getPropertyValue("backOffPolicy")).isInstanceOf(FixedBackOffPolicy.class);
  assertThat(((FixedBackOffPolicy) wrapper.getPropertyValue("backOffPolicy")).getBackOffPeriod()).isEqualTo(backOff);
}
 
Example #22
Source File: StandardJmsActivationSpecFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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;
}
 
Example #23
Source File: AbstractMultiCheckedElementTag.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #24
Source File: AutowiringSpringBeanJobFactory.java    From syncope with Apache License 2.0 6 votes vote down vote up
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
    Object job = beanFactory.getBean(bundle.getJobDetail().getKey().getName());
    if (isEligibleForPropertyPopulation(job)) {
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
        MutablePropertyValues pvs = new MutablePropertyValues();
        if (this.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);
        }
    }
    return job;
}
 
Example #25
Source File: TilesConfigurer.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected DefinitionsFactory createDefinitionsFactory(TilesApplicationContext applicationContext,
		TilesRequestContextFactory contextFactory, LocaleResolver resolver) {
	if (definitionsFactoryClass != null) {
		DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
		if (factory instanceof TilesApplicationContextAware) {
			((TilesApplicationContextAware) 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, contextFactory, resolver));
		}
		if (factory instanceof Refreshable) {
			((Refreshable) factory).refresh();
		}
		return factory;
	}
	else {
		return super.createDefinitionsFactory(applicationContext, contextFactory, resolver);
	}
}
 
Example #26
Source File: DataObjectWrapperBase.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Creates a data object wrapper.
 *
 * @param dataObject the data object to wrap.
 * @param metadata the metadata of the data object.
 * @param dataObjectService the data object service to use.
 * @param referenceLinker the reference linker implementation.
 */
protected DataObjectWrapperBase(T dataObject, DataObjectMetadata metadata, DataObjectService dataObjectService,
        ReferenceLinker referenceLinker) {
    this.dataObject = dataObject;
    this.metadata = metadata;
    this.dataObjectService = dataObjectService;
    this.referenceLinker = referenceLinker;
    this.wrapper = PropertyAccessorFactory.forBeanPropertyAccess(dataObject);
    // note that we do *not* want to set auto grow to be true here since we are using this primarily for
    // access to the data, we will expose getPropertyValueNullSafe instead because it prevents a a call to
    // getPropertyValue from modifying the internal state of the object by growing intermediate nested paths
}
 
Example #27
Source File: HttpServletBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Map config parameters onto bean properties of this servlet, and
 * invoke subclass initialization.
 * @throws ServletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 */
@Override
public final void init() throws ServletException {
	if (logger.isDebugEnabled()) {
		logger.debug("Initializing servlet '" + getServletName() + "'");
	}

	// Set bean properties from init parameters.
	PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
	if (!pvs.isEmpty()) {
		try {
			BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
			ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
			bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
			initBeanWrapper(bw);
			bw.setPropertyValues(pvs, true);
		}
		catch (BeansException ex) {
			if (logger.isErrorEnabled()) {
				logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);
			}
			throw ex;
		}
	}

	// Let subclasses do whatever initialization they like.
	initServletBean();

	if (logger.isDebugEnabled()) {
		logger.debug("Servlet '" + getServletName() + "' configured successfully");
	}
}
 
Example #28
Source File: HbaseFindBuilder.java    From springboot_cwenao with MIT License 5 votes vote down vote up
private void reflectBean(Class<T> tclazz) {

        tBean = BeanUtils.instantiate(tclazz);

        PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(tclazz);

        for (PropertyDescriptor p : propertyDescriptors) {
            if (p.getWriteMethod() != null) {
                this.fieldsMap.put(p.getName(), p);
            }
        }

        beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(tBean);
    }
 
Example #29
Source File: ListTableModel.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Get a primary key of entity in the list
 * @param row row of model
 * @return the primary key of model, if any
 */
private Object getPrimaryKey(Object row) {
	if (BeanUtils.getPropertyDescriptor(modelClass, id) == null)
		return row;
	
	BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(row);
	return wrapper.getPropertyValue(id);
}
 
Example #30
Source File: AbstractBinder.java    From jdal with Apache License 2.0 5 votes vote down vote up
private BeanWrapper getBeanWrapper() {
	BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(getModel());
	wrapper.setConversionService(getConversionService());
	wrapper.registerCustomEditor(Date.class, 
			new CustomDateEditor(SimpleDateFormat.getDateTimeInstance(), true));
	
	return wrapper;
}