KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > config > AspectJAutoProxyBeanDefinitionParser


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import org.w3c.dom.Node JavaDoc;
21 import org.w3c.dom.NodeList JavaDoc;
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 import org.springframework.core.Conventions;
29 import org.springframework.util.StringUtils;
30
31 /**
32  * {@link BeanDefinitionParser} for the <code>aspectj-autoproxy</code> tag,
33  * enabling the automatic application of @AspectJ-style aspects found in
34  * the {@link org.springframework.beans.factory.BeanFactory}.
35  *
36  * @author Rob Harrop
37  * @author Juergen Hoeller
38  * @since 2.0
39  */

40 class AspectJAutoProxyBeanDefinitionParser implements BeanDefinitionParser {
41
42     private static final String JavaDoc PROXY_TARGET_ATTRIBUTE = "proxy-target-class";
43
44     private static final String JavaDoc PROXY_TARGET_CLASS = Conventions.attributeNameToPropertyName(PROXY_TARGET_ATTRIBUTE);
45
46
47     public BeanDefinition parse(Element JavaDoc element, ParserContext parserContext) {
48         AopNamespaceUtils.registerAtAspectJAutoProxyCreatorIfNecessary(parserContext, element);
49         extendBeanDefinition(element, parserContext);
50         return null;
51     }
52
53     private void extendBeanDefinition(Element JavaDoc element, ParserContext parserContext) {
54         BeanDefinition beanDef =
55                 parserContext.getRegistry().getBeanDefinition(AopNamespaceUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
56         String JavaDoc proxyTargetClass = element.getAttribute(PROXY_TARGET_ATTRIBUTE);
57         if (StringUtils.hasText(proxyTargetClass)) {
58             beanDef.getPropertyValues().addPropertyValue(PROXY_TARGET_CLASS, proxyTargetClass);
59         }
60         if (element.hasChildNodes()) {
61             addIncludePatterns(element, parserContext, beanDef);
62         }
63     }
64
65     private void addIncludePatterns(Element JavaDoc element, ParserContext parserContext, BeanDefinition beanDef) {
66         ManagedList includePatterns = new ManagedList();
67         includePatterns.setSource(parserContext.extractSource(element));
68         NodeList JavaDoc childNodes = element.getChildNodes();
69         for (int i = 0; i < childNodes.getLength(); i++) {
70             Node JavaDoc node = childNodes.item(i);
71             if (node instanceof Element JavaDoc) {
72                 Element JavaDoc includeElement = (Element JavaDoc) node;
73                 TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name"));
74                 valueHolder.setSource(parserContext.extractSource(includeElement));
75                 includePatterns.add(valueHolder);
76             }
77         }
78         beanDef.getPropertyValues().addPropertyValue("includePatterns", includePatterns);
79     }
80
81 }
82
Popular Tags