List of usage examples for org.springframework.beans.factory.xml ParserContext isNested
public final boolean isNested()
From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java
/** * If the given parse operation is nested inside an instance of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition}, return * the template bean configuration associated with that component. Otherwise return null. *///from w w w . ja va 2s. co m public static DefaultListableBeanFactory findEnclosingTemplateFactory(ParserContext context) { if (context.isNested()) { //TODO: support deeper nesting. this logic breaks completely with bt:persister-chain. CompositeComponentDefinition parent = context.getContainingComponent(); if (parent instanceof TemplateComponentDefinition) return ((TemplateComponentDefinition) parent).getTemplateFactory(); } return null; }
From source file:com.apporiented.spring.override.GenericBeanDefinitionParser.java
/** * Determine whether the given attribute is eligible for being * turned into a corresponding bean property value. * <p>The default implementation considers any attribute as eligible, * except for the "id" and "name" attributes in case of a top-level bean. * @param attributeName the attribute name taken straight from the * XML element being parsed (never <code>null</code>) * @param parserContext The parser context. * @return true if eligible.// w w w . jav a2 s . co m */ protected boolean isEligibleAttribute(String attributeName, ParserContext parserContext) { return parserContext.isNested() || (!attributeName.equals(ID_ATTRIBUTE) && !attributeName.equals(aliasAttribute)); }
From source file:com.mtgi.analytics.aop.config.v11.BtMBeanPersisterBeanDefinitionParser.java
@Override protected void transform(ConfigurableListableBeanFactory factory, BeanDefinition template, Element element, ParserContext parserContext) { String id = overrideAttribute("id", template, element); overrideProperty("server", template, element, true); if (parserContext.isNested()) { if (id == null) id = parserContext.getReaderContext().generateBeanName(template); BtManagerBeanDefinitionParser.registerNestedBean(new BeanDefinitionHolder(template, id), "persister", parserContext);//w w w .j av a 2s. c o m } }
From source file:org.jboss.seam.spring.namespace.CdiBeanImportBeanDefinitionParser.java
@Override protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException { String id = element.getAttribute(ID_ATTRIBUTE); if (!StringUtils.hasText(id)) { if (!parserContext.isNested()) { parserContext.getReaderContext().error("A root level CDI bean reference must specify an id", element);/*from w w w . j a v a2s . c om*/ } id = parserContext.getReaderContext().generateBeanName(definition); } return id; }
From source file:com.mtgi.analytics.aop.config.v11.BtHttpRequestsBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //compile required constructor arguments from attributes and nested elements. first up, event type. builder.addConstructorArg(element.getAttribute(ATT_EVENT_TYPE)); //manager ID from enclosing tag, or ref attribute. String managerId = parserContext.isNested() ? (String) parserContext.getContainingBeanDefinition().getAttribute("id") : element.getAttribute(BtNamespaceConstants.ATT_TRACKING_MANAGER); builder.addConstructorArgReference(managerId); //parameter list to include in event data, if any. String paramList = element.getAttribute(ATT_PARAMETERS); builder.addConstructorArg(parseList(paramList)); //parameter list to include in event name, if any String nameList = element.getAttribute(ATT_NAME_PARAMETERS); builder.addConstructorArg(parseList(nameList)); //URI patterns, if any. can be specified as attribute or nested elements. ArrayList<Pattern> accum = new ArrayList<Pattern>(); if (element.hasAttribute(ATT_URI_PATTERN)) accum.add(Pattern.compile(element.getAttribute(ATT_URI_PATTERN))); NodeList nl = element.getElementsByTagNameNS("*", ATT_URI_PATTERN); for (int i = 0; i < nl.getLength(); ++i) { Element e = (Element) nl.item(i); String pattern = e.getTextContent(); if (StringUtils.hasText(pattern)) accum.add(Pattern.compile(pattern)); }/*ww w. ja v a 2s .c o m*/ if (accum.isEmpty()) builder.addConstructorArg(null); else builder.addConstructorArg(accum.toArray(new Pattern[accum.size()])); if (parserContext.isNested()) parserContext.getReaderContext().registerWithGeneratedName(builder.getBeanDefinition()); }
From source file:com.mtgi.analytics.aop.config.v11.BtXmlPersisterBeanDefinitionParser.java
@Override protected void transform(ConfigurableListableBeanFactory factory, BeanDefinition template, Element element, ParserContext parserContext) { String id = overrideAttribute("id", template, element); for (String p : PROPS) overrideProperty(p, template, element, false); //schedule periodic log rotation with Quartz String rotateSchedule = element.getAttribute("rotate-schedule"); if (rotateSchedule != null) configureLogRotation(parserContext, factory, rotateSchedule); if (parserContext.isNested()) { if (id == null) id = parserContext.getReaderContext().generateBeanName(template); BtManagerBeanDefinitionParser.registerNestedBean(new BeanDefinitionHolder(template, id), "persister", parserContext);/*from w ww . j a v a 2s. c om*/ } }
From source file:net.phoenix.thrift.xml.ArgBeanDefinitionParser.java
/** * ?arg//from w ww.java2 s. com */ @Override protected void postParse(Element element, ParserContext parserContext, AbstractBeanDefinition current) { Object argument = parserContext.getDelegate().parsePropertyValue(element, current, "argument"); if (argument == null) throw new BeanCreationException( "Could not found value for arg '" + element.getAttribute("name") + "'."); current.getPropertyValues().add("argument", argument); // register the definition; if (parserContext.isNested()) { this.registerBeanDefinition(element, parserContext, current); } }
From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java
/** * Creates a {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} instance for the * bean class and passes it to the/*from w w w. ja va 2 s. c om*/ * {@link #doParse} strategy method. * @param element the element that is to be parsed into a single BeanDefinition * @param parserContext the object encapsulating the current state of the parsing process * @return the BeanDefinition resulting from the parsing of the supplied {@link org.w3c.dom.Element} * @throws IllegalStateException if the bean {@link Class} returned from * bean class is <code>null</code> * @see #doParse */ protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(beanClass); builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (parserContext.isNested()) { // Inner bean definition must receive same scope as containing bean. builder.setScope(parserContext.getContainingBeanDefinition().getScope()); } if (parserContext.isDefaultLazyInit()) { // Default-lazy-init applies to custom bean definitions as well. builder.setLazyInit(true); } builder.setAutowireMode(autowireMode); builder.setFactoryMethod(factoryMethod); doParse(element, parserContext, builder); return builder.getBeanDefinition(); }
From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java
public final BeanDefinition parse(Element element, ParserContext parserContext) { if (!enabled) { throw new FatalBeanException("Support for " + element.getTagName() + " has been disabled. Please add the required jar files " + "to your classpath."); }/*from ww w . ja v a 2 s .c o m*/ AbstractBeanDefinition definition = parseInternal(element, parserContext); if (!parserContext.isNested()) { try { String id = resolveId(element, definition, parserContext); if (!StringUtils.hasText(id)) { parserContext.getReaderContext().error("Id is required for element '" + element.getLocalName() + "' when used as a top-level tag", element); } String[] aliases = resolveAliases(element, definition, parserContext); BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases); if (decorator != null) { holder = decorator.decorate(element, holder, parserContext); } registerBeanDefinition(holder, parserContext.getRegistry()); if (shouldFireEvents()) { BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder); postProcessComponentDefinition(componentDefinition); parserContext.registerComponent(componentDefinition); } } catch (BeanDefinitionStoreException ex) { parserContext.getReaderContext().error(ex.getMessage(), element); return null; } } else if (decorator != null) { BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, ""); decorator.decorate(element, holder, parserContext); } return definition; }
From source file:net.phoenix.thrift.xml.ComplexBeanDefinitionParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); String parentName = getParentName(element); if (parentName != null) { builder.getRawBeanDefinition().setParentName(parentName); }// w w w .j av a 2 s.co m Class<?> beanClass = getBeanClass(element); if (beanClass != null) { builder.getRawBeanDefinition().setBeanClass(beanClass); } else { String beanClassName = getBeanClassName(element); if (beanClassName != null) { builder.getRawBeanDefinition().setBeanClassName(beanClassName); } } builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (parserContext.isNested()) { // Inner bean definition must receive same scope as containing bean. builder.setScope(parserContext.getContainingBeanDefinition().getScope()); } if (parserContext.isDefaultLazyInit()) { // Default-lazy-init applies to custom bean definitions as well. builder.setLazyInit(true); } preParse(element, parserContext, builder); AbstractBeanDefinition target = builder.getBeanDefinition(); postParse(element, parserContext, target); return target; }