List of usage examples for org.springframework.beans MutablePropertyValues contains
@Override public boolean contains(String propertyName)
From source file:com.saysth.commons.quartz.SpringBeanJobFactory.java
/** * Create the job instance, populating it with property values taken from * the scheduler context, job data map and trigger data map. *///ww w . j av a 2 s . co m @Override protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { Object job = bundle.getJobDetail().getJobClass().newInstance(); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job); if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) { 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; }
From source file:net.tirasa.blog.springquartz.SpringBeanJobFactory.java
/** * An implementation of SpringBeanJobFactory that retrieves the bean from * the Spring context so that autowiring and transactions work * * This method is overriden.// ww w. j ava2 s .co m * @see org.springframework.scheduling.quartz.SpringBeanJobFactory#createJobInstance(org.quartz.spi.TriggerFiredBundle) */ @Override protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception { final ConfigurableApplicationContext ctx = ((ConfigurableApplicationContext) schedulerContext .get("applicationContext")); final Object job = ctx.getBean(bundle.getJobDetail().getName()); final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(job); if (isEligibleForPropertyPopulation(wrapper.getWrappedInstance())) { final 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) { wrapper.setPropertyValues(pvs, true); } else { for (String propName : this.ignoredUnknownProperties) { if (pvs.contains(propName) && !wrapper.isWritableProperty(propName)) { pvs.removePropertyValue(propName); } } wrapper.setPropertyValues(pvs); } } return job; }
From source file:org.syncope.core.scheduling.SpringBeanJobFactory.java
/** * An implementation of SpringBeanJobFactory that retrieves the bean from * the Spring context so that autowiring and transactions work. * * {@inheritDoc}//from w ww . j a va2s. c om */ @Override protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception { final ApplicationContext ctx = ((ConfigurableApplicationContext) schedulerContext .get("applicationContext")); // Try to re-create job bean from underlying task (useful for managing // failover scenarios) if (!ctx.containsBean(bundle.getJobDetail().getName())) { Long taskId = JobInstanceLoader.getTaskIdFromJobName(bundle.getJobDetail().getName()); if (taskId != null) { TaskDAO taskDAO = ctx.getBean(TaskDAO.class); SchedTask task = taskDAO.find(taskId); JobInstanceLoader jobInstanceLoader = ctx.getBean(JobInstanceLoader.class); jobInstanceLoader.registerJob(task, task.getJobClassName(), task.getCronExpression()); } Long reportId = JobInstanceLoader.getReportIdFromJobName(bundle.getJobDetail().getName()); if (reportId != null) { ReportDAO reportDAO = ctx.getBean(ReportDAO.class); Report report = reportDAO.find(reportId); JobInstanceLoader jobInstanceLoader = ctx.getBean(JobInstanceLoader.class); jobInstanceLoader.registerJob(report); } } final Object job = ctx.getBean(bundle.getJobDetail().getName()); final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(job); if (isEligibleForPropertyPopulation(wrapper.getWrappedInstance())) { final 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) { wrapper.setPropertyValues(pvs, true); } else { for (String propName : this.ignoredUnknownProperties) { if (pvs.contains(propName) && !wrapper.isWritableProperty(propName)) { pvs.removePropertyValue(propName); } } wrapper.setPropertyValues(pvs); } } return job; }
From source file:com.laxser.blitz.web.paramresolver.ServletRequestDataBinder.java
@Override protected void doBind(MutablePropertyValues mpvs) { // book.author.name?book.authorauthor PropertyValue[] pvArray = mpvs.getPropertyValues(); MutablePropertyValues newMpvs = null; for (int i = 0; i < pvArray.length; i++) { PropertyValue pv = pvArray[i];/*from w w w . j a va2 s. c o m*/ String propertyName = pv.getName(); int dot = propertyName.indexOf('.'); while (dot != -1) { String field = propertyName.substring(0, dot); if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) { Class<?> fieldType = getPropertyAccessor().getPropertyType(field); if (newMpvs == null) { newMpvs = new MutablePropertyValues(); } newMpvs.addPropertyValue(field, BeanUtils.instantiateClass(fieldType)); } dot = propertyName.indexOf('.', dot + 1); } } if (newMpvs == null) { super.doBind(mpvs); } else { newMpvs.addPropertyValues(mpvs); super.doBind(newMpvs); } }
From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java
protected void processRenamesOrRemovals(final BeanDefinitionRegistry registry, final Set<Object> processedKeys) { final String effectivePropertyPrefix = this.propertyPrefix + DOT; this.propertiesSource.forEach((key, value) -> { if (!processedKeys.contains(key)) { final Pair<String, String> processableKeyValue = this.getProcessableKeyValue(key, value, effectivePropertyPrefix); if (processableKeyValue != null) { LOGGER.debug("[{}] Evaluating property key {}", this.beanName, key); final String beanDefinitionKey = processableKeyValue.getFirst(); final String resolvedValue = processableKeyValue.getSecond(); final int propertyFragmentIdx = beanDefinitionKey.indexOf(FRAGMENT_PROPERTY); if (propertyFragmentIdx == -1) { LOGGER.trace("[{}] Processing entry {} = {}", this.beanName, key, resolvedValue); if (beanDefinitionKey.contains(FRAGMENT_RENAME)) { final String beanName = beanDefinitionKey.substring(0, beanDefinitionKey.indexOf(FRAGMENT_RENAME)); final String targetBeanName = beanDefinitionKey.substring( beanDefinitionKey.indexOf(FRAGMENT_RENAME) + FRAGMENT_RENAME.length()); if (Boolean.parseBoolean(resolvedValue)) { if (registry.containsBeanDefinition(beanName)) { LOGGER.debug("[{}] Renaming bean {} to {}", this.beanName, beanName, targetBeanName); final BeanDefinition beanDefinition = registry.getBeanDefinition(beanName); registry.removeBeanDefinition(beanName); registry.registerBeanDefinition(targetBeanName, beanDefinition); } else { LOGGER.debug("[{}] Unable to rename bean {} to {} - bean has not been defined", this.beanName, beanName, targetBeanName); }/*w w w .ja v a2s . co m*/ } else { LOGGER.debug("[{}] Not renaming bean {} to {} due to non-true property value", this.beanName, beanName, targetBeanName); } processedKeys.add(key); } else if (beanDefinitionKey.endsWith(SUFFIX_REMOVE)) { final String beanName = beanDefinitionKey.substring(0, beanDefinitionKey.indexOf(SUFFIX_REMOVE)); if (Boolean.parseBoolean(resolvedValue)) { if (registry.containsBeanDefinition(beanName)) { LOGGER.debug("[{}] Removing bean {}", this.beanName, beanName); registry.removeBeanDefinition(beanName); } else { LOGGER.debug("[{}] Unable to remove bean {} - bean has not been defined", this.beanName, beanName); } } else { LOGGER.debug("[{}] Not removing bean {} due to non-true property value", this.beanName, beanName); } processedKeys.add(key); } else { LOGGER.trace("[{}] Setting unsupported by processRenamesOrRemovals: {} = {}", this.beanName, key, resolvedValue); } } else { final String beanName = beanDefinitionKey.substring(0, propertyFragmentIdx); final String propertyDefinitionKey = beanDefinitionKey .substring(propertyFragmentIdx + FRAGMENT_PROPERTY.length()); if (propertyDefinitionKey.endsWith(SUFFIX_REMOVE)) { final String propertyName = propertyDefinitionKey.substring(0, propertyDefinitionKey.indexOf(SUFFIX_REMOVE)); if (registry.containsBeanDefinition(beanName)) { final BeanDefinition beanDefinition = registry.getBeanDefinition(beanName); final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); if (propertyValues.contains(propertyName)) { if (value instanceof String && Boolean.parseBoolean(resolvedValue)) { LOGGER.debug("[{}] Removing property {} from {}", this.beanName, propertyName, beanName); propertyValues.removePropertyValue(propertyName); } else { LOGGER.debug( "[{}] Not removing property {} from [} due to non-true property value", this.beanName, propertyName, beanName); } processedKeys.add(key); } else { LOGGER.trace( "[{}] Property {} not found in bean {} - key {} may refer to removal of values in collection-like property", this.beanName, propertyName, beanName, key); } } else { LOGGER.debug( "[{}] Unable to remove property {} from {} - bean has not been defined", this.beanName, propertyName, beanName); processedKeys.add(key); } } } } } }); }
From source file:net.nan21.dnet.core.presenter.descriptor.DsDefinitions.java
/** * Helper method to create the definition for a single given data-source. * //from www . j a v a2 s .co m * @param name * @param factory * @return * @throws Exception */ private DsDefinition createDefinition(String name, ConfigurableListableBeanFactory factory) throws Exception { BeanDefinition beanDef = factory.getBeanDefinition(name); DsDefinition definition = new DsDefinition(); definition.setName(name); String modelClass = null; String filterClass = null; String paramClass = null; String readOnly = null; MutablePropertyValues mpv = beanDef.getPropertyValues(); // model class modelClass = ((TypedStringValue) mpv.getPropertyValue("modelClass").getValue()).getValue(); definition.setModelClass(this.applicationContext.getClassLoader().loadClass(modelClass)); // filter class if (mpv.getPropertyValue("filterClass") != null) { filterClass = ((TypedStringValue) mpv.getPropertyValue("filterClass").getValue()).getValue(); definition.setFilterClass(this.applicationContext.getClassLoader().loadClass(filterClass)); } else { definition.setFilterClass(this.applicationContext.getClassLoader().loadClass(modelClass)); } // param-class if (mpv.getPropertyValue("paramClass") != null) { paramClass = ((TypedStringValue) mpv.getPropertyValue("paramClass").getValue()).getValue(); definition.setParamClass(this.applicationContext.getClassLoader().loadClass(paramClass)); } // other attributes if (mpv.contains("readOnly")) { readOnly = ((TypedStringValue) mpv.getPropertyValue("readOnly").getValue()).getValue(); definition.setReadOnly(Boolean.getBoolean(readOnly)); } // RPC methods if (mpv.contains("rpcData")) { @SuppressWarnings("unchecked") ManagedMap<TypedStringValue, Object> rpcData = (ManagedMap<TypedStringValue, Object>) mpv .getPropertyValue("rpcData").getValue(); List<String> services = new ArrayList<String>(); for (TypedStringValue tsv : rpcData.keySet()) { services.add(tsv.getValue()); } definition.setServiceMethods(services); } if (mpv.contains("rpcFilter")) { @SuppressWarnings("unchecked") ManagedMap<TypedStringValue, Object> rpcFilter = (ManagedMap<TypedStringValue, Object>) mpv .getPropertyValue("rpcFilter").getValue(); List<String> services = new ArrayList<String>(); for (TypedStringValue tsv : rpcFilter.keySet()) { services.add(tsv.getValue()); } definition.setServiceMethods(services); } return definition; }
From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java
/** * This overrides the method from WebDataBinder to allow for nested checkbox handling, so property paths such as * a._b will result in the boolean b on object a getting set to false. *//*from www.j a v a 2 s . c o m*/ @Override protected void checkFieldMarkers(MutablePropertyValues mpvs) { if (getFieldMarkerPrefix() == null) { return; } String fieldMarkerPrefix = getFieldMarkerPrefix(); PropertyValue[] pvArray = mpvs.getPropertyValues(); for (PropertyValue pv : pvArray) { // start of variation from superclass method if (propertyStartsWithFieldMarkerPrefix(pv, fieldMarkerPrefix)) { String field = stripFieldMarkerPrefix(pv.getName(), fieldMarkerPrefix); // end of variation from superclass method if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) { Class<?> fieldType = getPropertyAccessor().getPropertyType(field); mpvs.add(field, getEmptyValue(field, fieldType)); } mpvs.removePropertyValue(pv); } } }
From source file:org.kuali.rice.krad.datadictionary.MessageBeanProcessor.java
/** * Applies the given message text to the property within the given bean definition * * <p>/* w w w . j a v a 2 s .c o m*/ * The message text is applied to the bean definiton based on the property path. The path could be nested * in which case the property values of the bean definition are traversed to find the nested bean definition * that should hold the property value. The path could also represent a nested list bean. In this case a * helper method is called to find the correct list bean to apply the message to * </p> * * @param message message containing the text to apply * @param beanDefinition bean definition containing the property * @param propertyPath path to property within the bean definition the message should be applied to */ protected void applyMessageToNestedBean(Message message, BeanDefinition beanDefinition, String propertyPath) { MutablePropertyValues pvs = beanDefinition.getPropertyValues(); String beanPath = StringUtils.substringBefore(propertyPath, "."); String nestedPropertyPath = StringUtils.substringAfter(propertyPath, "."); boolean foundNestedBean = false; while (StringUtils.isNotBlank(nestedPropertyPath)) { if (pvs.contains(beanPath)) { PropertyValue propertyValue = pvs.getPropertyValue(beanPath); BeanDefinition propertyBeanDefinition = getPropertyValueBeanDefinition(propertyValue); if (propertyBeanDefinition != null) { applyMessageToNestedBean(message, propertyBeanDefinition, nestedPropertyPath); foundNestedBean = true; break; } else if (propertyValue.getValue() instanceof List) { applyMessageToNestedListBean(message, (List<?>) propertyValue.getValue(), nestedPropertyPath); foundNestedBean = true; break; } } beanPath += "." + StringUtils.substringBefore(nestedPropertyPath, "."); nestedPropertyPath = StringUtils.substringAfter(nestedPropertyPath, "."); } if (!foundNestedBean) { applyMessageTextToPropertyValue(propertyPath, message.getText(), beanDefinition); } }
From source file:org.kuali.rice.krad.datadictionary.MessageBeanProcessor.java
/** * Attempts to find a property value for the given property name within the bean definition, if the property * does not exist in the bean and there is a parent, the parent is checked for containing the property. This * continues until a property value is found or all the parents have been traversed * * @param beanDefinition bean definition to find property value in * @param propertyName name of the property to find the value for * @return String value for property in the bean definition or null if the property was not found *///from w w w.j a v a 2 s .c om protected String findPropertyValueInBeanDefinition(BeanDefinition beanDefinition, String propertyName) { String beanPropertyValue = null; MutablePropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(propertyName)) { PropertyValue propertyValue = pvs.getPropertyValue(propertyName); if (propertyValue.getValue() != null) { beanPropertyValue = propertyValue.getValue().toString(); } } else { if (StringUtils.isNotBlank(beanDefinition.getParentName())) { BeanDefinition parentBeanDefinition = beanFactory.getBeanDefinition(beanDefinition.getParentName()); beanPropertyValue = findPropertyValueInBeanDefinition(parentBeanDefinition, propertyName); } } return beanPropertyValue; }
From source file:org.kuali.rice.krad.datadictionary.MessageBeanProcessor.java
/** * Applies the given message text to the bean definition with the given property name, if a current * value exists for the property name the value is checked for expressions which are then merged with * the message/*from w w w.j a v a2 s .c o m*/ * * @param propertyName - name of the property to set on the bean definition * @param messageText - message text that will be the property value * @param beanDefinition - bean definition to set property on */ protected void applyMessageTextToPropertyValue(String propertyName, String messageText, BeanDefinition beanDefinition) { String newPropertyValue = messageText; MutablePropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(propertyName)) { PropertyValue propertyValue = pvs.getPropertyValue(propertyName); String stringPropertyValue = getStringValue(propertyValue.getValue()); if (StringUtils.isNotBlank(stringPropertyValue)) { newPropertyValue = getMergedMessageText(messageText, stringPropertyValue); } } applyPropertyValueToBean(propertyName, newPropertyValue, pvs); }