/** * Determine whether the name of the supplied node is equal to the supplied name. * <p>The default implementation checks the supplied desired name against both * {@link Node#getNodeName()} and {@link Node#getLocalName()}. * <p>Subclasses may override the default implementation to provide a different * mechanism for comparing node names. * @param node the node to compare * @param desiredName the name to check for */ public boolean nodeNameEquals(Node node, String desiredName) { return desiredName.equals(node.getNodeName()) || desiredName.equals(getLocalName(node)); }
private boolean isScheduledElement(Node node, ParserContext parserContext) { return node.getNodeType() == Node.ELEMENT_NODE && ELEMENT_SCHEDULED.equals(parserContext.getDelegate().getLocalName(node)); }
/** * Return {@code true} if the supplied node describes an advice type. May be one of: * '{@code before}', '{@code after}', '{@code after-returning}', * '{@code after-throwing}' or '{@code around}'. */ private boolean isAdviceNode(Node aNode, ParserContext parserContext) { if (!(aNode instanceof Element)) { return false; } else { String name = parserContext.getDelegate().getLocalName(aNode); return (BEFORE.equals(name) || AFTER.equals(name) || AFTER_RETURNING_ELEMENT.equals(name) || AFTER_THROWING_ELEMENT.equals(name) || AROUND.equals(name)); } }
/** * Determine whether the name of the supplied node is equal to the supplied name. * <p>The default implementation checks the supplied desired name against both * {@link Node#getNodeName()} and {@link Node#getLocalName()}. * <p>Subclasses may override the default implementation to provide a different * mechanism for comparing node names. * @param node the node to compare * @param desiredName the name to check for */ public boolean nodeNameEquals(Node node, String desiredName) { return desiredName.equals(node.getNodeName()) || desiredName.equals(getLocalName(node)); }
/** * 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" attribute and namespace declaration attributes. * @param attribute the XML attribute to check * @param parserContext the {@code ParserContext} * @see #isEligibleAttribute(String) */ protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) { String fullName = attribute.getName(); return (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") && isEligibleAttribute(parserContext.getDelegate().getLocalName(attribute))); }
/** * Locates the {@link BeanDefinitionParser} from the register implementations using * the local name of the supplied {@link Element}. */ @Nullable private BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) { String localName = parserContext.getDelegate().getLocalName(element); BeanDefinitionParser parser = this.parsers.get(localName); if (parser == null) { parserContext.getReaderContext().fatal( "Cannot locate BeanDefinitionParser for element [" + localName + "]", element); } return parser; }
/** * Gets the advice implementation class corresponding to the supplied {@link Element}. */ private Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) { String elementName = parserContext.getDelegate().getLocalName(adviceElement); if (BEFORE.equals(elementName)) { return AspectJMethodBeforeAdvice.class; } else if (AFTER.equals(elementName)) { return AspectJAfterAdvice.class; } else if (AFTER_RETURNING_ELEMENT.equals(elementName)) { return AspectJAfterReturningAdvice.class; } else if (AFTER_THROWING_ELEMENT.equals(elementName)) { return AspectJAfterThrowingAdvice.class; } else if (AROUND.equals(elementName)) { return AspectJAroundAdvice.class; } else { throw new IllegalArgumentException("Unknown advice kind [" + elementName + "]."); } }
private boolean isScheduledElement(Node node, ParserContext parserContext) { return node.getNodeType() == Node.ELEMENT_NODE && ELEMENT_SCHEDULED.equals(parserContext.getDelegate().getLocalName(node)); }
/** * Locates the {@link BeanDefinitionParser} from the register implementations using * the local name of the supplied {@link Node}. Supports both {@link Element Elements} * and {@link Attr Attrs}. */ @Nullable private BeanDefinitionDecorator findDecoratorForNode(Node node, ParserContext parserContext) { BeanDefinitionDecorator decorator = null; String localName = parserContext.getDelegate().getLocalName(node); if (node instanceof Element) { decorator = this.decorators.get(localName); } else if (node instanceof Attr) { decorator = this.attributeDecorators.get(localName); } else { parserContext.getReaderContext().fatal( "Cannot decorate based on Nodes of type [" + node.getClass().getName() + "]", node); } if (decorator == null) { parserContext.getReaderContext().fatal("Cannot locate BeanDefinitionDecorator for " + (node instanceof Element ? "element" : "attribute") + " [" + localName + "]", node); } return decorator; }
/** * 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" attribute and namespace declaration attributes. * @param attribute the XML attribute to check * @param parserContext the {@code ParserContext} * @see #isEligibleAttribute(String) */ protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) { String fullName = attribute.getName(); return (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") && isEligibleAttribute(parserContext.getDelegate().getLocalName(attribute))); }
/** * Locates the {@link BeanDefinitionParser} from the register implementations using * the local name of the supplied {@link Element}. */ @Nullable private BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) { String localName = parserContext.getDelegate().getLocalName(element); BeanDefinitionParser parser = this.parsers.get(localName); if (parser == null) { parserContext.getReaderContext().fatal( "Cannot locate BeanDefinitionParser for element [" + localName + "]", element); } return parser; }
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String propertyName = parserContext.getDelegate().getLocalName(attr); String propertyValue = attr.getValue(); MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues(); if (pvs.contains(propertyName)) { parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " + "both <property> and inline syntax. Only one approach may be used per property.", attr); } if (propertyName.endsWith(REF_SUFFIX)) { propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length()); pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue)); } else { pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue); } } return definition; }
protected void parseTypeFilters(Element element, ClassPathBeanDefinitionScanner scanner, ParserContext parserContext) { // Parse exclude and include filter elements. ClassLoader classLoader = scanner.getResourceLoader().getClassLoader(); NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String localName = parserContext.getDelegate().getLocalName(node); try { if (INCLUDE_FILTER_ELEMENT.equals(localName)) { TypeFilter typeFilter = createTypeFilter((Element) node, classLoader, parserContext); scanner.addIncludeFilter(typeFilter); } else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) { TypeFilter typeFilter = createTypeFilter((Element) node, classLoader, parserContext); scanner.addExcludeFilter(typeFilter); } } catch (ClassNotFoundException ex) { parserContext.getReaderContext().warning( "Ignoring non-present type filter class: " + ex, parserContext.extractSource(element)); } catch (Exception ex) { parserContext.getReaderContext().error( ex.getMessage(), parserContext.extractSource(element), ex.getCause()); } } } }
@Override @Nullable 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); } } parserContext.popAndRegisterContainingComponent(); return null; }
@Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); MutablePropertyValues commonProperties = parseCommonContainerProperties(element, parserContext); MutablePropertyValues specificProperties = parseSpecificContainerProperties(element, parserContext); String factoryId = element.getAttribute(FACTORY_ID_ATTRIBUTE); if (StringUtils.hasText(factoryId)) { RootBeanDefinition beanDefinition = createContainerFactory( factoryId, element, parserContext, commonProperties, specificProperties); if (beanDefinition != null) { beanDefinition.setSource(parserContext.extractSource(element)); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, factoryId)); } } NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { String localName = parserContext.getDelegate().getLocalName(child); if (LISTENER_ELEMENT.equals(localName)) { parseListener(element, (Element) child, parserContext, commonProperties, specificProperties); } } } parserContext.popAndRegisterContainingComponent(); return null; }
if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue());
if (!StringUtils.hasText(id)) { parserContext.getReaderContext().error( "Id is required for element '" + parserContext.getDelegate().getLocalName(element) + "' when used as a top-level tag", element);
this.parseState.push(new AdviceEntry(parserContext.getDelegate().getLocalName(adviceElement)));
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) { if (element.hasChildNodes()) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(parentId, parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt : childElts) { if(BeanDefinitionParserDelegate .QUALIFIER_ELEMENT.equals(elt.getLocalName())) { continue;//parsed elsewhere } String localName = parserContext.getDelegate().getLocalName(elt); localName = Conventions.attributeNameToPropertyName(localName); if (ConfigType.contains(localName)) { parseConfigTypes(elt, localName, redissonDef, parserContext); } else if (AddressType.contains(localName)) { parseAddressTypes(elt, localName, redissonDef, parserContext); } else if (helper.isRedissonNS(elt)) { elt.setAttribute(REDISSON_REF, redissonRef); parserContext.getDelegate().parseCustomElement(elt); } } parserContext.popContainingComponent(); } }
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) { if (element.hasChildNodes()) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(parentId, parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt : childElts) { if(BeanDefinitionParserDelegate .QUALIFIER_ELEMENT.equals(elt.getLocalName())) { continue;//parsed elsewhere } String localName = parserContext.getDelegate().getLocalName(elt); localName = Conventions.attributeNameToPropertyName(localName); if (ConfigType.contains(localName)) { parseConfigTypes(elt, localName, redissonDef, parserContext); } else if (AddressType.contains(localName)) { parseAddressTypes(elt, localName, redissonDef, parserContext); } else if (helper.isRedissonNS(elt)) { elt.setAttribute(REDISSON_REF, redissonRef); parserContext.getDelegate().parseCustomElement(elt); } } parserContext.popContainingComponent(); } }