Java Code Examples for org.springframework.beans.factory.config.BeanDefinition#getPropertyValues()
The following examples show how to use
org.springframework.beans.factory.config.BeanDefinition#getPropertyValues() .
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: DictionaryBeanFactoryPostProcessor.java From rice with Educational Community License v2.0 | 6 votes |
/** * Iterates through the properties defined for the bean definition and invokes helper methods to process * the property value * * @param beanDefinition bean definition whose properties will be processed * @param nestedBeanStack stack of beans which contain the given bean */ protected void processBeanProperties(BeanDefinition beanDefinition, Stack<BeanDefinitionHolder> nestedBeanStack) { // iterate through properties and check for any configured message keys within the value MutablePropertyValues pvs = beanDefinition.getPropertyValues(); PropertyValue[] pvArray = pvs.getPropertyValues(); for (PropertyValue pv : pvArray) { Object newPropertyValue = null; if (isStringValue(pv.getValue())) { newPropertyValue = processStringPropertyValue(pv.getName(), getString(pv.getValue()), nestedBeanStack); } else { newPropertyValue = visitPropertyValue(pv.getName(), pv.getValue(), nestedBeanStack); } pvs.removePropertyValue(pv.getName()); pvs.addPropertyValue(pv.getName(), newPropertyValue); } }
Example 2
Source File: MessageBeanProcessor.java From rice with Educational Community License v2.0 | 6 votes |
/** * Retrieves the component code associated with the bean definition * * @param beanName name of the bean to find component code for * @param beanDefinition bean definition to find component code for * @return String component code for bean or null if a component code was not found */ protected String getComponentForBean(String beanName, BeanDefinition beanDefinition) { String componentCode = null; MutablePropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(KRADPropertyConstants.COMPONENT_CODE)) { PropertyValue propertyValue = pvs.getPropertyValue(KRADPropertyConstants.COMPONENT_CODE); componentCode = getStringValue(propertyValue.getValue()); } if ((componentCode == null) && StringUtils.isNotBlank(beanName) && !isGeneratedBeanName(beanName)) { componentCode = beanName; } if (StringUtils.isNotBlank(componentCode)) { componentCode = StringUtils.removeEnd(componentCode, KRADConstants.DICTIONARY_BEAN_PARENT_SUFFIX); } return componentCode; }
Example 3
Source File: WebRemoteProxyBeanCreator.java From cuba with Apache License 2.0 | 6 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String useLocal = AppContext.getProperty("cuba.useLocalServiceInvocation"); if (Boolean.valueOf(useLocal)) { log.info("Configuring proxy beans for local service invocations: {}", services.keySet()); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; for (Map.Entry<String, String> entry : services.entrySet()) { String name = entry.getKey(); String serviceInterface = entry.getValue(); BeanDefinition definition = new RootBeanDefinition(serviceProxyClass); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.add("serviceName", name); propertyValues.add("serviceInterface", serviceInterface); registry.registerBeanDefinition(name, definition); log.debug("Configured proxy bean {} of type {}", name, serviceInterface); } processSubstitutions(beanFactory); } else { super.postProcessBeanFactory(beanFactory); } }
Example 4
Source File: SpringCloudConfiguration.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[i]); String beanClassName = beanDef.getBeanClassName(); if (FEIGN_FACTORY_CLASS.equals(beanClassName) == false) { continue; } MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); String client = String.valueOf(pv.getValue() == null ? "" : pv.getValue()); if (StringUtils.isNotBlank(client)) { this.transientClientSet.add(client); } } this.fireAfterPropertiesSet(); }
Example 5
Source File: SpringCloudSecondaryConfiguration.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[i]); String beanClassName = beanDef.getBeanClassName(); if (FEIGN_FACTORY_CLASS.equals(beanClassName) == false) { continue; } MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); String client = String.valueOf(pv.getValue() == null ? "" : pv.getValue()); if (StringUtils.isNotBlank(client)) { this.transientClientSet.add(client); } } this.fireAfterPropertiesSet(); }
Example 6
Source File: RemoteProxyBeanCreator.java From cuba with Apache License 2.0 | 6 votes |
protected void processSubstitutions(ConfigurableListableBeanFactory beanFactory) { if (substitutions != null) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; for (Map.Entry<String, String> entry : substitutions.entrySet()) { // replace bean with substitution bean if (beanFactory.containsBean(entry.getKey())) { String beanName = entry.getKey(); String beanClass = entry.getValue(); BeanDefinition definition = new RootBeanDefinition(beanClass); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.add("substitutedBean", beanFactory.getBean(beanName)); registry.registerBeanDefinition(beanName, definition); } } } }
Example 7
Source File: BeanComponentDefinition.java From blog_demos with Apache License 2.0 | 6 votes |
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) { List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>(); List<BeanReference> references = new ArrayList<BeanReference>(); PropertyValues propertyValues = beanDefinition.getPropertyValues(); for (int i = 0; i < propertyValues.getPropertyValues().length; i++) { PropertyValue propertyValue = propertyValues.getPropertyValues()[i]; Object value = propertyValue.getValue(); if (value instanceof BeanDefinitionHolder) { innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition()); } else if (value instanceof BeanDefinition) { innerBeans.add((BeanDefinition) value); } else if (value instanceof BeanReference) { references.add((BeanReference) value); } } this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]); this.beanReferences = references.toArray(new BeanReference[references.size()]); }
Example 8
Source File: AdvisorComponentDefinition.java From spring-analysis-note with MIT License | 6 votes |
public AdvisorComponentDefinition( String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) { Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null"); Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null"); this.advisorBeanName = advisorBeanName; this.advisorDefinition = advisorDefinition; MutablePropertyValues pvs = advisorDefinition.getPropertyValues(); BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName"); Assert.state(adviceReference != null, "Missing 'adviceBeanName' property"); if (pointcutDefinition != null) { this.beanReferences = new BeanReference[] {adviceReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition}; this.description = buildDescription(adviceReference, pointcutDefinition); } else { BeanReference pointcutReference = (BeanReference) pvs.get("pointcut"); Assert.state(pointcutReference != null, "Missing 'pointcut' property"); this.beanReferences = new BeanReference[] {adviceReference, pointcutReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition}; this.description = buildDescription(adviceReference, pointcutReference); } }
Example 9
Source File: BeanComponentDefinition.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) { List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>(); List<BeanReference> references = new ArrayList<BeanReference>(); PropertyValues propertyValues = beanDefinition.getPropertyValues(); for (int i = 0; i < propertyValues.getPropertyValues().length; i++) { PropertyValue propertyValue = propertyValues.getPropertyValues()[i]; Object value = propertyValue.getValue(); if (value instanceof BeanDefinitionHolder) { innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition()); } else if (value instanceof BeanDefinition) { innerBeans.add((BeanDefinition) value); } else if (value instanceof BeanReference) { references.add((BeanReference) value); } } this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]); this.beanReferences = references.toArray(new BeanReference[references.size()]); }
Example 10
Source File: MessageBeanProcessor.java From rice with Educational Community License v2.0 | 6 votes |
/** * 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 */ 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; }
Example 11
Source File: UifBeanFactoryPostProcessor.java From rice with Educational Community License v2.0 | 5 votes |
/** * Processes a top level (non nested) bean definition for expressions * * <p> * A bean that is non nested (or top of a collection) will hold all the expressions for the graph. A new * expression graph is initialized and expressions are collected as the bean and all its children are processed. * The expression graph is then set as a property on the top bean definition * </p> * * @param beanName name of the bean to process * @param beanDefinition bean definition to process * @param beanFactory factory holding all the bean definitions * @param processedBeanNames set of bean names that have already been processed */ protected void processBeanDefinition(String beanName, BeanDefinition beanDefinition, ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) { Class<?> beanClass = getBeanClass(beanDefinition, beanFactory); if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains( beanName)) { return; } // process bean definition and all nested definitions for expressions ManagedMap<String, String> expressionGraph = new ManagedMap<String, String>(); MutablePropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(UifPropertyPaths.EXPRESSION_GRAPH)) { expressionGraph = (ManagedMap<String, String>) pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH) .getValue(); if (expressionGraph == null) { expressionGraph = new ManagedMap<String, String>(); } } expressionGraph.setMergeEnabled(false); processNestedBeanDefinition(beanName, beanDefinition, "", expressionGraph, beanFactory, processedBeanNames); // add property for expression graph pvs = beanDefinition.getPropertyValues(); pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, expressionGraph); }
Example 12
Source File: UifDictionaryIndex.java From rice with Educational Community License v2.0 | 5 votes |
/** * Retrieves the configured property values for the view bean definition associated with the given type and * index * * <p> * Since constructing the View object can be expensive, when metadata only is needed this method can be used * to retrieve the configured property values. Note this looks at the merged bean definition * </p> * * @param viewTypeName - type name for the view * @param indexKey - Map of index key parameters, these are the parameters the indexer used to index * the view initially and needs to identify an unique view instance * @return PropertyValues configured on the view bean definition, or null if view is not found */ public PropertyValues getViewPropertiesByType(ViewType viewTypeName, Map<String, String> indexKey) { String index = buildTypeIndex(indexKey); ViewTypeDictionaryIndex typeIndex = getTypeIndex(viewTypeName); String beanName = typeIndex.get(index); if (StringUtils.isNotBlank(beanName)) { BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName); return beanDefinition.getPropertyValues(); } return null; }
Example 13
Source File: MessageBeanProcessor.java From rice with Educational Community License v2.0 | 5 votes |
/** * Applies the text for a given message to the associated bean definition property * * @param message message instance to apply * @param beanDefinition bean definition the message should be applied to * @param beanClass class for the bean definition */ protected void applyMessageToBean(Message message, BeanDefinition beanDefinition, Class<?> beanClass) { String key = message.getKey().trim(); // if message doesn't start with path indicator, it will be an explicit key that is matched when // iterating over the property values, so we will just return in that case if (!key.startsWith(KRADConstants.MESSAGE_KEY_PATH_INDICATOR)) { return; } // if here dealing with a path key, strip off indicator and then process as a property path key = StringUtils.stripStart(key, KRADConstants.MESSAGE_KEY_PATH_INDICATOR); // list factory beans just have the one list property (with no name) if (ListFactoryBean.class.isAssignableFrom(beanClass)) { MutablePropertyValues pvs = beanDefinition.getPropertyValues(); PropertyValue propertyValue = pvs.getPropertyValueList().get(0); List<?> listValue = (List<?>) propertyValue.getValue(); applyMessageToNestedListBean(message, listValue, key); } else if (StringUtils.contains(key, ".")) { applyMessageToNestedBean(message, beanDefinition, key); } else { applyMessageTextToPropertyValue(key, message.getText(), beanDefinition); } }
Example 14
Source File: SpringCamelContextBootstrap.java From wildfly-camel with Apache License 2.0 | 5 votes |
/** * Gets JNDI names for all configured instances of {@link JndiObjectFactoryBean} * * Note: If this method is invoked before ApplicationContext.refresh() then any bean property * values containing property placeholders will not be resolved. * * @return the unmodifiable list of JNDI binding names */ public List<String> getJndiNames() { List<String> bindings = new ArrayList<>(); for(String beanName : applicationContext.getBeanDefinitionNames()) { BeanDefinition definition = applicationContext.getBeanDefinition(beanName); String beanClassName = definition.getBeanClassName(); if (beanClassName != null && beanClassName.equals(JndiObjectFactoryBean.class.getName())) { MutablePropertyValues propertyValues = definition.getPropertyValues(); Object jndiPropertyValue = propertyValues.get("jndiName"); if (jndiPropertyValue == null) { LOGGER.debug("Skipping JNDI binding dependency for bean: {}", beanName); continue; } String jndiName = null; if (jndiPropertyValue instanceof String) { jndiName = (String) jndiPropertyValue; } else if (jndiPropertyValue instanceof TypedStringValue) { jndiName = ((TypedStringValue) jndiPropertyValue).getValue(); } else { LOGGER.debug("Ignoring unknown JndiObjectFactoryBean property value type {}", jndiPropertyValue.getClass().getSimpleName()); } if (jndiName != null) { bindings.add(jndiName); } } } return Collections.unmodifiableList(bindings); }
Example 15
Source File: DataDictionary.java From rice with Educational Community License v2.0 | 5 votes |
/** * Returns a property value for the bean with the given name from the dictionary. * * @param beanName id or name for the bean definition * @param propertyName name of the property to retrieve, must be a valid property configured on * the bean definition * @return Object property value for property */ public Object getDictionaryBeanProperty(String beanName, String propertyName) { Object bean = ddBeans.getSingleton(beanName); if (bean != null) { return ObjectPropertyUtils.getPropertyValue(bean, propertyName); } BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName); if (beanDefinition == null) { throw new RuntimeException("Unable to get bean for bean name: " + beanName); } PropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(propertyName)) { PropertyValue propertyValue = pvs.getPropertyValue(propertyName); Object value; if (propertyValue.isConverted()) { value = propertyValue.getConvertedValue(); } else if (propertyValue.getValue() instanceof String) { String unconvertedValue = (String) propertyValue.getValue(); Scope scope = ddBeans.getRegisteredScope(beanDefinition.getScope()); BeanExpressionContext beanExpressionContext = new BeanExpressionContext(ddBeans, scope); value = ddBeans.getBeanExpressionResolver().evaluate(unconvertedValue, beanExpressionContext); } else { value = propertyValue.getValue(); } return value; } return null; }
Example 16
Source File: MyBeanFactoryPostProcessor.java From java-tutorial with MIT License | 5 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { System.out.println("BeanFactoryPostProcessor 调用 postProcessBeanFactory 方法"); BeanDefinition bd = configurableListableBeanFactory.getBeanDefinition("student"); MutablePropertyValues propertyValues = bd.getPropertyValues(); //配置文件中的信息在加载到Spring中后以BeanDefinition的形式存在.在这里又可以更改BeanDefinition,所以可以理解为更改配置文件里面的内容 // propertyValues.add("zdy","123"); }
Example 17
Source File: CustomNamespaceHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { Element element = (Element) node; BeanDefinition def = definition.getBeanDefinition(); MutablePropertyValues mpvs = (def.getPropertyValues() == null) ? new MutablePropertyValues() : def.getPropertyValues(); mpvs.add("name", element.getAttribute("name")); mpvs.add("age", element.getAttribute("age")); ((AbstractBeanDefinition) def).setPropertyValues(mpvs); return definition; }
Example 18
Source File: UifDictionaryIndex.java From rice with Educational Community License v2.0 | 4 votes |
/** * Initializes the view index {@code Map} then iterates through all the * beans in the factory that implement {@code View}, adding them to the * index */ protected void buildViewIndicies() { LOG.info("Starting View Index Building"); viewBeanEntriesById = new HashMap<String, String>(); viewEntriesByType = new HashMap<String, ViewTypeDictionaryIndex>(); viewPools = new HashMap<String, UifViewPool>(); boolean inDevMode = Boolean.parseBoolean(ConfigContext.getCurrentContextConfig().getProperty( KRADConstants.ConfigParameters.KRAD_DEV_MODE)); ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize); String[] beanNames = ddBeans.getBeanNamesForType(View.class); for (final String beanName : beanNames) { BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName); PropertyValues propertyValues = beanDefinition.getPropertyValues(); String id = ViewModelUtils.getStringValFromPVs(propertyValues, "id"); if (StringUtils.isBlank(id)) { id = beanName; } if (viewBeanEntriesById.containsKey(id)) { throw new DataDictionaryException("Two views must not share the same id. Found duplicate id: " + id); } viewBeanEntriesById.put(id, beanName); indexViewForType(propertyValues, id); // pre-load views if necessary if (!inDevMode) { String poolSizeStr = ViewModelUtils.getStringValFromPVs(propertyValues, "preloadPoolSize"); if (StringUtils.isNotBlank(poolSizeStr)) { int poolSize = Integer.parseInt(poolSizeStr); if (poolSize < 1) { continue; } final View view = (View) ddBeans.getBean(beanName); final UifViewPool viewPool = new UifViewPool(); viewPool.setMaxSize(poolSize); for (int j = 0; j < poolSize; j++) { Runnable createView = new Runnable() { @Override public void run() { viewPool.addViewInstance((View) CopyUtils.copy(view)); } }; executor.execute(createView); } viewPools.put(id, viewPool); } } } executor.shutdown(); LOG.info("Completed View Index Building"); }
Example 19
Source File: RemoteServicesBeanCreator.java From cuba with Apache License 2.0 | 4 votes |
@Override public void postProcessBeanFactory(@Nonnull ConfigurableListableBeanFactory beanFactory) throws BeansException { log.info("Configuring remote services"); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; ApplicationContext coreContext = context.getParent(); if (coreContext == null) { throw new RuntimeException("Parent Spring context is null"); } Map<String,Object> services = coreContext.getBeansWithAnnotation(Service.class); for (Map.Entry<String, Object> entry : services.entrySet()) { String serviceName = entry.getKey(); Object service = entry.getValue(); List<Class> serviceInterfaces = new ArrayList<>(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(service.getClass()); for (Class intf : interfaces) { if (intf.getName().endsWith("Service")) serviceInterfaces.add(intf); } String intfName = null; if (serviceInterfaces.size() == 0) { log.error("Bean " + serviceName + " has @Service annotation but no interfaces named '*Service'. Ignoring it."); } else if (serviceInterfaces.size() > 1) { intfName = findLowestSubclassName(serviceInterfaces); if (intfName == null) log.error("Bean " + serviceName + " has @Service annotation and more than one interface named '*Service', " + "but these interfaces are not from the same hierarchy. Ignoring it."); } else { intfName = serviceInterfaces.get(0).getName(); } if (intfName != null) { if (ServiceExportHelper.exposeServices()) { BeanDefinition definition = new RootBeanDefinition(HttpServiceExporter.class); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.add("service", service); propertyValues.add("serviceInterface", intfName); registry.registerBeanDefinition("/" + serviceName, definition); log.debug("Bean " + serviceName + " configured for export via HTTP"); } else { ServiceExportHelper.registerLocal("/" + serviceName, service); } } } }
Example 20
Source File: UifDictionaryIndex.java From rice with Educational Community License v2.0 | 3 votes |
/** * Retrieves the configured property values for the view bean definition associated with the given id * * <p> * Since constructing the View object can be expensive, when metadata only is needed this method can be used * to retrieve the configured property values. Note this looks at the merged bean definition * </p> * * @param viewId - id for the view to retrieve * @return PropertyValues configured on the view bean definition, or null if view is not found */ public PropertyValues getViewPropertiesById(String viewId) { String beanName = viewBeanEntriesById.get(viewId); if (StringUtils.isNotBlank(beanName)) { BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName); return beanDefinition.getPropertyValues(); } return null; }