01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.aop.config;
18:
19: import org.w3c.dom.Element;
20: import org.w3c.dom.Node;
21: import org.w3c.dom.NodeList;
22:
23: import org.springframework.beans.factory.config.BeanDefinition;
24: import org.springframework.beans.factory.config.TypedStringValue;
25: import org.springframework.beans.factory.support.ManagedList;
26: import org.springframework.beans.factory.xml.BeanDefinitionParser;
27: import org.springframework.beans.factory.xml.ParserContext;
28:
29: /**
30: * {@link BeanDefinitionParser} for the <code>aspectj-autoproxy</code> tag,
31: * enabling the automatic application of @AspectJ-style aspects found in
32: * the {@link org.springframework.beans.factory.BeanFactory}.
33: *
34: * @author Rob Harrop
35: * @author Juergen Hoeller
36: * @since 2.0
37: */
38: class AspectJAutoProxyBeanDefinitionParser implements
39: BeanDefinitionParser {
40:
41: public BeanDefinition parse(Element element,
42: ParserContext parserContext) {
43: AopNamespaceUtils
44: .registerAspectJAnnotationAutoProxyCreatorIfNecessary(
45: parserContext, element);
46: extendBeanDefinition(element, parserContext);
47: return null;
48: }
49:
50: private void extendBeanDefinition(Element element,
51: ParserContext parserContext) {
52: BeanDefinition beanDef = parserContext.getRegistry()
53: .getBeanDefinition(
54: AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
55: if (element.hasChildNodes()) {
56: addIncludePatterns(element, parserContext, beanDef);
57: }
58: }
59:
60: private void addIncludePatterns(Element element,
61: ParserContext parserContext, BeanDefinition beanDef) {
62: ManagedList includePatterns = new ManagedList();
63: NodeList childNodes = element.getChildNodes();
64: for (int i = 0; i < childNodes.getLength(); i++) {
65: Node node = childNodes.item(i);
66: if (node instanceof Element) {
67: Element includeElement = (Element) node;
68: TypedStringValue valueHolder = new TypedStringValue(
69: includeElement.getAttribute("name"));
70: valueHolder.setSource(parserContext
71: .extractSource(includeElement));
72: includePatterns.add(valueHolder);
73: }
74: }
75: if (!includePatterns.isEmpty()) {
76: includePatterns.setSource(parserContext
77: .extractSource(element));
78: beanDef.getPropertyValues().addPropertyValue(
79: "includePatterns", includePatterns);
80: }
81: }
82:
83: }
|