List of usage examples for org.springframework.beans MutablePropertyValues removePropertyValue
public void removePropertyValue(String propertyName)
From source file:com.mtgi.analytics.aop.config.v11.SchedulerActivationPostProcessor.java
/** * Convenience method to override a CronTrigger bean definition with the given cron expression * and base name.//from w ww . j ava2 s . co m */ public static void configureTriggerDefinition(BeanDefinition trigger, String cronExpression, String name) { MutablePropertyValues props = trigger.getPropertyValues(); if (cronExpression != null) { props.removePropertyValue("cronExpression"); props.addPropertyValue("cronExpression", cronExpression); } props.addPropertyValue("name", name + "_trigger"); unwrapInnerBean(trigger, "jobDetail").getPropertyValues().addPropertyValue("name", name + "_job"); }
From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java
/** * Convenience method to update a template bean definition from overriding XML data. * If <code>overrides</code> contains attribute <code>attribute</code> or a child element * with name <code>attribute</code>, transfer that * attribute as a bean property onto <code>template</code>, overwriting the default value. * @param reference if true, the value of the attribute is to be interpreted as a runtime bean name reference; otherwise it is interpreted as a literal value *//* w w w.j av a 2 s . co m*/ public static boolean overrideProperty(String attribute, BeanDefinition template, Element overrides, boolean reference) { Object value = null; if (overrides.hasAttribute(attribute)) { value = overrides.getAttribute(attribute); } else { NodeList children = overrides.getElementsByTagNameNS("*", attribute); if (children.getLength() == 1) { Element child = (Element) children.item(0); value = child.getTextContent(); } } if (value != null) { if (reference) value = new RuntimeBeanReference(value.toString()); String propName = Conventions.attributeNameToPropertyName(attribute); MutablePropertyValues props = template.getPropertyValues(); props.removePropertyValue(propName); props.addPropertyValue(propName, value); return true; } return false; }
From source file:com.helpinput.spring.refresher.SessiontRefresher.java
@Override public void refresh(ApplicationContext context, Map<Class<?>, ScanedType> scanedClasses) { boolean needRefreshSessionFactory = false; for (Entry<Class<?>, ScanedType> entry : scanedClasses.entrySet()) { if (entry.getValue().getValue() > ScanedType.SAME.getValue() && entry.getKey().getAnnotation(Entity.class) != null) { needRefreshSessionFactory = true; break; }//from ww w . j ava2 s.c om } if (needRefreshSessionFactory) { DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) ((AbstractApplicationContext) context) .getBeanFactory(); //testUserManager(dlbf); final String sessionFactory = "sessionFactory"; final String annotatedClasses = "annotatedClasses"; final String setSessionFactory = "setSessionFactory"; BeanDefinition oldSessionFactoryDef = dlbf.getBeanDefinition(sessionFactory); if (oldSessionFactoryDef != null) { dlbf.removeBeanDefinition(sessionFactory); MutablePropertyValues propertyValues = oldSessionFactoryDef.getPropertyValues(); PropertyValue oldPropertyValue = propertyValues.getPropertyValue(annotatedClasses); propertyValues.removePropertyValue(annotatedClasses); BeanDefinition newSessionFactoryDef = BeanDefinitionBuilder .rootBeanDefinition(oldSessionFactoryDef.getBeanClassName()).getBeanDefinition(); List<PropertyValue> propertyValueList = newSessionFactoryDef.getPropertyValues() .getPropertyValueList(); propertyValueList.addAll(propertyValues.getPropertyValueList()); propertyValueList.add(new PropertyValue(annotatedClasses, getManageList(dlbf, oldPropertyValue))); dlbf.registerBeanDefinition(sessionFactory, newSessionFactoryDef); SessionFactory sessionFactoryImpl = (SessionFactory) dlbf.getBean(sessionFactory); String[] beanNames = dlbf.getBeanDefinitionNames(); for (String beanName : beanNames) { BeanDefinition beanDefinition = dlbf.getBeanDefinition(beanName); PropertyValues pValues = beanDefinition.getPropertyValues(); if (pValues.getPropertyValue(sessionFactory) != null) { Object theBean = dlbf.getBean(beanName); Method method = Utils.findMethod(theBean, setSessionFactory, sessionFactoryImpl); if (method != null) Utils.InvokedMethod(theBean, method, sessionFactoryImpl); } } } } }
From source file:org.echocat.jomon.spring.BeanPostConfigurer.java
protected void removeOldPropertyIfNeeded(@Nonnull BeanAndPropertyName beanAndPropertyName, @Nonnull MutablePropertyValues propertyValues) { final PropertyValue propertyValue = propertyValues.getPropertyValue(beanAndPropertyName.getPropertyName()); if (propertyValue != null) { propertyValues.removePropertyValue(propertyValue); }//from w ww . j a va2 s .c o m }
From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java
public void initZookeeperAddressIfNecessary(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); if (com.alibaba.dubbo.config.RegistryConfig.class.getName().equals(beanDef.getBeanClassName())) { MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue protpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_PROTOCOL); PropertyValue addrpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_ADDRESS); String protocol = null; String address = null; if (addrpv == null) { throw new FatalBeanException("zookeeper address cannot be null!"); // should never happen } else if (protpv == null) { String value = String.valueOf(addrpv.getValue()); try { URL url = new URL(null, value, this); protocol = url.getProtocol(); address = url.getAuthority(); } catch (Exception ex) { throw new FatalBeanException("Unsupported format!"); }/* w w w .j ava2s.co m*/ } else { protocol = String.valueOf(protpv.getValue()); String value = StringUtils.trimToEmpty(String.valueOf(addrpv.getValue())); int index = value.indexOf(protocol); if (index == -1) { address = value; } else if (index == 0) { String str = StringUtils.trimToEmpty(value.substring(protocol.length())); if (str.startsWith("://")) { address = StringUtils.trimToEmpty(str.substring(3)); } else { throw new FatalBeanException("Unsupported format!"); } } else { throw new FatalBeanException("Unsupported format!"); } } if (KEY_DUBBO_REGISTRY_ZOOKEEPER.equalsIgnoreCase(protocol) == false) { throw new FatalBeanException("Unsupported protocol!"); } String addrKey = "zookeeperAddr"; String[] watcherBeanArray = beanFactory .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class); BeanDefinition watcherBeanDef = beanFactory.getBeanDefinition(watcherBeanArray[0]); MutablePropertyValues warcherMpv = watcherBeanDef.getPropertyValues(); PropertyValue warcherPv = warcherMpv.getPropertyValue(addrKey); if (warcherPv == null) { warcherMpv.addPropertyValue(new PropertyValue(addrKey, address)); } else { warcherMpv.removePropertyValue(addrKey); warcherMpv.addPropertyValue(new PropertyValue(addrKey, address)); } } } }
From source file:com.mtgi.analytics.aop.config.v11.BtManagerBeanDefinitionParser.java
@Override protected void transform(ConfigurableListableBeanFactory factory, BeanDefinition template, Element element, ParserContext parserContext) {/*from ww w.ja va 2 s .co m*/ ManagerComponentDefinition def = (ManagerComponentDefinition) parserContext.getContainingComponent(); String managerId = overrideAttribute(ATT_ID, template, element); if (managerId == null) template.setAttribute(ATT_ID, managerId = "defaultTrackingManager"); if ("false".equals(element.getAttribute(ATT_ENABLED))) { //manager is disabled. replace definition with dummy instance. template.setBeanClassName(DisabledBehaviorTrackingManager.class.getName()); //clear properties and attributes. for (String att : template.attributeNames()) if (!ATT_ID.equals(att)) template.removeAttribute(att); template.getPropertyValues().clear(); //terminate immediately, do not parse any nested definitions (persisters, AOP config, context beans, etc) return; } overrideProperty(ATT_APPLICATION, template, element, false); overrideProperty(ATT_FLUSH_THRESHOLD, template, element, false); //wake up MBeanExporter if we're going to be doing MBean registration. if ("true".equalsIgnoreCase(element.getAttribute(ATT_REGISTER_MBEANS))) { AbstractBeanDefinition exporter = (AbstractBeanDefinition) factory .getBeanDefinition(CONFIG_MBEAN_EXPORTER); exporter.setLazyInit(false); //append manager ID to mbean name, in case of multiple managers in a single application. BeanDefinition naming = factory.getBeanDefinition(CONFIG_NAMING_STRATEGY); naming.getPropertyValues().addPropertyValue("value", managerId); } //prefer references to beans in the parent factory if they've been specified if (element.hasAttribute(ATT_MBEAN_SERVER)) factory.registerAlias(element.getAttribute(ATT_MBEAN_SERVER), CONFIG_MBEAN_SERVER); if (element.hasAttribute(ATT_SCHEDULER)) factory.registerAlias(element.getAttribute(ATT_SCHEDULER), CONFIG_SCHEDULER); if (element.hasAttribute(ATT_TASK_EXECUTOR)) factory.registerAlias(element.getAttribute(ATT_TASK_EXECUTOR), CONFIG_EXECUTOR); //make note of external persister element so that we don't activate log rotation. if (element.hasAttribute(ATT_PERSISTER)) { def.addNestedProperty(ATT_PERSISTER); MutablePropertyValues props = template.getPropertyValues(); props.removePropertyValue(ATT_PERSISTER); props.addPropertyValue(ATT_PERSISTER, new RuntimeBeanReference(element.getAttribute(ATT_PERSISTER))); } if (element.hasAttribute(ATT_SESSION_CONTEXT)) { //override default session context with reference def.addNestedProperty("sessionContext"); factory.registerAlias(element.getAttribute(ATT_SESSION_CONTEXT), CONFIG_SESSION_CONTEXT); } //handle AOP configuration if needed if (element.hasAttribute(ATT_METHOD_EXPRESSION)) { //activate global AOP proxying if it hasn't already been done (borrowed logic from AopNamespaceHandler / config element parser) activateAopProxies(parserContext, element); //register pointcut definition for the provided expression. RootBeanDefinition pointcut = new RootBeanDefinition(AspectJExpressionPointcut.class); //rely on deprecated method to maintain spring 2.0 support pointcut.setSingleton(false); pointcut.setSynthetic(true); pointcut.getPropertyValues().addPropertyValue("expression", element.getAttribute(ATT_METHOD_EXPRESSION)); //create implicit pointcut advice bean. RootBeanDefinition advice = new RootBeanDefinition(BehaviorTrackingAdvice.class); advice.getPropertyValues().addPropertyValue("trackingManager", new RuntimeBeanReference(managerId)); //register advice, pointcut, and advisor entry to bind the two together. XmlReaderContext ctx = parserContext.getReaderContext(); String pointcutId = ctx.registerWithGeneratedName(pointcut); String adviceId = ctx.registerWithGeneratedName(advice); RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); advisorDefinition.getPropertyValues().addPropertyValue("adviceBeanName", new RuntimeBeanNameReference(adviceId)); advisorDefinition.getPropertyValues().addPropertyValue("pointcut", new RuntimeBeanReference(pointcutId)); ctx.registerWithGeneratedName(advisorDefinition); } //configure flush trigger and job to be globally unique based on manager name. BeanDefinition flushTrigger = factory.getBeanDefinition("com.mtgi.analytics.btFlushTrigger"); SchedulerActivationPostProcessor.configureTriggerDefinition(flushTrigger, element.getAttribute(ATT_FLUSH_SCHEDULE), managerId + "_flush"); //set up a post-processor to register the flush job with the selected scheduler instance. the job and scheduler //come from the template factory, but the post-processor runs when the currently-parsing factory is finished. SchedulerActivationPostProcessor.registerPostProcessor(parserContext, factory, CONFIG_SCHEDULER, CONFIG_NAMESPACE + ".btFlushTrigger"); //ManagerComponentDefinition is a flag to nested parsers that they should push their parsed bean definitions into //the manager bean definition. for example, see BtPersisterBeanDefinitionParser. //descend on nested child nodes to pick up persister and session context configuration NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String namespaceUri = node.getNamespaceURI(); NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(namespaceUri); ParserContext nestedCtx = new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), template); nestedCtx.pushContainingComponent(def); handler.parse((Element) node, nestedCtx); } } if (!def.nestedProperties.contains(ATT_PERSISTER)) { //no persister registered. schedule default log rotation trigger. BtXmlPersisterBeanDefinitionParser.configureLogRotation(parserContext, factory, null); } if (!def.nestedProperties.contains("sessionContext")) { //custom session context not registered. select appropriate default class //depending on whether we are in a web context or not. if (parserContext.getReaderContext().getReader().getResourceLoader() instanceof WebApplicationContext) { BeanDefinition scDef = factory.getBeanDefinition(CONFIG_SESSION_CONTEXT); scDef.setBeanClassName(SpringSessionContext.class.getName()); } } }
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; }// w w w. j a va 2s.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 ww. j a v a 2 s . 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; }
From source file:com.cloudy.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 av a2s . 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.ibm.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; }
From source file:com.cykj.base.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 ww w . ja v a 2 s .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.sishuok.es.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; }