List of usage examples for org.springframework.beans.factory.xml ParserContext popAndRegisterContainingComponent
public void popAndRegisterContainingComponent()
From source file:be.hikage.springtemplate.ImportTemplateBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { Map<String, String> patternMap = prepareReplacement(element); MappingBeanDefinitionVisitor visitor = new MappingBeanDefinitionVisitor(patternMap); Map<String, BeanDefinition> beansDefinition = loadTemplateBeans(element, visitor); CompositeComponentDefinition def = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(def); registerBeans(parserContext, beansDefinition); parserContext.popAndRegisterContainingComponent(); return null;//ww w. j a v a 2s.co m }
From source file:com.mtgi.analytics.aop.config.v11.BtConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition component = new CompositeComponentDefinition(element.getNodeName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(component); try {//from w w w .j a va 2 s . c o m NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) parserContext.getDelegate().parseCustomElement((Element) node, null); } //no actual bean generated for bt:config. return null; } finally { parserContext.popAndRegisterContainingComponent(); } }
From source file:eap.config.ConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); configureAutoProxyCreator(parserContext, element); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt : childElts) { String localName = parserContext.getDelegate().getLocalName(elt); if (POINTCUT.equals(localName)) { parsePointcut(elt, parserContext); } else if (ADVISOR.equals(localName)) { parseAdvisor(elt, parserContext); } else if (ASPECT.equals(localName)) { parseAspect(elt, parserContext); }/* w ww. j a v a 2 s .co m*/ } parserContext.popAndRegisterContainingComponent(); return null; }
From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { final CompositeComponentDefinition compositeDef; final BeanDefinitionBuilder bdd; final AbstractBeanDefinition beanDefinition; String id;//from w ww. j a va 2s.c o m compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); bdd = BeanDefinitionBuilder.rootBeanDefinition(RemoteServiceControllerConfig.class); bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (parserContext.isDefaultLazyInit()) { bdd.setLazyInit(true); } bdd.addConstructorArgReference(getSerializationPolicyProviderBeanRef(element, parserContext).getBeanName()); bdd.addPropertyValue("serviceModuleConfigs", parseModules(element, parserContext)); getBaseServiceConfigParser().update(element, parserContext, bdd, RemoteServiceControllerConfig.DEFAULT_RPC_VALIDATOR_SERVICE_NAME); id = element.getAttribute(XmlNames.ID_ATTR); if (!StringUtils.hasText(id)) { id = RemoteServiceControllerConfig.DEFAULT_BEAN_ID; } beanDefinition = bdd.getBeanDefinition(); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id)); parserContext.popAndRegisterContainingComponent(); return beanDefinition; }
From source file:com.ryantenney.metrics.spring.config.RegisterMetricBeanDefinitionParser.java
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { final CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compDefinition); final String metricRegistryBeanName = element.getAttribute("metric-registry"); if (!StringUtils.hasText(metricRegistryBeanName)) { throw new RuntimeException(); // TODO }//from www . j a v a2 s . c o m final RuntimeBeanReference metricRegistryBeanRef = new RuntimeBeanReference(metricRegistryBeanName); final List<Element> metricElements = DomUtils.getChildElementsByTagName(element, new String[] { "bean", "ref" }); for (Element metricElement : metricElements) { // Get the name attribute and remove it (to prevent Spring from looking for a BeanDefinitionDecorator) final String name = metricElement.getAttributeNS(METRICS_NAMESPACE, "name"); if (name != null) { metricElement.removeAttributeNS(METRICS_NAMESPACE, "name"); } final Object metric = parserContext.getDelegate().parsePropertySubElement(metricElement, null); final RootBeanDefinition metricRegistererDef = new RootBeanDefinition(MetricRegisterer.class); metricRegistererDef.setSource(parserContext.extractSource(metricElement)); metricRegistererDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final ConstructorArgumentValues args = metricRegistererDef.getConstructorArgumentValues(); args.addIndexedArgumentValue(0, metricRegistryBeanRef); args.addIndexedArgumentValue(1, name); args.addIndexedArgumentValue(2, metric); final String beanName = parserContext.getReaderContext().registerWithGeneratedName(metricRegistererDef); parserContext.registerComponent(new BeanComponentDefinition(metricRegistererDef, beanName)); } parserContext.popAndRegisterContainingComponent(); return null; }
From source file:org.devefx.httpmapper.spring.config.ListenersBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compDefinition); RuntimeBeanReference pathMatcherRef = null; if (element.hasAttribute("path-matcher")) { pathMatcherRef = new RuntimeBeanReference(element.getAttribute("path-matcher")); }//w ww. j av a 2s . c o m List<Element> listeners = DomUtils.getChildElementsByTagName(element, "bean", "ref", "listener"); for (Element listener : listeners) { RootBeanDefinition mappedListenerDef = new RootBeanDefinition(MappedListener.class); mappedListenerDef.setSource(parserContext.extractSource(listener)); mappedListenerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); ManagedList<String> includePatterns = null; ManagedList<String> excludePatterns = null; Object listenerBean; if ("listener".equals(listener.getLocalName())) { includePatterns = getIncludePatterns(listener, "mapping"); excludePatterns = getIncludePatterns(listener, "exclude-mapping"); Element beanElem = DomUtils.getChildElementsByTagName(listener, "bean", "ref").get(0); listenerBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null); } else { listenerBean = parserContext.getDelegate().parsePropertySubElement(listener, null); } mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns); mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns); mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(2, listenerBean); if (pathMatcherRef != null) { mappedListenerDef.getPropertyValues().add("pathMatcher", pathMatcherRef); } String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedListenerDef); parserContext.registerComponent(new BeanComponentDefinition(mappedListenerDef, beanName)); } parserContext.popAndRegisterContainingComponent(); return null; }
From source file:com.ryantenney.metrics.spring.config.AnnotationDrivenBeanDefinitionParser.java
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { final Object source = parserContext.extractSource(element); final CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);//from w w w .ja v a2s .c om parserContext.pushContainingComponent(compDefinition); String metricsBeanName = element.getAttribute("metric-registry"); if (!StringUtils.hasText(metricsBeanName)) { metricsBeanName = registerComponent(parserContext, build(MetricRegistry.class, source, ROLE_APPLICATION)); } String healthCheckBeanName = element.getAttribute("health-check-registry"); if (!StringUtils.hasText(healthCheckBeanName)) { healthCheckBeanName = registerComponent(parserContext, build(HealthCheckRegistry.class, source, ROLE_APPLICATION)); } final ProxyConfig proxyConfig = new ProxyConfig(); if (StringUtils.hasText(element.getAttribute("expose-proxy"))) { proxyConfig.setExposeProxy(Boolean.valueOf(element.getAttribute("expose-proxy"))); } if (StringUtils.hasText(element.getAttribute("proxy-target-class"))) { proxyConfig.setProxyTargetClass(Boolean.valueOf(element.getAttribute("proxy-target-class"))); } //@formatter:off registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE) .setFactoryMethod("exceptionMetered").addConstructorArgReference(metricsBeanName) .addConstructorArgValue(proxyConfig)); registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE) .setFactoryMethod("metered").addConstructorArgReference(metricsBeanName) .addConstructorArgValue(proxyConfig)); registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE).setFactoryMethod("timed") .addConstructorArgReference(metricsBeanName).addConstructorArgValue(proxyConfig)); registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE) .setFactoryMethod("gauge").addConstructorArgReference(metricsBeanName)); registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE) .setFactoryMethod("injectMetric").addConstructorArgReference(metricsBeanName)); registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE) .setFactoryMethod("healthCheck").addConstructorArgReference(healthCheckBeanName)); //@formatter:on parserContext.popAndRegisterContainingComponent(); return null; }
From source file:eap.config.ConfigBeanDefinitionParser.java
private void parseAspect(Element aspectElement, ParserContext parserContext) { String aspectId = aspectElement.getAttribute(ID); String aspectName = aspectElement.getAttribute(REF); try {// w w w. ja v a2 s. co m this.parseState.push(new AspectEntry(aspectId, aspectName)); List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>(); List<BeanReference> beanReferences = new ArrayList<BeanReference>(); List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS); for (int i = METHOD_INDEX; i < declareParents.size(); i++) { Element declareParentsElement = declareParents.get(i); beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext)); } // We have to parse "advice" and all the advice kinds in one loop, to get the // ordering semantics right. NodeList nodeList = aspectElement.getChildNodes(); boolean adviceFoundAlready = false; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (isAdviceNode(node, parserContext)) { if (!adviceFoundAlready) { adviceFoundAlready = true; if (!StringUtils.hasText(aspectName)) { parserContext.getReaderContext().error( "<aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.", aspectElement, this.parseState.snapshot()); return; } beanReferences.add(new RuntimeBeanReference(aspectName)); } AbstractBeanDefinition advisorDefinition = parseAdvice(aspectName, i, aspectElement, (Element) node, parserContext, beanDefinitions, beanReferences); beanDefinitions.add(advisorDefinition); } } AspectComponentDefinition aspectComponentDefinition = createAspectComponentDefinition(aspectElement, aspectId, beanDefinitions, beanReferences, parserContext); parserContext.pushContainingComponent(aspectComponentDefinition); List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT); for (Element pointcutElement : pointcuts) { parsePointcut(pointcutElement, parserContext); } parserContext.popAndRegisterContainingComponent(); } finally { this.parseState.pop(); } }
From source file:org.jdal.beans.ServiceBeanDefinitionParser.java
/** * {@inheritDoc}// w w w . ja v a2 s .com */ public AbstractBeanDefinition parse(Element element, ParserContext parserContext) { // default dao and service classes String daoClassName = JPA_DAO_CLASS_NAME; String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME; String name = null; boolean declareService = false; if (element.hasAttribute(DAO_CLASS)) daoClassName = element.getAttribute(DAO_CLASS); if (element.hasAttribute(SERVICE_CLASS)) { serviceClassName = element.getAttribute(SERVICE_CLASS); declareService = true; } if (element.hasAttribute(NAME)) name = element.getAttribute(NAME); if (element.hasAttribute(ENTITY)) { String className = element.getAttribute(ENTITY); if (name == null) { name = StringUtils .uncapitalize(StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR)); } parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Dao BeanDefinitionBuilder daoBuilder = BeanDefinitionBuilder.genericBeanDefinition(daoClassName); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA); if (nl.getLength() > 0) { ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER))); } daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders); } daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null)); daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); String daoBeanName; if (declareService) { // use dao suffix daoBeanName = name + DAO_SUFFIX; registerBeanDefinition(parserContext, daoBuilder, daoBeanName); // register service wrapper String serviceBeanName = name + SERVICE_SUFFIX; BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder .genericBeanDefinition(serviceClassName); serviceBuilder.addPropertyReference("dao", daoBeanName); registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName); } else { // use service suffix for dao and declare an alias with dao suffix for compatibility with older api. daoBeanName = name + SERVICE_SUFFIX; String[] aliases = new String[] { name + DAO_SUFFIX }; BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(), daoBeanName, aliases); parserContext.registerBeanComponent(bcd); } parserContext.popAndRegisterContainingComponent(); } return null; }
From source file:org.jdal.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}//from www .j ava2 s . c om */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String tableModelBeanName = name + LIST_TABLE_MODEL_SUFFIX; String tablePanelBeanName = name + TABLE_PANEL_SUFFIX; String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; if (element.hasAttribute(SERVICE_ATTRIBUTE)) dataSource = element.getAttribute(SERVICE_ATTRIBUTE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); // create ListTableModel BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListTableModel.class); bdb.setScope(scope); bdb.addPropertyValue("modelClass", entity); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableModelBeanName, bdb); // create PageableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(PageableTable.class); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyReference(TABLE_MODEL, tableModelBeanName); bdb.addPropertyValue(NAME, pageableTableBeanName); if (element.hasAttribute(TABLE_SERVICE)) bdb.addPropertyReference(Conventions.attributeNameToPropertyName(TABLE_SERVICE), element.getAttribute(TABLE_SERVICE)); if (element.hasAttribute(FILTER)) bdb.addPropertyReference(FILTER, element.getAttribute(FILTER)); if (element.hasAttribute(SHOW_MENU)) bdb.addPropertyValue(Conventions.attributeNameToPropertyName(SHOW_MENU), element.getAttribute(SHOW_MENU)); if (element.hasAttribute(MESSAGE_SOURCE)) bdb.addPropertyReference(MESSAGE_SOURCE, element.getAttribute(MESSAGE_SOURCE)); registerBeanDefinition(element, parserContext, pageableTableBeanName, bdb); // create TablePanel String tablePanelClassName = "org.jdal.swing.table.TablePanel"; if (element.hasAttribute(TABLE_PANEL_CLASS)) tablePanelClassName = element.getAttribute(TABLE_PANEL_CLASS); bdb = BeanDefinitionBuilder.genericBeanDefinition(tablePanelClassName); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); bdb.addPropertyReference(TABLE, pageableTableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyReference(PERSISTENT_SERVICE, dataSource); if (element.hasAttribute(FILTER_VIEW)) bdb.addPropertyReference(Conventions.attributeNameToPropertyName(FILTER_VIEW), element.getAttribute(FILTER_VIEW)); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); registerBeanDefinition(element, parserContext, tablePanelBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }