List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference
public RuntimeBeanReference(Class<?> beanType)
From source file:org.impalaframework.spring.dynamic.DynamicBeansProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames().clone(); for (String beanName : beanDefinitionNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (logger.isInfoEnabled()) logger.info(beanName + ": " + beanDefinition.getScope()); if (beanDefinition.getScope().equals("dynamic") && beanFactory instanceof BeanDefinitionRegistry) { final BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) beanFactory; final String implBeanName = beanName + "Impl"; final String targetSourceBeanName = beanName + "TargetSource"; bdr.registerBeanDefinition(implBeanName, beanDefinition); /*/*from w ww . j a v a 2s . c o m*/ * <bean id="testInterface" * class="org.springframework.aop.framework.ProxyFactoryBean"> * <property name="targetSource"> <bean * class="org.impalaframework.spring.externalconfig.RefreshableTargetSourceFactoryBean"> * <property name="beanName" methodName = "testInterfaceImpl"/> * </bean> </property> </bean> */ RootBeanDefinition targetSource = new RootBeanDefinition(PrototypeTargetSource.class); targetSource.getPropertyValues().addPropertyValue("targetBeanName", implBeanName); bdr.registerBeanDefinition(targetSourceBeanName, targetSource); RootBeanDefinition proxy = new RootBeanDefinition(ProxyFactoryBean.class); proxy.getPropertyValues().addPropertyValue("targetSource", new RuntimeBeanReference(targetSourceBeanName)); bdr.registerBeanDefinition(beanName, proxy); } } }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Adds the property value to the bean definition based on the name and value of the attribute. * * @param name - The name of the attribute. * @param value - The value of the attribute. * @param entries - The property entries for the over all tag. * @param bean - The bean definition being created. *//* w ww .j a va 2 s . c om*/ protected void processSingleValue(String name, String value, Map<String, BeanTagAttributeInfo> entries, BeanDefinitionBuilder bean) { if (name.toLowerCase().compareTo("parent") == 0) { // If attribute is defining the parent set it in the bean builder. bean.setParentName(value); } else if (name.toLowerCase().compareTo("abstract") == 0) { // If the attribute is defining the parent as abstract set it in the bean builder. bean.setAbstract(Boolean.valueOf(value)); } else if (name.toLowerCase().compareTo("id") == 0) { //nothing - insures that its erased } else { // If the attribute is not a reserved case find the property name form the connected map and add the new // property value. if (name.contains("-ref")) { bean.addPropertyValue(name.substring(0, name.length() - 4), new RuntimeBeanReference(value)); } else { BeanTagAttributeInfo info = entries.get(name); String propertyName; if (info == null) { propertyName = name; } else { propertyName = info.getName(); } bean.addPropertyValue(propertyName, value); } } }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses a bean of the spring namespace. * * @param tag - The Element to be parsed. * @return The parsed bean./* ww w .j a va 2 s . c om*/ */ protected Object parseSpringBean(Element tag, ParserContext parserContext) { if (tag.getLocalName().compareTo("ref") == 0) { // Create the referenced bean by creating a new bean and setting its parent to the referenced bean // then replace grand child with it Element temp = tag.getOwnerDocument().createElement("bean"); temp.setAttribute("parent", tag.getAttribute("bean")); tag = temp; return new RuntimeBeanReference(tag.getAttribute("parent")); } //peel off p: properties an make them actual property nodes - p-namespace does not work properly (unknown cause) Document document = tag.getOwnerDocument(); NamedNodeMap attributes = tag.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); String name = attribute.getNodeName(); if (name.startsWith("p:")) { Element property = document.createElement("property"); property.setAttribute("name", StringUtils.removeStart(name, "p:")); property.setAttribute("value", attribute.getTextContent()); if (tag.getFirstChild() != null) { tag.insertBefore(property, tag.getFirstChild()); } else { tag.appendChild(property); } } } // Create the bean definition for the grandchild and return it. BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); BeanDefinitionHolder bean = delegate.parseBeanDefinitionElement(tag); // Creates a custom name for the new bean. String name = bean.getBeanDefinition().getParentName() + "$Customchild" + beanNumber; if (tag.getAttribute("id") != null && !StringUtils.isEmpty(tag.getAttribute("id"))) { name = tag.getAttribute("id"); } else { beanNumber++; } return new BeanDefinitionHolder(bean.getBeanDefinition(), name); }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parseAndRegisterUnits(Element profileElement, File origin, BeanDefinitionRegistry registry, ParserContext parserContext) {/*from w ww .ja v a 2 s . c om*/ List<Element> unitElements = DomUtils.getChildElementsByTagName(profileElement, ELEMENT_UNIT); for (Element unitElement : unitElements) { // first retrieve all XML attributes of the Unit element String unitId = extractMandatoryIdAttributeFromElement(unitElement, "Unit", registry); // TODO: currently not used as there is nowhere to set this on a ConfigurationUnit @SuppressWarnings("unused") String unitType = unitElement.getAttribute(ATTRIBUTE_UNIT_TYPE); boolean unitIsAbstract = Boolean.valueOf(unitElement.getAttribute(ATTRIBUTE_UNIT_ABSTRACT)); String unitExtends = parseString(unitElement, ATTRIBUTE_UNIT_EXTENDS, null, registry); ManagedList<AbstractBeanDefinition> requiredCapabilityReferences = parseRequiredCapabilities( unitElement, unitId, registry); ManagedList<AbstractBeanDefinition> providedCapabilityReferences = parseProvidedCapabilities( unitElement, unitId, registry); ManagedList<Attribute> attributes = parseAttributesElement(unitElement, parserContext); ManagedList<AbstractBeanDefinition> mappings = parseMappingsElement(unitElement, unitId, registry); ManagedList<AbstractBeanDefinition> commands = parseCommands(unitElement, unitId, registry); ManagedList<AbstractBeanDefinition> asserts = parseAsserts(unitElement, registry); BeanDefinitionBuilder unitBeanDefBuilder = null; if (StringUtils.isNotBlank(unitExtends)) { unitBeanDefBuilder = BeanDefinitionBuilder.childBeanDefinition(unitExtends); unitBeanDefBuilder.getRawBeanDefinition().setBeanClass(ConfigurationUnit.class); requiredCapabilityReferences.setMergeEnabled(true); providedCapabilityReferences.setMergeEnabled(true); attributes.setMergeEnabled(true); mappings.setMergeEnabled(true); commands.setMergeEnabled(true); asserts.setMergeEnabled(true); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_PARENT_ID, unitExtends); } else { unitBeanDefBuilder = BeanDefinitionBuilder.rootBeanDefinition(ConfigurationUnit.class); } String description = extractDescription(unitElement, registry); unitBeanDefBuilder.setAbstract(false); unitBeanDefBuilder.addPropertyValue(PROPERTY_ORIGIN, origin); unitBeanDefBuilder.addPropertyValue(PROPERTY_DESCRIPTION, description); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_ABSTRACT, unitIsAbstract); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_PROVIDED_CAPABILITIES, providedCapabilityReferences); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_REQUIRED_CAPABILITIES, requiredCapabilityReferences); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_ATTRIBUTES, attributes); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_MAPPINGS, mappings); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_COMMANDS, commands); unitBeanDefBuilder.addPropertyValue(PROPERTY_UNIT_ASSERTS, asserts); unitBeanDefBuilder.addConstructorArgValue(unitId); RuntimeBeanReference unitBeanRef = new RuntimeBeanReference(unitId); unitBeanRef.setSource(parserContext.getReaderContext().extractSource(unitElement)); registry.registerBeanDefinition(unitId, unitBeanDefBuilder.getBeanDefinition()); } }
From source file:org.metaeffekt.dcc.commons.spring.xml.DCCConfigurationBeanDefinitionParser.java
private void parseAndRegisterBindings(Element profileElement, File origin, BeanDefinitionRegistry registry, ParserContext parserContext) {//from w ww . j ava 2 s . c om List<Element> bindingElements = DomUtils.getChildElementsByTagName(profileElement, ELEMENT_BINDING); for (Element bindingElement : bindingElements) { Element sourceElement = DomUtils.getChildElementByTagName(bindingElement, ELEMENT_BINDING_SOURCE); Element targetElement = DomUtils.getChildElementByTagName(bindingElement, ELEMENT_BINDING_TARGET); String sourceUnitRef = parseString(sourceElement, "unitRef", null, registry); String sourceCapabilityId = parseString(sourceElement, "capabilityId", null, registry); String targetUnitRef = parseString(targetElement, "unitRef", null, registry); String targetCapabilityId = parseString(targetElement, "capabilityId", null, registry); // convention: if target capabilityId is omitted then use the source capability id if (StringUtils.isEmpty(targetCapabilityId)) { targetCapabilityId = sourceCapabilityId; } String description = extractDescription(bindingElement, registry); BeanDefinitionBuilder bindingBeanBuilder = BeanDefinitionBuilder .genericBeanDefinition(BindingFactoryBean.class); bindingBeanBuilder.addPropertyValue(PROPERTY_ORIGIN, origin); bindingBeanBuilder.addPropertyValue(PROPERTY_DESCRIPTION, description); bindingBeanBuilder.addPropertyValue("sourceCapabilityId", Id.createCapabilityId(sourceCapabilityId)); bindingBeanBuilder.addPropertyReference("sourceUnit", sourceUnitRef); bindingBeanBuilder.addPropertyValue("targetCapabilityId", Id.createCapabilityId(targetCapabilityId)); bindingBeanBuilder.addPropertyReference("targetUnit", targetUnitRef); String bindingBeanName = parserContext.getReaderContext() .generateBeanName(bindingBeanBuilder.getBeanDefinition()); registry.registerBeanDefinition(bindingBeanName, bindingBeanBuilder.getBeanDefinition()); RuntimeBeanReference beanRef = new RuntimeBeanReference(bindingBeanName); beanRef.setSource(parserContext.extractSource(bindingElement)); } }
From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
public void insertSingletonBeanInTarget(String propertyName, String singletonName) { String newName = bestGuessName(targetConfig, propertyName, target.getBeanClassName()); MutablePropertyValues targetProperties = target.getPropertyValues(); PropertyValue pv = targetProperties.getPropertyValue(newName); Object oldValue = null == pv ? null : pv.getValue(); if (!targetConfig.isIgnored(propertyName)) { if (targetConfig.isCollection(propertyName)) { if (null == oldValue) { oldValue = new ManagedList(); pv = new PropertyValue(newName, oldValue); targetProperties.addPropertyValue(pv); }//from w w w . j a v a 2 s .c o m List list = retrieveList(oldValue); list.add(new RuntimeBeanReference(singletonName)); } else { // not a collection targetProperties.addPropertyValue(newName, new RuntimeBeanReference(singletonName)); } } // getTarget().getPropertyValues().addPropertyValue(newName, new RuntimeBeanReference(singletonName)); }
From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
protected void addPropertyWithReference(MutablePropertyValues properties, SingleProperty config, String name, Object value) {//from w ww . ja va 2 s . c o m if (!config.isIgnored()) { if (config.isReference()) { if (value instanceof String) { if (((String) value).trim().indexOf(" ") > -1) { config.setCollection(); } for (StringTokenizer refs = new StringTokenizer((String) value); refs.hasMoreTokens();) { String ref = refs.nextToken(); if (logger.isDebugEnabled()) { logger.debug("possible non-dependent reference: " + name + "/" + ref); } addPropertyWithoutReference(properties, config, name, new RuntimeBeanReference(ref)); } } else { throw new IllegalArgumentException("Bean reference must be a String: " + name + "/" + value); } } else { addPropertyWithoutReference(properties, config, name, value); } } }
From source file:org.mule.config.spring.parsers.specific.RetryPolicyDefinitionParser.java
/** * The BDP magic inside this method will transform this simple config: * * <test:connector name="testConnector8"> * <ee:reconnect blocking="false" count="5" frequency="1000"/> * </test:connector>//from w w w. j a v a2s .c o m * * into this equivalent config, because of the attribute asynchronous="true": * * <test:connector name="testConnector8"> * <spring:property name="retryPolicyTemplate"> * <spring:bean class="org.mule.retry.async.AsynchronousRetryTemplate"> * <spring:constructor-arg> * <spring:bean name="delegate" class="org.mule.retry.policies.SimpleRetryPolicyTemplate"> * <spring:property name="count" value="5"/> * <spring:property name="frequency" value="1000"/> * </spring:bean> * </spring:constructor-arg> * </spring:bean> * </spring:property> * </test:connector> */ @Override protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.parseChild(element, parserContext, builder); if (asynchronous) { // Create the AsynchronousRetryTemplate as a wrapper bean BeanDefinitionBuilder bdb = BeanDefinitionBuilder .genericBeanDefinition(AsynchronousRetryTemplate.class); // Generate a bean name String asynchWrapperName = parserContext.getReaderContext().generateBeanName(bdb.getBeanDefinition()); // Pass in the retry policy as a constructor argument String retryPolicyName = getBeanName(element); bdb.addConstructorArgReference(retryPolicyName); // Register the new bean BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), asynchWrapperName); registerBeanDefinition(holder, parserContext.getRegistry()); // Set the AsynchronousRetryTemplate wrapper bean on the retry policy's parent instead of the retry policy itself BeanDefinition parent = parserContext.getRegistry().getBeanDefinition(getParentBeanName(element)); parent.getPropertyValues().addPropertyValue(getPropertyName(element), new RuntimeBeanReference(asynchWrapperName)); } }
From source file:org.mule.config.spring.util.ProcessingStrategyUtils.java
public static void configureProcessingStrategy(Element element, BeanDefinitionBuilder builder, String defaultStrategy) { String processingStrategyName = element.getAttribute(PROCESSING_STRATEGY_ATTRIBUTE_NAME); ProcessingStrategy processingStrategy = parseProcessingStrategy(processingStrategyName); if (processingStrategy != null) { builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME, processingStrategy); } else if (!StringUtils.isBlank(processingStrategyName)) { builder.addPropertyValue(PROCESSING_STRATEGY_ATTRIBUTE_NAME, new RuntimeBeanReference(processingStrategyName)); }//from w w w. ja v a 2s. c o m }
From source file:org.mule.security.oauth.config.AbstractDevkitBasedDefinitionParser.java
protected void setRef(BeanDefinitionBuilder builder, String propertyName, String ref) { if (!isMuleExpression(ref)) { builder.addPropertyValue(propertyName, new RuntimeBeanReference(ref)); } else {//from ww w .j av a 2 s.c om builder.addPropertyValue(propertyName, ref); } }