KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import org.springframework.beans.factory.config.BeanDefinition;
22 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
23 import org.springframework.beans.factory.xml.BeanDefinitionParser;
24 import org.springframework.beans.factory.xml.ParserContext;
25 import org.springframework.util.ClassUtils;
26
27 /**
28  * {@link BeanDefinitionParser} responsible for parsing the <code>&lt;aop:spring-configured/&gt;</code> tag.
29  *
30  * @author Rob Harrop
31  * @author Adrian Colyer
32  * @since 2.0
33  */

34 class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser {
35
36     private static final String JavaDoc BEAN_CONFIGURER_CLASS_NAME =
37             "org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect";
38
39
40     private boolean registered;
41
42
43     public BeanDefinition parse(Element JavaDoc element, ParserContext parserContext) {
44         if (!this.registered) {
45             BeanDefinitionBuilder builder =
46                     BeanDefinitionBuilder.rootBeanDefinition(getBeanConfigurerClass(), "aspectOf");
47             builder.setSource(parserContext.extractSource(element));
48             parserContext.getReaderContext().registerWithGeneratedName(builder.getBeanDefinition());
49             this.registered = true;
50         }
51         return null;
52     }
53
54     /**
55      * Load the <code>Class</code> instance for the bean configurer.
56      * @throws IllegalStateException if the bean configurer <code>Class</code> cannot be found
57      */

58     private static Class JavaDoc getBeanConfigurerClass() throws IllegalStateException JavaDoc {
59         try {
60             return ClassUtils.forName(BEAN_CONFIGURER_CLASS_NAME);
61         }
62         catch (Throwable JavaDoc ex) {
63             throw new IllegalStateException JavaDoc(
64                     "Unable to load aspect class [" + BEAN_CONFIGURER_CLASS_NAME +
65                     "]: cannot use @Configurable. Root cause: " + ex);
66         }
67     }
68
69 }
70
Popular Tags