Source Code Cross Referenced for SignatureFactory.java in  » Aspect-oriented » aspectwerkz-2.0 » org » codehaus » aspectwerkz » joinpoint » management » 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 » Aspect oriented » aspectwerkz 2.0 » org.codehaus.aspectwerkz.joinpoint.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************************
002:         * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
003:         * http://aspectwerkz.codehaus.org                                                    *
004:         * ---------------------------------------------------------------------------------- *
005:         * The software in this package is published under the terms of the LGPL license      *
006:         * a copy of which has been included with this distribution in the license.txt file.  *
007:         **************************************************************************************/package org.codehaus.aspectwerkz.joinpoint.management;
008:
009:        import java.lang.reflect.Constructor;
010:        import java.lang.reflect.Field;
011:        import java.lang.reflect.Method;
012:
013:        import org.codehaus.aspectwerkz.joinpoint.EnclosingStaticJoinPoint;
014:        import org.codehaus.aspectwerkz.joinpoint.impl.CatchClauseSignatureImpl;
015:        import org.codehaus.aspectwerkz.joinpoint.impl.ConstructorSignatureImpl;
016:        import org.codehaus.aspectwerkz.joinpoint.impl.EnclosingStaticJoinPointImpl;
017:        import org.codehaus.aspectwerkz.joinpoint.impl.FieldSignatureImpl;
018:        import org.codehaus.aspectwerkz.joinpoint.impl.MethodSignatureImpl;
019:        import org.codehaus.aspectwerkz.joinpoint.impl.StaticInitializerSignatureImpl;
020:        import org.codehaus.aspectwerkz.reflect.ReflectHelper;
021:        import org.codehaus.aspectwerkz.transform.TransformationConstants;
022:        import org.codehaus.aspectwerkz.transform.inlining.AsmHelper;
023:
024:        /**
025:         * Factory class for the signature hierarchy.
026:         * The helper methods here are called by the JIT jp.
027:         *
028:         * TODO may be worth having a cache
029:         *
030:         * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
031:         * @author <a href="mailto:the_mindstorm@evolva.ro">Alex Popescu</a>
032:         */
033:        public final class SignatureFactory {
034:
035:            /**
036:             * Method signature factory
037:             *
038:             * @param declaringClass
039:             * @param joinPointHash
040:             * @return
041:             */
042:            public static final MethodSignatureImpl newMethodSignature(
043:                    final Class declaringClass, final int joinPointHash) {
044:                Method[] methods = declaringClass.getDeclaredMethods();
045:                for (int i = 0; i < methods.length; i++) {
046:                    Method method = methods[i];
047:                    if (ReflectHelper.calculateHash(method) == joinPointHash) {
048:                        return new MethodSignatureImpl(declaringClass, method);
049:                    }
050:                }
051:                // lookup in the hierarchy
052:                MethodSignatureImpl signature = null;
053:                for (int i = 0; i < declaringClass.getInterfaces().length; i++) {
054:                    signature = newMethodSignature(declaringClass
055:                            .getInterfaces()[i], joinPointHash);
056:                    if (signature != null) {
057:                        return signature;
058:                    }
059:                }
060:                if (declaringClass.getSuperclass() != null) {
061:                    signature = newMethodSignature(declaringClass
062:                            .getSuperclass(), joinPointHash);
063:                } else {
064:                    return null;
065:                }
066:                return signature;
067:            }
068:
069:            /**
070:             * Field signature factory
071:             *
072:             * @param declaringClass
073:             * @param joinPointHash
074:             * @return
075:             */
076:            public static final FieldSignatureImpl newFieldSignature(
077:                    final Class declaringClass, final int joinPointHash) {
078:                Field[] fields = declaringClass.getDeclaredFields();
079:                for (int i = 0; i < fields.length; i++) {
080:                    Field field = fields[i];
081:                    if (ReflectHelper.calculateHash(field) == joinPointHash) {
082:                        return new FieldSignatureImpl(declaringClass, field);
083:                    }
084:                }
085:                // lookup in the hierarchy
086:                if (declaringClass.getSuperclass() != null) {
087:                    return newFieldSignature(declaringClass.getSuperclass(),
088:                            joinPointHash);
089:                } else {
090:                    return null;
091:                }
092:            }
093:
094:            /**
095:             * Constructor signature factory
096:             *
097:             * @param declaringClass
098:             * @param joinPointHash
099:             * @return
100:             */
101:            public static final ConstructorSignatureImpl newConstructorSignature(
102:                    final Class declaringClass, final int joinPointHash) {
103:                Constructor constructor = null;
104:                for (int i = 0; i < declaringClass.getDeclaredConstructors().length; i++) {
105:                    Constructor c = declaringClass.getDeclaredConstructors()[i];
106:                    if (ReflectHelper.calculateHash(c) == joinPointHash) {
107:                        return new ConstructorSignatureImpl(declaringClass, c);
108:                    }
109:                }
110:                // lookup in the hierarchy
111:                if (declaringClass.getSuperclass() != null) {
112:                    return newConstructorSignature(declaringClass
113:                            .getSuperclass(), joinPointHash);
114:                } else {
115:                    return null;
116:                }
117:            }
118:
119:            /**
120:             * Handler signature factory
121:             *
122:             * @param exceptionClass
123:             * @return
124:             */
125:            public static final CatchClauseSignatureImpl newCatchClauseSignature(
126:                    final Class exceptionClass) {
127:                return new CatchClauseSignatureImpl(exceptionClass);
128:            }
129:
130:            /**
131:             * Enclosing signature factory, wrapped behind an EnclosingStaticJoinPoint for syntax consistency
132:             *
133:             * @param declaringClass
134:             * @param name
135:             * @param description
136:             * @return
137:             */
138:            public static EnclosingStaticJoinPoint newEnclosingStaticJoinPoint(
139:                    final Class declaringClass, final String name,
140:                    final String description) {
141:                if (TransformationConstants.CLINIT_METHOD_NAME.equals(name)) {
142:                    return new EnclosingStaticJoinPointImpl(
143:                            new StaticInitializerSignatureImpl(declaringClass),
144:                            JoinPointType.STATIC_INITIALIZATION);
145:                } else if (TransformationConstants.INIT_METHOD_NAME
146:                        .equals(name)) {
147:                    return new EnclosingStaticJoinPointImpl(
148:                            newConstructorSignature(declaringClass, AsmHelper
149:                                    .calculateConstructorHash(description)),
150:                            JoinPointType.CONSTRUCTOR_EXECUTION);
151:                } else {
152:                    // regular method
153:                    return new EnclosingStaticJoinPointImpl(newMethodSignature(
154:                            declaringClass, AsmHelper.calculateMethodHash(name,
155:                                    description)),
156:                            JoinPointType.METHOD_EXECUTION);
157:                }
158:            }
159:
160:            /**
161:             * Static initialization factory
162:             * 
163:             * @param declaringClass
164:             * @return
165:             */
166:            public static StaticInitializerSignatureImpl newStaticInitializationSignature(
167:                    final Class declaringClass) {
168:                return new StaticInitializerSignatureImpl(declaringClass);
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.