Source Code Cross Referenced for JavassistClassTransformer.java in  » Database-ORM » hibernate » org » hibernate » bytecode » javassist » 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 » Database ORM » hibernate » org.hibernate.bytecode.javassist 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$Id: $
002:        package org.hibernate.bytecode.javassist;
003:
004:        import java.io.ByteArrayInputStream;
005:        import java.io.ByteArrayOutputStream;
006:        import java.io.DataInputStream;
007:        import java.io.DataOutputStream;
008:        import java.io.IOException;
009:        import java.security.ProtectionDomain;
010:
011:        import javassist.bytecode.ClassFile;
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:        import org.hibernate.HibernateException;
015:        import org.hibernate.bytecode.AbstractClassTransformerImpl;
016:        import org.hibernate.bytecode.util.ClassFilter;
017:
018:        /**
019:         * Enhance the classes allowing them to implements InterceptFieldEnabled
020:         * This interface is then used by Hibernate for some optimizations.
021:         *
022:         * @author Emmanuel Bernard
023:         * @author Steve Ebersole
024:         */
025:        public class JavassistClassTransformer extends
026:                AbstractClassTransformerImpl {
027:
028:            private static Log log = LogFactory
029:                    .getLog(JavassistClassTransformer.class.getName());
030:
031:            public JavassistClassTransformer(ClassFilter classFilter,
032:                    org.hibernate.bytecode.util.FieldFilter fieldFilter) {
033:                super (classFilter, fieldFilter);
034:            }
035:
036:            protected byte[] doTransform(ClassLoader loader, String className,
037:                    Class classBeingRedefined,
038:                    ProtectionDomain protectionDomain, byte[] classfileBuffer) {
039:                ClassFile classfile;
040:                try {
041:                    // WARNING: classfile only
042:                    classfile = new ClassFile(new DataInputStream(
043:                            new ByteArrayInputStream(classfileBuffer)));
044:                } catch (IOException e) {
045:                    log.error("Unable to build enhancement metamodel for "
046:                            + className);
047:                    return classfileBuffer;
048:                }
049:                FieldTransformer transformer = getFieldTransformer(classfile);
050:                if (transformer != null) {
051:                    if (log.isDebugEnabled()) {
052:                        log.debug("Enhancing " + className);
053:                    }
054:                    DataOutputStream out = null;
055:                    try {
056:                        transformer.transform(classfile);
057:                        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
058:                        out = new DataOutputStream(byteStream);
059:                        classfile.write(out);
060:                        return byteStream.toByteArray();
061:                    } catch (Exception e) {
062:                        log.error("Unable to transform class", e);
063:                        throw new HibernateException(
064:                                "Unable to transform class: " + e.getMessage());
065:                    } finally {
066:                        try {
067:                            if (out != null)
068:                                out.close();
069:                        } catch (IOException e) {
070:                            //swallow
071:                        }
072:                    }
073:                }
074:                return classfileBuffer;
075:            }
076:
077:            protected FieldTransformer getFieldTransformer(
078:                    final ClassFile classfile) {
079:                if (alreadyInstrumented(classfile)) {
080:                    return null;
081:                }
082:                return new FieldTransformer(new FieldFilter() {
083:                    public boolean handleRead(String desc, String name) {
084:                        return fieldFilter.shouldInstrumentField(classfile
085:                                .getName(), name);
086:                    }
087:
088:                    public boolean handleWrite(String desc, String name) {
089:                        return fieldFilter.shouldInstrumentField(classfile
090:                                .getName(), name);
091:                    }
092:
093:                    public boolean handleReadAccess(String fieldOwnerClassName,
094:                            String fieldName) {
095:                        return fieldFilter.shouldTransformFieldAccess(classfile
096:                                .getName(), fieldOwnerClassName, fieldName);
097:                    }
098:
099:                    public boolean handleWriteAccess(
100:                            String fieldOwnerClassName, String fieldName) {
101:                        return fieldFilter.shouldTransformFieldAccess(classfile
102:                                .getName(), fieldOwnerClassName, fieldName);
103:                    }
104:                });
105:            }
106:
107:            private boolean alreadyInstrumented(ClassFile classfile) {
108:                String[] intfs = classfile.getInterfaces();
109:                for (int i = 0; i < intfs.length; i++) {
110:                    if (FieldHandled.class.getName().equals(intfs[i])) {
111:                        return true;
112:                    }
113:                }
114:                return false;
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.