List of usage examples for org.springframework.beans MutablePropertyValues getPropertyValue
@Override
@Nullable
public PropertyValue getPropertyValue(String propertyName)
From source file:org.bytesoft.bytetcc.supports.spring.CompensableEndpointPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); BeanDefinition protocolDef = null;/*from w w w .j a v a 2 s . c om*/ List<BeanDefinition> beanDefList = new ArrayList<BeanDefinition>(); String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = null; try { beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { logger.debug("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex); continue; } if (CompensableEndpointAware.class.isAssignableFrom(beanClass)) { beanDefList.add(beanDef); } else if (ProtocolConfig.class.isAssignableFrom(beanClass)) { if (protocolDef == null) { protocolDef = beanDef; } else { throw new FatalBeanException( "There are more than one com.alibaba.dubbo.config.ProtocolConfig was found!"); } } } if (protocolDef == null) { throw new FatalBeanException( "No configuration of class com.alibaba.dubbo.config.ProtocolConfig was found."); } MutablePropertyValues protocolValues = protocolDef.getPropertyValues(); PropertyValue protocolValue = protocolValues.getPropertyValue("port"); if (protocolValue == null || protocolValue.getValue() == null) { throw new FatalBeanException("Attribute 'port' of <dubbo:protocol ... /> is null."); } String host = CommonUtils.getInetAddress(); String port = String.valueOf(protocolValue.getValue()); String identifier = String.format("%s:%s", host, port); for (int i = 0; i < beanDefList.size(); i++) { BeanDefinition beanDef = beanDefList.get(i); MutablePropertyValues mpv = beanDef.getPropertyValues(); mpv.addPropertyValue(CompensableEndpointAware.ENDPOINT_FIELD_NAME, identifier); } }
From source file:org.bytesoft.bytejta.supports.dubbo.TransactionConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); String applicationBeanId = null; String registryBeanId = null; String transactionBeanId = null; for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); if (com.alibaba.dubbo.config.ApplicationConfig.class.getName().equals(beanClassName)) { if (StringUtils.isBlank(applicationBeanId)) { applicationBeanId = beanName; } else { throw new FatalBeanException("There are more than one application name was found!"); }/*from ww w.jav a 2 s. co m*/ } else if (org.bytesoft.bytejta.TransactionCoordinator.class.getName().equals(beanClassName)) { if (StringUtils.isBlank(transactionBeanId)) { transactionBeanId = beanName; } else { throw new FatalBeanException( "There are more than one org.bytesoft.bytejta.TransactionCoordinator was found!"); } } else if (org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry.class.getName() .equals(beanClassName)) { if (StringUtils.isBlank(registryBeanId)) { registryBeanId = beanName; } else { throw new FatalBeanException( "There are more than one org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry was found!"); } } } if (StringUtils.isBlank(applicationBeanId)) { throw new FatalBeanException("No application name was found!"); } BeanDefinition beanDef = beanFactory.getBeanDefinition(applicationBeanId); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); if (pv == null || pv.getValue() == null || StringUtils.isBlank(String.valueOf(pv.getValue()))) { throw new FatalBeanException("No application name was found!"); } if (StringUtils.isBlank(transactionBeanId)) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytejta.TransactionCoordinator was found."); } else if (registryBeanId == null) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry was found."); } String application = String.valueOf(pv.getValue()); this.initializeForProvider(beanFactory, application, transactionBeanId); this.initializeForConsumer(beanFactory, application, registryBeanId); }
From source file:org.bytesoft.bytetcc.supports.dubbo.CompensableDubboConfigValidator.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); final Map<String, Class<?>> beanClassMap = new HashMap<String, Class<?>>(); final Map<String, BeanDefinition> serviceMap = new HashMap<String, BeanDefinition>(); final Map<String, BeanDefinition> references = new HashMap<String, BeanDefinition>(); String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = null; try {//from w ww . j a v a 2 s . c o m beanClass = cl.loadClass(beanClassName); beanClassMap.put(beanName, beanClass); } catch (Exception ex) { continue; } if (com.alibaba.dubbo.config.spring.ServiceBean.class.equals(beanClass)) { serviceMap.put(beanName, beanDef); } else if (com.alibaba.dubbo.config.spring.ReferenceBean.class.equals(beanClass)) { references.put(beanName, beanDef); } } for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); String beanKey = entry.getKey(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue ref = mpv.getPropertyValue("ref"); PropertyValue filter = mpv.getPropertyValue("filter"); PropertyValue group = mpv.getPropertyValue("group"); if (ref == null || ref.getValue() == null || RuntimeBeanReference.class.equals(ref.getValue().getClass()) == false) { continue; } RuntimeBeanReference beanRef = (RuntimeBeanReference) ref.getValue(); Class<?> refClass = beanClassMap.get(beanRef.getBeanName()); if (refClass.getAnnotation(Compensable.class) == null) { continue; } if (group == null || group.getValue() == null || KEY_GROUP_COMPENSABLE.equals(group.getValue()) == false) { logger.warn("The value of attr 'group'(beanId= {}) should be 'org.bytesoft.bytetcc'.", beanKey); continue; } else if (filter == null || filter.getValue() == null || KEY_FILTER_COMPENSABLE.equals(filter.getValue()) == false) { logger.warn("The value of attr 'filter'(beanId= {}) should be 'compensable'.", beanKey); continue; } PropertyValue timeoutPv = mpv.getPropertyValue(KEY_TIMEOUT); Object value = timeoutPv == null ? null : timeoutPv.getValue(); if (String.valueOf(Integer.MAX_VALUE).equals(value) == false) { throw new FatalBeanException(String.format("Timeout value(beanId= %s) must be %s." // , beanKey, Integer.MAX_VALUE)); } } for (Iterator<Map.Entry<String, BeanDefinition>> itr = references.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); String beanKey = entry.getKey(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue filter = mpv.getPropertyValue("filter"); PropertyValue group = mpv.getPropertyValue("group"); if (group == null || group.getValue() == null || KEY_GROUP_COMPENSABLE.equals(group.getValue()) == false) { logger.warn("The value of attr 'group'(beanId= {}) should be 'org.bytesoft.bytetcc'.", beanKey); continue; } else if (filter == null || filter.getValue() == null || KEY_FILTER_COMPENSABLE.equals(filter.getValue()) == false) { logger.warn("The value of attr 'filter'(beanId= {}) should be 'compensable'.", beanKey); continue; } PropertyValue timeoutPv = mpv.getPropertyValue(KEY_TIMEOUT); Object value = timeoutPv == null ? null : timeoutPv.getValue(); if (String.valueOf(Integer.MAX_VALUE).equals(value) == false) { throw new FatalBeanException( String.format("The value of attribute 'timeout' (beanId= %s) must be %s." // , beanKey, Integer.MAX_VALUE)); } } }
From source file:com.bstek.dorado.spring.ClassTypeListShortCutDecorator.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { AbstractBeanDefinition beanDef = (AbstractBeanDefinition) definition.getBeanDefinition(); MutablePropertyValues propertyValues = (beanDef.getPropertyValues() == null) ? new MutablePropertyValues() : beanDef.getPropertyValues(); ManagedList list = null;/*from ww w . ja v a2 s .c o m*/ boolean firstPropertyValue = propertyValues.getPropertyValue(IMPL_TYPES) == null; if (!firstPropertyValue) { list = (ManagedList) (propertyValues.getPropertyValue(IMPL_TYPES).getValue()); } else { list = new ManagedList(); list.setSource(node); list.setMergeEnabled(true); propertyValues.addPropertyValue(IMPL_TYPES, list); beanDef.setPropertyValues(propertyValues); } Element el = (Element) node; String className = el.getAttribute("name"); try { list.add(Class.forName(className)); } catch (ClassNotFoundException e) { logger.warn(e, e); } return definition; }
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 a va 2s.c o 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.dianping.zebra.monitor.spring.DataSourceAutoMonitor.java
@SuppressWarnings("unchecked") private void replaceInnerDataSourceInZebra(String beanName, BeanDefinition zebraDataSourceDefinition) { MutablePropertyValues propertyValues = zebraDataSourceDefinition.getPropertyValues(); PropertyValue dataSourcePoolVal = propertyValues.getPropertyValue("dataSourcePool"); if (dataSourcePoolVal == null) { if (logger.isWarnEnabled()) { logger.warn("Zebra dataSource's dataSourcePool property not found, maybe its name is modified, " + "change the automonitor's implementation, otherwise some inner dataSource cannot be monitored."); }//from ww w . j a v a 2 s .c o m return; } Map<TypedStringValue, Object> innerDSDefinitionMap = (Map<TypedStringValue, Object>) dataSourcePoolVal .getValue(); for (Entry<TypedStringValue, Object> innerDSDefEntry : innerDSDefinitionMap.entrySet()) { Object innerDSDefVal = innerDSDefEntry.getValue(); if (innerDSDefVal instanceof BeanDefinitionHolder) { BeanDefinitionHolder innerDSDefHolder = (BeanDefinitionHolder) innerDSDefVal; BeanDefinition innerDSDefinition = innerDSDefHolder.getBeanDefinition(); innerDSDefEntry.setValue( new BeanDefinitionHolder(createMonitorableBeanDefinition(beanName, innerDSDefinition), innerDSDefHolder.getBeanName(), innerDSDefHolder.getAliases())); } } }
From source file:com.dianping.zebra.monitor.spring.DataSourceAutoMonitor.java
@SuppressWarnings("unchecked") private boolean checkInnerDataSourceInZebra(String beanName, BeanDefinition zebraDataSourceDefinition) { MutablePropertyValues propertyValues = zebraDataSourceDefinition.getPropertyValues(); PropertyValue dataSourcePoolVal = propertyValues.getPropertyValue("dataSourcePool"); if (dataSourcePoolVal == null) { if (logger.isWarnEnabled()) { logger.warn("Zebra dataSource's dataSourcePool property not found, maybe its name is modified, " + "change the automonitor's implementation, otherwise some inner dataSource cannot be monitored."); }//w w w . j a v a 2 s. c o m return true; } Map<TypedStringValue, Object> innerDSDefinitionMap = (Map<TypedStringValue, Object>) dataSourcePoolVal .getValue(); for (Entry<TypedStringValue, Object> innerDSDefEntry : innerDSDefinitionMap.entrySet()) { Object innerDSDefVal = innerDSDefEntry.getValue(); if (innerDSDefVal instanceof BeanDefinitionHolder) { BeanDefinitionHolder innerDSDefHolder = (BeanDefinitionHolder) innerDSDefVal; BeanDefinition innerDSDefinition = innerDSDefHolder.getBeanDefinition(); if (GroupDataSource.class.getName().equals(innerDSDefinition.getBeanClassName())) { return false; } } } 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 w w w.j ava2s .com*/ } 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:com.alvexcore.repo.workflow.activiti.AssignTaskListener.java
@SuppressWarnings("unchecked") @Override/*www.ja v a 2 s . c om*/ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { BeanDefinition activitiConfiguration = beanFactory.getBeanDefinition(ACTIVITI_PROCESS_ENGINE_CONFIGURATION); MutablePropertyValues propertyValues = activitiConfiguration.getPropertyValues(); PropertyValue postParseHandlers = propertyValues.getPropertyValue(POST_PARSE_HANDLERS); ManagedList<RuntimeBeanReference> refsList = (ManagedList<RuntimeBeanReference>) postParseHandlers .getValue(); refsList.add(new RuntimeBeanReference(HANDLER_BEAN_NAME)); }