Source Code Cross Referenced for WeavingTransformer.java in  » J2EE » spring-framework-2.5 » org » springframework » instrument » classloading » 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.instrument.classloading 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 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.instrument.classloading;
018:
019:        import java.lang.instrument.ClassFileTransformer;
020:        import java.lang.instrument.IllegalClassFormatException;
021:        import java.security.ProtectionDomain;
022:        import java.util.ArrayList;
023:        import java.util.List;
024:
025:        /**
026:         * ClassFileTransformer-based weaver, allowing for a list of transformers to be
027:         * applied on a class byte array. Normally used inside class loaders.
028:         *
029:         * <p>Note: This class is deliberately implemented for minimal external dependencies,
030:         * since it is included in weaver jars (to be deployed into application servers).
031:         *
032:         * @author Rod Johnson
033:         * @author Costin Leau
034:         * @author Juergen Hoeller
035:         * @since 2.0
036:         */
037:        public class WeavingTransformer {
038:
039:            private final ClassLoader classLoader;
040:
041:            private final List<ClassFileTransformer> transformers = new ArrayList<ClassFileTransformer>();
042:
043:            /**
044:             * Create a new WeavingTransformer for the current context class loader.
045:             */
046:            public WeavingTransformer() {
047:                this (null);
048:            }
049:
050:            /**
051:             * Create a new WeavingTransformer for the given class loader.
052:             * @param classLoader the ClassLoader to build a transformer for
053:             */
054:            public WeavingTransformer(ClassLoader classLoader) {
055:                this .classLoader = (classLoader != null ? classLoader
056:                        : getDefaultClassLoader());
057:            }
058:
059:            /**
060:             * Add a class file transformer to be applied by this weaver.
061:             * @param transformer the class file transformer to register
062:             */
063:            public void addTransformer(ClassFileTransformer transformer) {
064:                if (transformer == null) {
065:                    throw new IllegalArgumentException(
066:                            "Transformer must not be null");
067:                }
068:                this .transformers.add(transformer);
069:            }
070:
071:            /**
072:             * Apply transformation on a given class byte definition.
073:             * The method will always return a non-null byte array (if no transformation has taken place
074:             * the array content will be identical to the original one).
075:             * 
076:             * @param className the full qualified name of the class in dot format (i.e. some.package.SomeClass)
077:             * @param bytes class byte definition
078:             * @return (possibly transformed) class byte definition
079:             */
080:            public byte[] transformIfNecessary(String className, byte[] bytes) {
081:                String internalName = className.replace(".", "/");
082:                return transformIfNecessary(className, internalName, bytes,
083:                        null);
084:            }
085:
086:            /**
087:             * Apply transformation on a given class byte definition.
088:             * The method will always return a non-null byte array (if no transformation has taken place
089:             * the array content will be identical to the original one).
090:             * 
091:             * @param className the full qualified name of the class in dot format (i.e. some.package.SomeClass)
092:             * @param internalName class name internal name in / format (i.e. some/package/SomeClass)
093:             * @param bytes class byte definition
094:             * @param pd protection domain to be used (can be null)
095:             * 
096:             * @return (possibly transformed) class byte definition
097:             */
098:            public byte[] transformIfNecessary(String className,
099:                    String internalName, byte[] bytes, ProtectionDomain pd) {
100:                byte[] result = bytes;
101:                for (ClassFileTransformer cft : this .transformers) {
102:                    try {
103:                        byte[] transformed = cft.transform(this .classLoader,
104:                                internalName, null, pd, result);
105:                        if (transformed != null) {
106:                            result = transformed;
107:                        }
108:                    } catch (IllegalClassFormatException ex) {
109:                        throw new IllegalStateException(
110:                                "Class file transformation failed", ex);
111:                    }
112:                }
113:                return result;
114:            }
115:
116:            /**
117:             * See ClassUtils. We don't depend on that to avoid pulling in more of Spring.
118:             * @see org.springframework.util.ClassUtils#getDefaultClassLoader()
119:             */
120:            protected ClassLoader getDefaultClassLoader() {
121:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
122:                if (cl == null) {
123:                    // No thread context class loader -> use class loader of this class.
124:                    cl = getClass().getClassLoader();
125:                }
126:                return cl;
127:            }
128:
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.