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.registerAtAspectJAutoProxyCreatorIfNecessary(
44: parserContext, element);
45: extendBeanDefinition(element, parserContext);
46: return null;
47: }
48:
49: private void extendBeanDefinition(Element element,
50: ParserContext parserContext) {
51: BeanDefinition beanDef = parserContext.getRegistry()
52: .getBeanDefinition(
53: AopNamespaceUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
54: if (element.hasChildNodes()) {
55: addIncludePatterns(element, parserContext, beanDef);
56: }
57: }
58:
59: private void addIncludePatterns(Element element,
60: ParserContext parserContext, BeanDefinition beanDef) {
61: ManagedList includePatterns = new ManagedList();
62: NodeList childNodes = element.getChildNodes();
63: for (int i = 0; i < childNodes.getLength(); i++) {
64: Node node = childNodes.item(i);
65: if (node instanceof Element) {
66: Element includeElement = (Element) node;
67: TypedStringValue valueHolder = new TypedStringValue(
68: includeElement.getAttribute("name"));
69: valueHolder.setSource(parserContext
70: .extractSource(includeElement));
71: includePatterns.add(valueHolder);
72: }
73: }
74: if (!includePatterns.isEmpty()) {
75: includePatterns.setSource(parserContext
76: .extractSource(element));
77: beanDef.getPropertyValues().addPropertyValue(
78: "includePatterns", includePatterns);
79: }
80: }
81:
82: }
|