Source Code Cross Referenced for ConstrainedDetector.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » site » instrument » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.site.instrument 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: ConstrainedDetector.java 3811 2007-06-25 15:06:16Z gbevin $
007:         */
008:        package com.uwyn.rife.site.instrument;
009:
010:        import com.uwyn.rife.asm.*;
011:
012:        import com.uwyn.rife.instrument.exceptions.ClassBytesNotFoundException;
013:        import com.uwyn.rife.instrument.exceptions.VisitInterruptionException;
014:        import com.uwyn.rife.tools.ClassBytesLoader;
015:
016:        /**
017:         * Detects whether class implements the {@code Constrainted} interface or not,
018:         * by analyzing its bytecode.
019:         * 
020:         * @author Geert Bevin (gbevin[remove] at uwyn dot com)
021:         * @version $Revision: 3811 $
022:         * @since 1.6
023:         */
024:        public class ConstrainedDetector {
025:            private final String CONSTRAINED_INTERNAL_NAME = "com/uwyn/rife/site/Constrained";
026:            private final String CONSTRAINED_NAME = "com.uwyn.rife.site.Constrained";
027:            private final String OBJECT_INTERNAL_NAME = "java/lang/Object";
028:
029:            private ClassBytesLoader mBytesLoader = null;
030:
031:            /**
032:             * Creates new instance by providing a loader that is able to retrieve the
033:             * bytes of any parent classes that are extended by the class that is
034:             * being analyzed.
035:             * 
036:             * @param bytesLoader the loader that will be used to retrieve the bytes
037:             * of the additional classes
038:             * @since 1.6
039:             */
040:            public ConstrainedDetector(ClassBytesLoader bytesLoader) {
041:                mBytesLoader = bytesLoader;
042:            }
043:
044:            /**
045:             * Verifies if the Constrained interface is implemented by the class that
046:             * is defined by the bytes that are provided.
047:             * 
048:             * @param internedClassname the class name as the previously interned
049:             * string
050:             * @param bytes the array of bytes that defines the class that needs to be
051:             * analyzed
052:             * @return {@code true} if the analyzed class implements the constrained
053:             * interface; or
054:             * <p>{@code false} otherwise
055:             * @exception ClassBytesNotFoundException when the bytes of a parent class
056:             * can be found
057:             * @since 1.6
058:             */
059:            public boolean isConstrained(String internedClassname, byte[] bytes)
060:                    throws ClassBytesNotFoundException {
061:                if (CONSTRAINED_NAME == internedClassname) {
062:                    return false;
063:                }
064:
065:                ConstrainedDetectionClassVisitor visitor = new ConstrainedDetectionClassVisitor();
066:                ClassReader detection_reader = null;
067:
068:                while (!visitor.isConstrained()) {
069:                    detection_reader = new ClassReader(bytes);
070:                    try {
071:                        detection_reader.accept(visitor, true);
072:                    } catch (VisitInterruptionException e) {
073:                        // do nothing
074:                    }
075:
076:                    if (null == visitor.getSuperNameInternal()
077:                            || OBJECT_INTERNAL_NAME == visitor
078:                                    .getSuperNameInternal()) {
079:                        break;
080:                    }
081:
082:                    // get the parent's class' bytecode
083:                    if (!visitor.isConstrained()) {
084:                        String filename = visitor.getSuperNameInternal()
085:                                + ".class";
086:                        try {
087:                            bytes = mBytesLoader.getClassBytes(filename);
088:                        } catch (ClassNotFoundException e) {
089:                            throw new ClassBytesNotFoundException(filename, e);
090:                        }
091:                    }
092:                }
093:
094:                return visitor.isConstrained();
095:            }
096:
097:            private class ConstrainedDetectionClassVisitor implements 
098:                    ClassVisitor {
099:                private boolean mIsConstrained = false;
100:                private String mSuperNameInternal = null;
101:
102:                private boolean isConstrained() {
103:                    return mIsConstrained;
104:                }
105:
106:                private String getSuperNameInternal() {
107:                    return mSuperNameInternal;
108:                }
109:
110:                public void visit(int version, int access, String name,
111:                        String signature, String super Name, String[] interfaces) {
112:                    for (String interface_name : interfaces) {
113:                        if (CONSTRAINED_INTERNAL_NAME == interface_name
114:                                .intern()) {
115:                            mIsConstrained = true;
116:                            break;
117:                        }
118:                    }
119:
120:                    if (null == super Name) {
121:                        mSuperNameInternal = null;
122:                    } else {
123:                        mSuperNameInternal = super Name.intern();
124:                    }
125:
126:                    throw new VisitInterruptionException();
127:                }
128:
129:                public MethodVisitor visitMethod(int access, String name,
130:                        String desc, String signature, String[] exceptions) {
131:                    return null;
132:                }
133:
134:                public void visitInnerClass(String name, String outerName,
135:                        String innerName, int access) {
136:                }
137:
138:                public void visitOuterClass(String owner, String name,
139:                        String desc) {
140:                }
141:
142:                public FieldVisitor visitField(int access, String name,
143:                        String desc, String signature, Object value) {
144:                    return null;
145:                }
146:
147:                public void visitSource(String source, String debug) {
148:                }
149:
150:                public AnnotationVisitor visitAnnotation(String desc,
151:                        boolean visible) {
152:                    return null;
153:                }
154:
155:                public void visitAttribute(Attribute attr) {
156:                }
157:
158:                public void visitEnd() {
159:                }
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.