List of usage examples for org.springframework.beans.factory.config TypedStringValue TypedStringValue
public TypedStringValue(@Nullable String value)
From source file:com.easyshop.datasource.MyBatisBeanFactoryPostProcessor.java
/** * @param beanFactory// w w w . ja v a 2s . c o m * @throws BeansException * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) */ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { BeanDefinition bd = beanFactory.getBeanDefinition(sqlSessionFactoryBeanName); MutablePropertyValues propertyValues = bd.getPropertyValues(); PropertyValue propertyValue = propertyValues.getPropertyValue("mapperLocations"); Object value = propertyValue.getValue(); ManagedList<TypedStringValue> locations = new ManagedList<TypedStringValue>(); for (String location : mapperLocations) { locations.add(new TypedStringValue(location)); log.info(" SQL Mapper :{} " + location); } if (value == null) { PropertyValue newValue = new PropertyValue(propertyValue, locations); propertyValues.addPropertyValue(newValue); } else if (value instanceof String) { locations.add(new TypedStringValue((String) value)); PropertyValue newValue = new PropertyValue(propertyValue, locations); propertyValues.addPropertyValue(newValue); } else if (value instanceof ManagedList) { ((ManagedList) value).addAll(locations); } else if (value instanceof TypedStringValue) { locations.add((TypedStringValue) value); PropertyValue newValue = new PropertyValue(propertyValue, locations); propertyValues.addPropertyValue(newValue); } }
From source file:eap.config.AspectJAutoProxyBeanDefinitionParser.java
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<TypedStringValue>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); }/* w ww .j a v a 2 s . com*/ } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
From source file:com.helpinput.spring.refresher.SessiontRefresher.java
@SuppressWarnings("unchecked") ManagedList<Object> getManageList(DefaultListableBeanFactory dlbf, PropertyValue oldPropertyValue) { Set<String> oldClasses = null; if (oldPropertyValue != null) { Object value = oldPropertyValue.getValue(); if (value != null && value instanceof ManagedList) { ManagedList<Object> real = (ManagedList<Object>) value; oldClasses = new HashSet<>(real.size() >>> 1); ClassLoader parentClassLoader = ClassUtils.getDefaultClassLoader(); for (Object object : real) { TypedStringValue typedStringValue = (TypedStringValue) object; String className = typedStringValue.getValue(); try { parentClassLoader.loadClass(className); oldClasses.add(className); } catch (ClassNotFoundException e) { }/* w ww . java 2 s . c o m*/ } } } int oldClassSize = (Utils.hasLength(oldClasses) ? oldClasses.size() : 0); Map<String, Object> beans = dlbf.getBeansWithAnnotation(Entity.class); HashSet<String> totalClasses = new HashSet<>(beans.size() + oldClassSize); if (oldClassSize > 0) { totalClasses.addAll(oldClasses); } for (Object entity : beans.values()) { String clzName = entity.getClass().getName(); if (!totalClasses.contains(clzName)) { totalClasses.add(clzName); } } ManagedList<Object> list = new ManagedList<>(totalClasses.size()); for (String clzName : totalClasses) { TypedStringValue typedStringValue = new TypedStringValue(clzName); list.add(typedStringValue); } return list; }
From source file:com.developmentsprint.spring.breaker.config.BreakerAdviceParser.java
private RootBeanDefinition parseAttributeSource(List<Element> methods, ParserContext parserContext) { ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute> circuitBreakerAttributeMap = new ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute>( methods.size());/* w ww . jav a 2 s. c o m*/ circuitBreakerAttributeMap.setSource(parserContext.extractSource(methods)); for (Element methodEle : methods) { String methodName = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE); TypedStringValue nameHolder = new TypedStringValue(methodName); nameHolder.setSource(parserContext.extractSource(methodEle)); RuleBasedCircuitBreakerAttribute attribute = new RuleBasedCircuitBreakerAttribute(); attribute.setMethodName(methodName); String cbName = methodEle.getAttribute(CB_NAME_ATTRIBUTE); if (StringUtils.isEmpty(cbName)) { attribute.setName(methodName); } else { attribute.setName(cbName); } ManagedMap<String, String> props = new ManagedMap<String, String>(); Element propsElement = DomUtils.getChildElementByTagName(methodEle, "properties"); if (propsElement != null) { //Map<String, String> props = new HashMap<String, String>(); List<Element> propElements = DomUtils.getChildElementsByTagName(propsElement, "prop"); for (Element propElement : propElements) { String key = propElement.getAttribute("key"); String val = DomUtils.getTextValue(propElement); props.put(key, new TypedStringValue(val).getValue()); } attribute.setProperties(props); } if (log.isDebugEnabled()) { for (Map.Entry<String, String> e : attribute.getProperties().entrySet()) { log.debug("{} prop : {} : {}", cbName, e.getKey(), e.getValue()); } } circuitBreakerAttributeMap.put(nameHolder, attribute); } RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition( NameMatchCircuitBreakerAttributeSource.class); attributeSourceDefinition.setSource(parserContext.extractSource(methods)); attributeSourceDefinition.getPropertyValues().add("nameMap", circuitBreakerAttributeMap); return attributeSourceDefinition; }
From source file:com.himanshu.spring.context.loader.sameconfigallcontext.bean.visitor.BeanVisitor.java
private TypedStringValue insertPrefixToProperty(TypedStringValue typedStringValue) { return new TypedStringValue(insertPrefixToProperty(typedStringValue.getValue())); }
From source file:com.wavemaker.runtime.data.cloudfoundry.CloudFoundryDataServiceBeanFactoryPostProcessor.java
/** * @param beanFactory// w ww. ja v a 2 s.c om */ private void processHibernateProperties(DefaultListableBeanFactory beanFactory) { String[] sessionFactoryBeanNames = beanFactory .getBeanNamesForType(ConfigurationAndSessionFactoryBean.class); for (String sfBean : sessionFactoryBeanNames) { BeanDefinition beanDefinition = getBeanDefinition(beanFactory, sfBean); if (sfBean.contains(DataServiceConstants.AUX_BEAN_SUFFIX)) { beanDefinition.setLazyInit(false); } else { beanDefinition.setLazyInit(true); } MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); PropertyValue hibernateProperties = propertyValues.getPropertyValue("hibernateProperties"); ManagedProperties hibernatePropsPropertyValue = null; if (hibernateProperties != null) { Object value = hibernateProperties.getValue(); if (value instanceof ManagedProperties) { hibernatePropsPropertyValue = (ManagedProperties) hibernateProperties.getValue(); TypedStringValue dialect = (TypedStringValue) hibernatePropsPropertyValue .get(new TypedStringValue(DataServiceConstants.HIBERNATE_DIALECT_PROPERTY)); if (dialect != null && dialect .equals(new TypedStringValue("com.wavemaker.runtime.data.dialect.MySQLDialect"))) { hibernatePropsPropertyValue.put( new TypedStringValue(DataServiceConstants.HIBERNATE_DIALECT_PROPERTY), new TypedStringValue("org.hibernate.dialect.MySQLDialect")); } } } else { hibernatePropsPropertyValue = new ManagedProperties(); } } }
From source file:eap.config.TxAdviceBeanDefinitionParser.java
private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) { List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT); ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap = new ManagedMap<TypedStringValue, RuleBasedTransactionAttribute>( methods.size());/*from w w w. java2s. c o m*/ transactionAttributeMap.setSource(parserContext.extractSource(attrEle)); for (Element methodEle : methods) { String name = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE); TypedStringValue nameHolder = new TypedStringValue(name); nameHolder.setSource(parserContext.extractSource(methodEle)); RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute(); String propagation = methodEle.getAttribute(PROPAGATION_ATTRIBUTE); String isolation = methodEle.getAttribute(ISOLATION_ATTRIBUTE); String timeout = methodEle.getAttribute(TIMEOUT_ATTRIBUTE); String readOnly = methodEle.getAttribute(READ_ONLY_ATTRIBUTE); if (StringUtils.hasText(propagation)) { attribute .setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation); } if (StringUtils.hasText(isolation)) { attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation); } if (StringUtils.hasText(timeout)) { try { attribute.setTimeout(Integer.parseInt(timeout)); } catch (NumberFormatException ex) { parserContext.getReaderContext().error("Timeout must be an integer value: [" + timeout + "]", methodEle); } } if (StringUtils.hasText(readOnly)) { attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY_ATTRIBUTE))); } List<RollbackRuleAttribute> rollbackRules = new LinkedList<RollbackRuleAttribute>(); if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) { String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE); addRollbackRuleAttributesTo(rollbackRules, rollbackForValue); } if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) { String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE); addNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue); } attribute.setRollbackRules(rollbackRules); transactionAttributeMap.put(nameHolder, attribute); } RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition( NameMatchTransactionAttributeSource.class); attributeSourceDefinition.setSource(parserContext.extractSource(attrEle)); attributeSourceDefinition.getPropertyValues().add("nameMap", transactionAttributeMap); return attributeSourceDefinition; }
From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java
@Test public void existingPropertiesFactoryBeanLocationTypedStringValue() { BeanReference br = new RuntimeBeanNameReference(this.beanName); this.propertyValues.addPropertyValue(this.key, br); when(this.beanDefinition.getBeanClassName()).thenReturn(PropertiesFactoryBean.class.getCanonicalName()); this.propertyValues.addPropertyValue("location", new TypedStringValue("alpha.properties")); this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties); assertTrue(this.propertyValues.contains(this.key)); assertContainsKey("alpha"); }
From source file:cn.guoyukun.spring.SpeedUpSpringProcessor.java
private boolean needRemove(String beanName, BeanDefinition beanDefinition) { if (ArrayUtils.isNotEmpty(removedBeanNames)) { for (String removedBeanName : removedBeanNames) { if (beanName.equals(removedBeanName)) { return true; }//from ww w .j av a 2 s . co m if (beanDefinition.getBeanClassName().equals(removedBeanName)) { return true; } } } if (this.removedBeanProperties != null) { Set<String[]> propertiesSet = removedBeanProperties.get(beanName); if (propertiesSet != null) { Iterator<String[]> iter = propertiesSet.iterator(); MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); while (iter.hasNext()) { String[] properties = iter.next(); if (properties.length == 1) { // propertyValues.removePropertyValue(properties[0]); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0]; if (this.replaceBeanProperties.containsKey(key)) { propertyValues.add(properties[0], this.replaceBeanProperties.get(key)); } } } else { PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]); if (propertyValue != null) { Object nextValue = propertyValue.getValue(); //??? + Map if (nextValue instanceof ManagedMap) { TypedStringValue typedStringValue = new TypedStringValue(properties[1]); ((ManagedMap) nextValue).remove(typedStringValue); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0] + "@" + properties[1]; if (this.replaceBeanProperties.containsKey(key)) { ((ManagedMap) nextValue).put(properties[1], this.replaceBeanProperties.get(key)); } } } } } } } } String className = beanDefinition.getBeanClassName(); //spring data jpa if (className.equals("cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepositoryFactoryBean") || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) { PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues() .getPropertyValue("repositoryInterface"); if (repositoryInterfaceValue != null) { className = repositoryInterfaceValue.getValue().toString(); } } if (ArrayUtils.isEmpty(this.removedClassPatterns)) { return false; } if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) { for (String includeClassPattern : includeClassPatterns) { if (className.matches(includeClassPattern)) { return false; } } } for (String removedClassPattern : removedClassPatterns) { if (className.matches(removedClassPattern)) { return true; } } return false; }
From source file:com.luna.common.spring.SpeedUpSpringProcessor.java
private boolean needRemove(String beanName, BeanDefinition beanDefinition) { if (ArrayUtils.isNotEmpty(removedBeanNames)) { for (String removedBeanName : removedBeanNames) { if (beanName.equals(removedBeanName)) { return true; }/*from w w w. j a v a 2s . c o m*/ if (beanDefinition.getBeanClassName().equals(removedBeanName)) { return true; } } } if (this.removedBeanProperties != null) { Set<String[]> propertiesSet = removedBeanProperties.get(beanName); if (propertiesSet != null) { Iterator<String[]> iter = propertiesSet.iterator(); MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); while (iter.hasNext()) { String[] properties = iter.next(); if (properties.length == 1) { // propertyValues.removePropertyValue(properties[0]); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0]; if (this.replaceBeanProperties.containsKey(key)) { propertyValues.add(properties[0], this.replaceBeanProperties.get(key)); } } } else { PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]); if (propertyValue != null) { Object nextValue = propertyValue.getValue(); //??? + Map if (nextValue instanceof ManagedMap) { TypedStringValue typedStringValue = new TypedStringValue(properties[1]); ((ManagedMap) nextValue).remove(typedStringValue); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0] + "@" + properties[1]; if (this.replaceBeanProperties.containsKey(key)) { ((ManagedMap) nextValue).put(properties[1], this.replaceBeanProperties.get(key)); } } } } } } } } String className = beanDefinition.getBeanClassName(); //spring data jpa if (className.equals("com.luna.common.repository.support.SimpleBaseRepositoryFactoryBean") || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) { PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues() .getPropertyValue("repositoryInterface"); if (repositoryInterfaceValue != null) { className = repositoryInterfaceValue.getValue().toString(); } } if (ArrayUtils.isEmpty(this.removedClassPatterns)) { return false; } if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) { for (String includeClassPattern : includeClassPatterns) { if (className.matches(includeClassPattern)) { return false; } } } for (String removedClassPattern : removedClassPatterns) { if (className.matches(removedClassPattern)) { return true; } } return false; }