List of usage examples for org.springframework.beans PropertyValue getName
public String getName()
From source file:org.springmodules.cache.config.ConfigAssert.java
/** * Asserts the given set of property values contains the expected property * value./*from w w w. j ava2 s . c o m*/ * * @param propertyValues * the given set of property values * @param expectedPropertyValue * the expected property value */ public static void assertPropertyIsPresent(MutablePropertyValues propertyValues, PropertyValue expectedPropertyValue) { String propertyName = expectedPropertyValue.getName(); PropertyValue actualPropertyValue = propertyValues.getPropertyValue(propertyName); Assert.assertNotNull("Property " + StringUtils.quote(propertyName) + " not found", actualPropertyValue); Object expectedValue = expectedPropertyValue.getValue(); Object actualValue = actualPropertyValue.getValue(); String message = "<Property " + StringUtils.quote(propertyName) + ">"; assertEquals(message, expectedValue, actualValue); }
From source file:me.springframework.di.spring.SpringConfigurationLoader.java
/** * Loads a {@link MutableInstance} from one of the {@link BeanDefinition}s * provided by the {@link BeanDefinitionRegistry} passed in. * /*from www .j a va 2 s .c o m*/ * @param instance * A {@link MutableInstance} to be populated. * @param definition * A {@link BeanDefinition}, providing the meta data. */ private static void load(MutableInstance instance, BeanDefinition definition, MutableContext context) { instance.setReferencedType(definition.getBeanClassName()); instance.setPrimitive(false); instance.setLazyInit(definition.isLazyInit()); instance.setId("source" + counter++); instance.setFactoryMethod(definition.getFactoryMethodName()); instance.setFactoryInstance(definition.getFactoryBeanName()); if (ConfigurableBeanFactory.SCOPE_SINGLETON.equals(definition.getScope())) { instance.setScope(Scope.SINGLETON); } if (ConfigurableBeanFactory.SCOPE_PROTOTYPE.equals(definition.getScope())) { instance.setScope(Scope.PROTOTYPE); } if (definition instanceof AbstractBeanDefinition) { instance.setInitMethod(((AbstractBeanDefinition) definition).getInitMethodName()); instance.setDestroyMethod(((AbstractBeanDefinition) definition).getDestroyMethodName()); } if (!definition.getConstructorArgumentValues().isEmpty()) { List<MutableConstructorArgument> arguments = new ArrayList<MutableConstructorArgument>(); for (Object object : definition.getConstructorArgumentValues().getGenericArgumentValues()) { MutableConstructorArgument argument = new MutableConstructorArgument(instance); argument.setInstance(instance); ValueHolder holder = (ValueHolder) object; argument.setSource(loadSource(context, argument, holder.getValue())); argument.setType(holder.getType()); arguments.add(argument); } instance.setConstructorArguments(arguments); } Set<MutablePropertySetter> setters = new HashSet<MutablePropertySetter>(); for (Object object : definition.getPropertyValues().getPropertyValueList()) { MutablePropertySetter setter = new MutablePropertySetter(instance); setter.setInstance(instance); PropertyValue value = (PropertyValue) object; setter.setName(value.getName()); setter.setSource(loadSource(context, setter, value.getValue())); setters.add(setter); } instance.setSetters(setters); // added by woj instance.setAutowireCandidate(definition.isAutowireCandidate()); if (definition instanceof AbstractBeanDefinition) { instance.setAutowireMode(((AbstractBeanDefinition) definition).getResolvedAutowireMode()); } else { instance.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_NO); } }
From source file:org.uimafit.component.initialize.ConfigurationParameterInitializer.java
/** * Initialize a component from an {@link UimaContext} This code can be a little confusing * because the configuration parameter annotations are used in two contexts: in describing the * component and to initialize member variables from a {@link UimaContext}. Here we are * performing the latter task. It is important to remember that the {@link UimaContext} passed * in to this method may or may not have been derived using reflection of the annotations (i.e. * using {@link ConfigurationParameterFactory} via e.g. a call to a AnalysisEngineFactory.create * method). It is just as possible for the description of the component to come directly from an * XML descriptor file. So, for example, just because a configuration parameter specifies a * default value, this does not mean that the passed in context will have a value for that * configuration parameter. It should be possible for a descriptor file to specify its own value * or to not provide one at all. If the context does not have a configuration parameter, then * the default value provided by the developer as specified by the defaultValue element of the * {@link ConfigurationParameter} will be used. See comments in the code for additional details. * * @param component the component to initialize. * @param context a UIMA context with configuration parameters. *///from w w w .j a va 2s. c o m public static void initialize(final Object component, final UimaContext context) throws ResourceInitializationException { MutablePropertyValues values = new MutablePropertyValues(); List<String> mandatoryValues = new ArrayList<String>(); for (Field field : ReflectionUtil.getFields(component)) { // component.getClass().getDeclaredFields()) if (ConfigurationParameterFactory.isConfigurationParameterField(field)) { org.uimafit.descriptor.ConfigurationParameter annotation = field .getAnnotation(org.uimafit.descriptor.ConfigurationParameter.class); Object parameterValue; String parameterName = ConfigurationParameterFactory.getConfigurationParameterName(field); // Obtain either from the context - or - if the context does not provide the // parameter, check if there is a default value. Note there are three possibilities: // 1) Parameter present and set // 2) Parameter present and set to null (null value) // 3) Parameter not present (also provided as null value by UIMA) // Unfortunately we cannot make a difference between case 2 and 3 since UIMA does // not allow us to actually get a list of the parameters set in the context. We can // only get a list of the declared parameters. Thus we have to rely on the null // value. parameterValue = context.getConfigParameterValue(parameterName); if (parameterValue == null) { parameterValue = ConfigurationParameterFactory.getDefaultValue(field); } if (parameterValue != null) { values.addPropertyValue(field.getName(), parameterValue); } // TODO does this check really belong here? It seems that // this check is already performed by UIMA if (annotation.mandatory()) { mandatoryValues.add(field.getName()); // if (parameterValue == null) { // final String key = ResourceInitializationException.CONFIG_SETTING_ABSENT; // throw new ResourceInitializationException(key, // new Object[] { configurationParameterName }); // } } // else { // if (parameterValue == null) { // continue; // } // } // final Object fieldValue = convertValue(field, parameterValue); // try { // setParameterValue(component, field, fieldValue); // } // catch (Exception e) { // throw new ResourceInitializationException(e); // } } } DataBinder binder = new DataBinder(component) { @Override protected void checkRequiredFields(MutablePropertyValues mpvs) { String[] requiredFields = getRequiredFields(); if (!ObjectUtils.isEmpty(requiredFields)) { Map<String, PropertyValue> propertyValues = new HashMap<String, PropertyValue>(); PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { String canonicalName = PropertyAccessorUtils.canonicalPropertyName(pv.getName()); propertyValues.put(canonicalName, pv); } for (String field : requiredFields) { PropertyValue pv = propertyValues.get(field); boolean empty = (pv == null || pv.getValue() == null); // For our purposes, empty Strings or empty String arrays do not count as // empty. Empty is only "null". // if (!empty) { // if (pv.getValue() instanceof String) { // empty = !StringUtils.hasText((String) pv.getValue()); // } // else if (pv.getValue() instanceof String[]) { // String[] values = (String[]) pv.getValue(); // empty = (values.length == 0 || !StringUtils.hasText(values[0])); // } // } if (empty) { // Use bind error processor to create FieldError. getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult()); // Remove property from property values to bind: // It has already caused a field error with a rejected value. if (pv != null) { mpvs.removePropertyValue(pv); propertyValues.remove(field); } } } } } }; binder.initDirectFieldAccess(); PropertyEditorUtil.registerUimaFITEditors(binder); binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()])); binder.bind(values); if (binder.getBindingResult().hasErrors()) { StringBuilder sb = new StringBuilder(); sb.append("Errors initializing [" + component.getClass() + "]"); for (ObjectError error : binder.getBindingResult().getAllErrors()) { if (sb.length() > 0) { sb.append("\n"); } sb.append(error.getDefaultMessage()); } throw new IllegalArgumentException(sb.toString()); } }
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
static RSACBeanInfo convertBeanDef(BeanDefinition origdef, String beanname, ConfigurableListableBeanFactory factory, MethodAnalyser abdAnalyser, BeanDefConverter converter) { RSACBeanInfo rbi = new RSACBeanInfo(); AbstractBeanDefinition def = getMergedBeanDefinition(factory, beanname, origdef); MutablePropertyValues pvs = def.getPropertyValues(); PropertyValue[] values = pvs.getPropertyValues(); for (int j = 0; j < values.length; ++j) { PropertyValue thispv = values[j]; Object beannames = BeanDefUtil.propertyValueToBeanName(thispv.getValue(), converter); boolean skip = false; // skip recording the dependency if it was unresolvable (some // unrecognised // type) or was a single-valued type referring to a static dependency. // NB - we now record ALL dependencies - bean-copying strategy // discontinued. if (beannames == null // || beannames instanceof String // && !blankcontext.containsBean((String) beannames) ) {/*from ww w. ja v a 2 s . co m*/ skip = true; } if (!skip) { rbi.recordDependency(thispv.getName(), beannames); } } // NB - illegal cast here is unavoidable. // Bit of a problem here with Spring flow - apparently the bean class // will NOT be set for a "factory-method" bean UNTIL it has been // instantiated // via the logic in AbstractAutowireCapableBeanFactory l.376: // protected BeanWrapper instantiateUsingFactoryMethod( AbstractBeanDefinition abd = def; rbi.factorybean = abd.getFactoryBeanName(); rbi.factorymethod = abd.getFactoryMethodName(); rbi.initmethod = abd.getInitMethodName(); rbi.destroymethod = abd.getDestroyMethodName(); rbi.islazyinit = abd.isLazyInit(); rbi.dependson = abd.getDependsOn(); rbi.issingleton = abd.isSingleton(); rbi.isabstract = abd.isAbstract(); rbi.aliases = factory.containsBeanDefinition(beanname) ? factory.getAliases(beanname) : StringArrayParser.EMPTY_STRINGL; if (abd.hasConstructorArgumentValues()) { ConstructorArgumentValues cav = abd.getConstructorArgumentValues(); boolean hasgeneric = !cav.getGenericArgumentValues().isEmpty(); boolean hasindexed = !cav.getIndexedArgumentValues().isEmpty(); if (hasgeneric && hasindexed) { throw new UnsupportedOperationException("RSAC Bean " + beanname + " has both indexed and generic constructor arguments, which is not supported"); } if (hasgeneric) { List cvalues = cav.getGenericArgumentValues(); rbi.constructorargvals = new ConstructorArgumentValues.ValueHolder[cvalues.size()]; for (int i = 0; i < cvalues.size(); ++i) { rbi.constructorargvals[i] = (ConstructorArgumentValues.ValueHolder) cvalues.get(i); } } else if (hasindexed) { Map cvalues = cav.getIndexedArgumentValues(); rbi.constructorargvals = new ConstructorArgumentValues.ValueHolder[cvalues.size()]; for (int i = 0; i < cvalues.size(); ++i) { rbi.constructorargvals[i] = (ConstructorArgumentValues.ValueHolder) cvalues.get(new Integer(i)); } } } if (rbi.factorymethod == null) { // Core Spring change at 2.0M5 - ALL bean classes are now irrevocably // lazy!! // Package org.springframework.beans // introduced lazy loading (and lazy validation) of bean classes in // standard bean factories and bean definition readers AccessMethod bcnaccess = abdAnalyser.getAccessMethod("beanClassName"); if (bcnaccess != null) { String bcn = (String) bcnaccess.getChildObject(abd); if (bcn != null) { rbi.beanclass = ClassGetter.forName(bcn); if (rbi.beanclass == null) { throw new IllegalArgumentException("Class name " + bcn + " for bean definition with name " + beanname + " cannot be resolved"); } } } else { // all right then BE like that! We'll work out the class later. // NB - beandef.getBeanClass() was eliminated around 1.2, we must // use the downcast even earlier now. rbi.beanclass = abd.getBeanClass(); } } return rbi; }
From source file:org.sakaiproject.metaobj.utils.mvc.impl.MapWrapper.java
public void setPropertyValue(PropertyValue pv) throws BeansException { setPropertyValue(pv.getName(), pv.getValue()); }
From source file:com.himanshu.spring.context.loader.sameconfigallcontext.bean.visitor.BeanVisitor.java
private void visitProperties(MutablePropertyValues propertyValues) { for (PropertyValue propertyValue : propertyValues.getPropertyValueList()) { Object resolvedValue = resolveValue(propertyValue.getValue()); propertyValues.add(propertyValue.getName(), resolvedValue); }/* w w w. j a v a 2 s . c o m*/ }
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]; 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(); }/* w w w. j ava 2 s. c o m*/ 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:org.brekka.stillingar.spring.pc.PropertyDefChangeListener.java
/** * Update the property with the new value *///from w ww . j a v a2 s . co m @Override public void onChange(String newValue) { ConfigurableListableBeanFactory beanFactory = beanFactoryRef.get(); if (beanFactory == null) { return; } BeanDefinition beanDef = beanFactory.getMergedBeanDefinition(beanName); MutablePropertyValues mutablePropertyValues = beanDef.getPropertyValues(); PropertyValue propertyValue = mutablePropertyValues.getPropertyValue(propertyName); if (!ObjectUtils.nullSafeEquals(newValue, propertyValue.getValue())) { mutablePropertyValues.add(propertyValue.getName(), newValue); } }
From source file:org.guicerecipes.spring.converter.SpringConverter.java
protected String getSetterMethod(PropertyValue propertyValue) { String name = propertyValue.getName(); StringBuilder sb = new StringBuilder(propertyValue.getName().length() + 3); sb.append("set"); if (name.length() > 0) { sb.append(Character.toUpperCase(name.charAt(0))); sb.append(name.substring(1));//from www . ja va2 s.c om } return sb.toString(); }
From source file:org.solmix.runtime.support.spring.ContainerDefinitionParser.java
private void copyProps(BeanDefinitionBuilder src, BeanDefinition def) { for (PropertyValue v : src.getBeanDefinition().getPropertyValues().getPropertyValues()) { if (!"name".equals(v.getName())) { def.getPropertyValues().addPropertyValue(v.getName(), v.getValue()); }//from w w w . j av a 2 s .c om src.getBeanDefinition().getPropertyValues().removePropertyValue(v); } }