Source Code Cross Referenced for AnnotationConfigUtils.java in  » J2EE » spring-framework-2.5 » org » springframework » context » annotation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.context.annotation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.context.annotation;
018:
019:        import java.util.LinkedHashSet;
020:        import java.util.Set;
021:
022:        import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
023:        import org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor;
024:        import org.springframework.beans.factory.config.BeanDefinition;
025:        import org.springframework.beans.factory.config.BeanDefinitionHolder;
026:        import org.springframework.beans.factory.support.BeanDefinitionRegistry;
027:        import org.springframework.beans.factory.support.RootBeanDefinition;
028:        import org.springframework.util.ClassUtils;
029:
030:        /**
031:         * Utility class that allows for convenient registration of common
032:         * {@link org.springframework.beans.factory.config.BeanPostProcessor}
033:         * definitions for annotation-based configuration.
034:         *
035:         * @author Mark Fisher
036:         * @author Juergen Hoeller
037:         * @since 2.5
038:         * @see org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
039:         * @see org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor
040:         * @see CommonAnnotationBeanPostProcessor
041:         * @see org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor
042:         */
043:        public class AnnotationConfigUtils {
044:
045:            /**
046:             * The bean name of the internally managed Required annotation processor.
047:             */
048:            public static final String REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME = "org.springframework.context.annotation.internalRequiredAnnotationProcessor";
049:
050:            /**
051:             * The bean name of the internally managed Autowired annotation processor.
052:             */
053:            public static final String AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME = "org.springframework.context.annotation.internalAutowiredAnnotationProcessor";
054:
055:            /**
056:             * The bean name of the internally managed JSR-250 annotation processor.
057:             */
058:            public static final String COMMON_ANNOTATION_PROCESSOR_BEAN_NAME = "org.springframework.context.annotation.internalCommonAnnotationProcessor";
059:
060:            /**
061:             * The bean name of the internally managed JPA annotation processor.
062:             */
063:            public static final String PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME = "org.springframework.context.annotation.internalPersistenceAnnotationProcessor";
064:
065:            private static final String PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME = "org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor";
066:
067:            private static final boolean jsr250Present = ClassUtils.isPresent(
068:                    "javax.annotation.Resource", AnnotationConfigUtils.class
069:                            .getClassLoader());
070:
071:            private static final boolean jpaPresent = ClassUtils.isPresent(
072:                    "javax.persistence.EntityManagerFactory",
073:                    AnnotationConfigUtils.class.getClassLoader())
074:                    && ClassUtils.isPresent(
075:                            PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME,
076:                            AnnotationConfigUtils.class.getClassLoader());
077:
078:            /**
079:             * Register all relevant annotation post processors in the given registry.
080:             * @param registry the registry to operate on
081:             */
082:            public static void registerAnnotationConfigProcessors(
083:                    BeanDefinitionRegistry registry) {
084:                registerAnnotationConfigProcessors(registry, null);
085:            }
086:
087:            /**
088:             * Register all relevant annotation post processors in the given registry.
089:             * @param registry the registry to operate on
090:             * @param source the configuration source element (already extracted)
091:             * that this registration was triggered from. May be <code>null</code>.
092:             * @return a Set of BeanDefinitionHolders, containing all bean definitions
093:             * that have actually been registered by this call
094:             */
095:            public static Set<BeanDefinitionHolder> registerAnnotationConfigProcessors(
096:                    BeanDefinitionRegistry registry, Object source) {
097:
098:                Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<BeanDefinitionHolder>(
099:                        4);
100:
101:                if (!registry
102:                        .containsBeanDefinition(REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
103:                    RootBeanDefinition def = new RootBeanDefinition(
104:                            RequiredAnnotationBeanPostProcessor.class);
105:                    def.setSource(source);
106:                    beanDefinitions.add(registerBeanPostProcessor(registry,
107:                            def, REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
108:                }
109:
110:                if (!registry
111:                        .containsBeanDefinition(AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
112:                    RootBeanDefinition def = new RootBeanDefinition(
113:                            AutowiredAnnotationBeanPostProcessor.class);
114:                    def.setSource(source);
115:                    beanDefinitions.add(registerBeanPostProcessor(registry,
116:                            def, AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
117:                }
118:
119:                // Check for JSR-250 support, and if present add the CommonAnnotationBeanPostProcessor.
120:                if (jsr250Present
121:                        && !registry
122:                                .containsBeanDefinition(COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)) {
123:                    RootBeanDefinition def = new RootBeanDefinition(
124:                            CommonAnnotationBeanPostProcessor.class);
125:                    def.setSource(source);
126:                    beanDefinitions.add(registerBeanPostProcessor(registry,
127:                            def, COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
128:                }
129:
130:                // Check for JPA support, and if present add the PersistenceAnnotationBeanPostProcessor.
131:                if (jpaPresent
132:                        && !registry
133:                                .containsBeanDefinition(PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)) {
134:                    RootBeanDefinition def = new RootBeanDefinition();
135:                    def
136:                            .setBeanClassName(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME);
137:                    def.setSource(source);
138:                    beanDefinitions.add(registerBeanPostProcessor(registry,
139:                            def, PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME));
140:                }
141:
142:                return beanDefinitions;
143:            }
144:
145:            private static BeanDefinitionHolder registerBeanPostProcessor(
146:                    BeanDefinitionRegistry registry,
147:                    RootBeanDefinition definition, String beanName) {
148:
149:                definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
150:                registry.registerBeanDefinition(beanName, definition);
151:                return new BeanDefinitionHolder(definition, beanName);
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.