Source Code Cross Referenced for DelegatingIntroductionInterceptor.java in  » J2EE » spring-framework-2.0.6 » org » springframework » aop » support » 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.0.6 » org.springframework.aop.support 
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.aop.support;
018:
019:        import org.aopalliance.intercept.MethodInvocation;
020:
021:        import org.springframework.aop.DynamicIntroductionAdvice;
022:        import org.springframework.aop.IntroductionInterceptor;
023:        import org.springframework.aop.ProxyMethodInvocation;
024:        import org.springframework.util.Assert;
025:
026:        /**
027:         * Convenient implementation of the
028:         * {@link org.springframework.aop.IntroductionInterceptor} interface.
029:         *
030:         * <p>Subclasses merely need to extend this class and implement the interfaces
031:         * to be introduced themselves. In this case the delegate is the subclass
032:         * instance itself. Alternatively a separate delegate may implement the
033:         * interface, and be set via the delegate bean property.
034:         *
035:         * <p>Delegates or subclasses may implement any number of interfaces.
036:         * All interfaces except IntroductionInterceptor are picked up from
037:         * the subclass or delegate by default.
038:         *
039:         * <p>The <code>suppressInterface</code> method can be used to suppress interfaces
040:         * implemented by the delegate but which should not be introduced to the owning
041:         * AOP proxy.
042:         * 
043:         * <p>An instance of this class is serializable if the delegate is.
044:         *
045:         * @author Rod Johnson
046:         * @author Juergen Hoeller
047:         * @since 16.11.2003
048:         * @see #suppressInterface
049:         * @see DelegatePerTargetObjectIntroductionInterceptor
050:         */
051:        public class DelegatingIntroductionInterceptor extends
052:                IntroductionInfoSupport implements  IntroductionInterceptor {
053:
054:            /**
055:             * Object that actually implements the interfaces.
056:             * May be "this" if a subclass implements the introduced interfaces.
057:             */
058:            private Object delegate;
059:
060:            /**
061:             * Construct a new DelegatingIntroductionInterceptor, providing
062:             * a delegate that implements the interfaces to be introduced.
063:             * @param delegate the delegate that implements the introduced interfaces
064:             */
065:            public DelegatingIntroductionInterceptor(Object delegate) {
066:                init(delegate);
067:            }
068:
069:            /**
070:             * Construct a new DelegatingIntroductionInterceptor.
071:             * The delegate will be the subclass, which must implement
072:             * additional interfaces.
073:             */
074:            protected DelegatingIntroductionInterceptor() {
075:                init(this );
076:            }
077:
078:            /**
079:             * Both constructors use this init method, as it is impossible to pass
080:             * a "this" reference from one constructor to another.
081:             * @param delegate the delegate object
082:             */
083:            private void init(Object delegate) {
084:                Assert.notNull(delegate, "Delegate must not be null");
085:                this .delegate = delegate;
086:                implementInterfacesOnObject(delegate);
087:
088:                // We don't want to expose the control interface
089:                suppressInterface(IntroductionInterceptor.class);
090:                suppressInterface(DynamicIntroductionAdvice.class);
091:            }
092:
093:            /**
094:             * Subclasses may need to override this if they want to  perform custom
095:             * behaviour in around advice. However, subclasses should invoke this
096:             * method, which handles introduced interfaces and forwarding to the target.
097:             */
098:            public Object invoke(MethodInvocation mi) throws Throwable {
099:                if (isMethodOnIntroducedInterface(mi)) {
100:                    // Using the following method rather than direct reflection, we
101:                    // get correct handling of InvocationTargetException
102:                    // if the introduced method throws an exception.
103:                    Object retVal = AopUtils.invokeJoinpointUsingReflection(
104:                            this .delegate, mi.getMethod(), mi.getArguments());
105:
106:                    // Massage return value if possible: if the delegate returned itself,
107:                    // we really want to return the proxy.
108:                    if (retVal == this .delegate
109:                            && mi instanceof  ProxyMethodInvocation) {
110:                        Object proxy = ((ProxyMethodInvocation) mi).getProxy();
111:                        if (mi.getMethod().getReturnType().isInstance(proxy)) {
112:                            retVal = proxy;
113:                        }
114:                    }
115:                    return retVal;
116:                }
117:
118:                return doProceed(mi);
119:            }
120:
121:            /**
122:             * Proceed with the supplied {@link org.aopalliance.intercept.MethodInterceptor}.
123:             * Subclasses can override this method to intercept method invocations on the
124:             * target object which is useful when an introduction needs to monitor the object
125:             * that it is introduced into. This method is <strong>never</strong> called for
126:             * {@link MethodInvocation MethodInvocations} on the introduced interfaces.
127:             */
128:            protected Object doProceed(MethodInvocation mi) throws Throwable {
129:                // If we get here, just pass the invocation on.
130:                return mi.proceed();
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.