List of usage examples for org.springframework.beans.factory.config BeanDefinitionHolder BeanDefinitionHolder
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName)
From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java
/** * Create cache pointcut definition//from w w w . j a va2 s. c o m */ private void registerCachePointcutDefinition(Element element, ParserContext parserContext) { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(AnnotationMatchingPointcut.class); definition.getConstructorArgumentValues().addGenericArgumentValue(new ValueHolder(null, "java.lang.Class")); definition.getConstructorArgumentValues().addGenericArgumentValue( new ValueHolder("com.dianping.avatar.cache.annotation.Cache", "java.lang.Class")); cachePointcutId = element.getAttribute(CACHE_POINTCUT_ID_ATTR); if (!StringUtils.hasText(cachePointcutId)) { cachePointcutId = DEFAULT_CACHE_POINTCUT_ID; } BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, this.cachePointcutId); BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); }
From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java
/** * Register {@link DefaultBeanFactoryPointcutAdvisor} definition *//* w w w . j av a2 s . com*/ private void registerAdvisorDefinition(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(parserContext, element); GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(DefaultBeanFactoryPointcutAdvisor.class); definition.getPropertyValues().addPropertyValue(ADVICE_BEAN_NAME, new RuntimeBeanNameReference(cacheInterceptorId)); definition.getPropertyValues().addPropertyValue(POINTCUT, new RuntimeBeanReference(cachePointcutId)); String id = element.getAttribute(ADVISOR_ID_ATTR); if (!StringUtils.hasText(id)) { id = DEFAULT_ADVISOR_ID; } BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "cacheAdvisor"); BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); }
From source file:org.devproof.portal.core.config.factory.DevproofClassPathBeanDefinitionScanner.java
private BeanDefinitionHolder buildGenericRepositoryDefinition(Class<?> clazz) { Class<?> entityClazz = getEntityClazz(clazz); GenericRepository annotation = clazz.getAnnotation(GenericRepository.class); BeanDefinition bd = BeanDefinitionBuilder.childBeanDefinition("baseGenericDao") .addPropertyValue("daoInterface", clazz).addPropertyValue("entityClass", entityClazz) .getBeanDefinition();// w ww . j av a 2s.c o m return new BeanDefinitionHolder(bd, annotation.value()); }
From source file:org.devproof.portal.core.config.factory.DevproofClassPathBeanDefinitionScanner.java
private BeanDefinitionHolder buildGenericDataProviderDefinition(Class<?> clazz) { RegisterGenericDataProvider annotation = clazz.getAnnotation(RegisterGenericDataProvider.class); Class<?> entityClazz = clazz; Class<?> queryClazz = annotation.queryClass(); BeanDefinition bd = BeanDefinitionBuilder.childBeanDefinition("persistenceDataProvider") .setScope(BeanDefinition.SCOPE_PROTOTYPE) .addPropertyValue("sort", new SortParam(annotation.sortProperty(), annotation.sortAscending())) .addPropertyValue("queryClass", queryClazz).addPropertyValue("entityClass", entityClazz) .addPropertyValue("countQuery", annotation.countQuery()) .addPropertyValue("prefetch", Arrays.asList(annotation.prefetch())).getBeanDefinition(); return new BeanDefinitionHolder(bd, annotation.value()); }
From source file:org.directwebremoting.spring.DwrNamespaceHandler.java
/** * Registers a new {@link org.directwebremoting.extend.Creator} in the registry using name <code>javascript</code>. * @param registry The definition of all the Beans * @param javascript The name of the bean in the registry. * @param creatorConfig//from w ww . ja v a2 s . c o m * @param params * @param children The node list to check for nested elements */ @SuppressWarnings("unchecked") protected void registerCreator(BeanDefinitionRegistry registry, String javascript, BeanDefinitionBuilder creatorConfig, Map<String, String> params, NodeList children) { registerSpringConfiguratorIfNecessary(registry); List<String> includes = new ArrayList<String>(); creatorConfig.addPropertyValue("includes", includes); List<String> excludes = new ArrayList<String>(); creatorConfig.addPropertyValue("excludes", excludes); Properties auth = new Properties(); creatorConfig.addPropertyValue("auth", auth); // check to see if there are any nested elements here for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE) { continue; } Element child = (Element) node; if ("dwr:latencyfilter".equals(node.getNodeName())) { BeanDefinitionBuilder beanFilter = BeanDefinitionBuilder .rootBeanDefinition(ExtraLatencyAjaxFilter.class); beanFilter.addPropertyValue("delay", child.getAttribute("delay")); BeanDefinitionHolder holder2 = new BeanDefinitionHolder(beanFilter.getBeanDefinition(), "__latencyFilter_" + javascript); BeanDefinitionReaderUtils.registerBeanDefinition(holder2, registry); ManagedList filterList = new ManagedList(); filterList.add(new RuntimeBeanReference("__latencyFilter_" + javascript)); creatorConfig.addPropertyValue("filters", filterList); } else if ("dwr:include".equals(node.getNodeName())) { includes.add(child.getAttribute("method")); } else if ("dwr:exclude".equals(node.getNodeName())) { excludes.add(child.getAttribute("method")); } else if ("dwr:auth".equals(node.getNodeName())) { auth.setProperty(child.getAttribute("method"), child.getAttribute("role")); } else if ("dwr:convert".equals(node.getNodeName())) { Element element = (Element) node; String type = element.getAttribute("type"); String className = element.getAttribute("class"); ConverterConfig converterConfig = new ConverterConfig(); converterConfig.setType(type); parseConverterSettings(converterConfig, element); lookupConverters(registry).put(className, converterConfig); } else if ("dwr:filter".equals(node.getNodeName())) { Element element = (Element) node; String filterClass = element.getAttribute("class"); List<Element> filterParamElements = DomUtils.getChildElementsByTagName(element, "param"); BeanDefinitionBuilder beanFilter; try { beanFilter = BeanDefinitionBuilder.rootBeanDefinition(ClassUtils.forName(filterClass)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("DWR filter class '" + filterClass + "' was not found. " + "Check the class name specified in <dwr:filter class=\"" + filterClass + "\" /> exists"); } for (Element filterParamElement : filterParamElements) { beanFilter.addPropertyValue(filterParamElement.getAttribute("name"), filterParamElement.getAttribute("value")); } BeanDefinitionHolder holder2 = new BeanDefinitionHolder(beanFilter.getBeanDefinition(), "__filter_" + filterClass + "_" + javascript); BeanDefinitionReaderUtils.registerBeanDefinition(holder2, registry); ManagedList filterList = new ManagedList(); filterList.add(new RuntimeBeanReference("__filter_" + filterClass + "_" + javascript)); creatorConfig.addPropertyValue("filters", filterList); } else if ("dwr:param".equals(node.getNodeName())) { Element element = (Element) node; String name = element.getAttribute("name"); String value = element.getAttribute("value"); params.put(name, value); } else { throw new RuntimeException("an unknown dwr:remote sub node was fouund: " + node.getNodeName()); } } creatorConfig.addPropertyValue("params", params); String creatorConfigName = "__" + javascript; BeanDefinitionHolder holder3 = new BeanDefinitionHolder(creatorConfig.getBeanDefinition(), creatorConfigName); BeanDefinitionReaderUtils.registerBeanDefinition(holder3, registry); lookupCreators(registry).put(javascript, new RuntimeBeanReference(creatorConfigName)); }
From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java
/** * Parses the supplied <code><bean></code> element. May return <code>null</code> if there were errors during * parse. Errors are reported to the {@link org.springframework.beans.factory.parsing.ProblemReporter}. */// w ww . j a v a2s.c om private BeanDefinitionHolder parseComponentDefinitionElement(Element ele, BeanDefinition containingBean) { // extract bean name String id = ele.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE); String nameAttr = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE); List<String> aliases = new ArrayList<String>(4); if (StringUtils.hasLength(nameAttr)) { String[] nameArr = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS); aliases.addAll(Arrays.asList(nameArr)); } String beanName = id; if (!StringUtils.hasText(beanName) && !aliases.isEmpty()) { beanName = (String) aliases.remove(0); if (log.isDebugEnabled()) { log.debug("No XML 'id' specified - using '" + beanName + "' as bean name and " + aliases + " as aliases"); } } if (containingBean == null) { if (checkNameUniqueness(beanName, aliases, usedNames)) { error("Bean name '" + beanName + "' is already used in this file", ele); } if (ParsingUtils.isReservedName(beanName, ele, parserContext)) { error("Blueprint reserved name '" + beanName + "' cannot be used", ele); } } AbstractBeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName, containingBean); if (beanDefinition != null) { if (!StringUtils.hasText(beanName)) { try { if (containingBean != null) { beanName = ParsingUtils.generateBlueprintBeanName(beanDefinition, parserContext.getRegistry(), true); } else { beanName = ParsingUtils.generateBlueprintBeanName(beanDefinition, parserContext.getRegistry(), false); // TODO: should we support 2.0 behaviour (see below): // // Register an alias for the plain bean class name, if still possible, // if the generator returned the class name plus a suffix. // This is expected for Spring 1.2/2.0 backwards compatibility. } if (log.isDebugEnabled()) { log.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name [" + beanName + "]"); } } catch (Exception ex) { error(ex.getMessage(), ele, ex); return null; } } return new BeanDefinitionHolder(beanDefinition, beanName); } return null; }
From source file:org.kuali.rice.krad.datadictionary.DictionaryBeanFactoryPostProcessor.java
/** * Invokes processors to handle the root bean definition then processes the bean properties * * @param beanName name of the bean within the factory * @param beanDefinition root bean definition to process *//*www . jav a2s . c om*/ protected void processRootBeanDefinition(String beanName, BeanDefinition beanDefinition) { for (DictionaryBeanProcessor beanProcessor : beanProcessors) { beanProcessor.processRootBeanDefinition(beanName, beanDefinition); } Stack<BeanDefinitionHolder> nestedBeanStack = new Stack<BeanDefinitionHolder>(); nestedBeanStack.push(new BeanDefinitionHolder(beanDefinition, beanName)); processBeanProperties(beanDefinition, nestedBeanStack); }
From source file:org.kuali.rice.krad.datadictionary.DictionaryBeanFactoryPostProcessor.java
/** * Invokes the processors to handle the given nested bean definition * * <p>/* w w w. j a va2 s .c om*/ * A check is also made to determine if the nested bean has a non-generated id which is not registered in the * factory, if so the bean is added as a registered bean (so it can be found by id) * </p> * * @param beanName name of the nested bean definition in the bean factory * @param beanDefinition nested bean definition to process * @param nestedPropertyPath the property path to the nested bean from the parent bean definition * @param isCollectionBean indicates whether the nested bean is in a collection, if so a different handler * method is called on the processors * @param nestedBeanStack the stack of bean containers(those beans which contain the bean) */ public void processNestedBeanDefinition(String beanName, BeanDefinition beanDefinition, String nestedPropertyPath, boolean isCollectionBean, Stack<BeanDefinitionHolder> nestedBeanStack) { // if bean name is given and factory does not have it registered we need to add it (inner beans that // were given an id) if (StringUtils.isNotBlank(beanName) && !StringUtils.contains(beanName, "$") && !StringUtils.contains(beanName, "#") && !beanFactory.containsBean(beanName)) { ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(beanName, beanDefinition); } // invoke the processors to handle the nested bean for (DictionaryBeanProcessor beanProcessor : beanProcessors) { if (isCollectionBean) { beanProcessor.processCollectionBeanDefinition(beanName, beanDefinition, nestedPropertyPath, nestedBeanStack); } else { beanProcessor.processNestedBeanDefinition(beanName, beanDefinition, nestedPropertyPath, nestedBeanStack); } } BeanDefinitionHolder nestedBeanDefinitionHolder = new BeanDefinitionHolder(beanDefinition, beanName); nestedBeanStack.push(nestedBeanDefinitionHolder); processBeanProperties(beanDefinition, nestedBeanStack); nestedBeanStack.pop(); }
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./*www.j a va 2s. c o m*/ */ 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.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses a bean of the custom namespace. * * @param tag - The Element to be parsed. * @param parent - The parent bean that the tag is nested in. * @param parserContext - Provided information and functionality regarding current bean set. * @return The parsed bean./*from ww w .jav a 2 s. c o m*/ */ protected Object parseCustomBean(Element tag, BeanDefinitionBuilder parent, ParserContext parserContext) { BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(tag, parent.getBeanDefinition()); String name = beanDefinition.getParentName() + "$Customchild" + beanNumber; if (tag.getAttribute("id") != null && !StringUtils.isEmpty(tag.getAttribute("id"))) { name = tag.getAttribute("id"); } else { beanNumber++; } return new BeanDefinitionHolder(beanDefinition, name); }