Source Code Cross Referenced for EJB21Finder.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » deployment » annotations » helper » bean » 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 » ow2 easybeans » org.ow2.easybeans.deployment.annotations.helper.bean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2006 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: EJB21Finder.java 2057 2007-11-21 15:35:32Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.deployment.annotations.helper.bean;
025:
026:        import java.util.ArrayList;
027:        import java.util.List;
028:
029:        import org.ow2.easybeans.asm.Opcodes;
030:        import org.ow2.easybeans.asm.Type;
031:        import org.ow2.easybeans.deployment.annotations.JMethod;
032:        import org.ow2.easybeans.deployment.annotations.impl.JRemove;
033:        import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
034:        import org.ow2.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata;
035:        import org.ow2.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata;
036:
037:        /**
038:         * This class finds the business interface that are used as return type in the
039:         * Home or LocalHome interface of the Bean.
040:         * @author Florent Benoit
041:         */
042:        public final class EJB21Finder {
043:
044:            /**
045:             * Signature of the remove method.
046:             */
047:            private static final JMethod REMOVE_METHOD = new JMethod(
048:                    Opcodes.ACC_PUBLIC, "remove", "()V", null,
049:                    new String[] { "javax/ejb/RemoveException" });
050:
051:            /**
052:             * Signature of the isIdentical(EJBObject) method.
053:             */
054:            private static final JMethod ISIDENTICAL_METHOD = new JMethod(
055:                    Opcodes.ACC_PUBLIC, "isIdentical",
056:                    "(Ljavax/ejb/EJBObject;)Z", null,
057:                    new String[] { "java/rmi/RemoteException" });
058:
059:            /**
060:             * Signature of the isIdentical(EJBLocalObject) method.
061:             */
062:            private static final JMethod ISIDENTICAL_LOCAL_METHOD = new JMethod(
063:                    Opcodes.ACC_PUBLIC, "isIdentical",
064:                    "(Ljavax/ejb/EJBLocalObject;)Z", null,
065:                    new String[] { "javax/ejb/EJBException" });
066:
067:            /**
068:             * Signature of the getHandle method.
069:             */
070:            private static final JMethod GETHANDLE_METHOD = new JMethod(
071:                    Opcodes.ACC_PUBLIC, "getHandle", "()Ljavax/ejb/Handle;",
072:                    null, new String[] { "java/rmi/RemoteException" });
073:
074:            /**
075:             * Signature of the getHandle method.
076:             */
077:            private static final JMethod GETPRIMARYKEY_METHOD = new JMethod(
078:                    Opcodes.ACC_PUBLIC, "getPrimaryKey",
079:                    "()Ljava/lang/Object;", null, null);
080:
081:            /**
082:             * Helper class, no public constructor.
083:             */
084:            private EJB21Finder() {
085:            }
086:
087:            /**
088:             * Finds business method in a session bean.
089:             * @param bean the bean to analyze
090:             */
091:            public static void resolve(final ClassAnnotationMetadata bean) {
092:                // Home and RemoteHome on the bean ?
093:                String remoteHome = bean.getRemoteHome();
094:                String localHome = bean.getLocalHome();
095:
096:                // First, check if there is a home or local home interface (else do
097:                // nothing)
098:                if (remoteHome == null && localHome == null) {
099:                    return;
100:                }
101:
102:                // EJB-JAR
103:                EjbJarAnnotationMetadata ejbJarAnnotationMetadata = bean
104:                        .getEjbJarAnnotationMetadata();
105:                // List of interfaces found in remote home interfaces.
106:                List<String> interfacesList = new ArrayList<String>();
107:
108:                // Get List of Interfaces from remote home
109:                if (remoteHome != null) {
110:                    getInterfacesFromHome(remoteHome, interfacesList,
111:                            ejbJarAnnotationMetadata);
112:                }
113:
114:                // Get List of Interfaces from Local home
115:                if (localHome != null) {
116:                    getInterfacesFromHome(localHome, interfacesList,
117:                            ejbJarAnnotationMetadata);
118:                }
119:
120:                // And then, set business method found in the createXXX() methods in
121:                // home interfaces
122:                for (String itf : interfacesList) {
123:                    // Get metadata of this interface
124:                    ClassAnnotationMetadata interfaceUsed = ejbJarAnnotationMetadata
125:                            .getClassAnnotationMetadata(itf);
126:                    if (interfaceUsed == null) {
127:                        throw new IllegalStateException(
128:                                "Cannot find the metadata for the class '"
129:                                        + itf
130:                                        + "' referenced in the home/localhome of the bean '"
131:                                        + bean.getClassName() + "'.");
132:                    }
133:
134:                    // Get all methods
135:                    for (MethodAnnotationMetadata methodData : interfaceUsed
136:                            .getMethodAnnotationMetadataCollection()) {
137:                        JMethod itfMethod = methodData.getJMethod();
138:
139:                        // Ignore class init method
140:                        if (itfMethod.getName().equals(
141:                                BusinessMethodResolver.CLASS_INIT)
142:                                || itfMethod.getName().equals(
143:                                        BusinessMethodResolver.CONST_INIT)) {
144:                            continue;
145:                        }
146:
147:                        // take the method from the bean class
148:                        MethodAnnotationMetadata beanMethod = bean
149:                                .getMethodAnnotationMetadata(itfMethod);
150:                        if (beanMethod == null) {
151:                            throw new IllegalStateException(
152:                                    "No method was found for method "
153:                                            + itfMethod + " in class "
154:                                            + bean.getClassName());
155:                        }
156:                        beanMethod.setBusinessMethod(true);
157:                    }
158:
159:                }
160:
161:                // Add remove method
162:                MethodAnnotationMetadata metadataRemove = bean
163:                        .getMethodAnnotationMetadata(REMOVE_METHOD);
164:                // not present ? add it
165:                if (metadataRemove == null) {
166:                    metadataRemove = new MethodAnnotationMetadata(
167:                            REMOVE_METHOD, bean);
168:                    bean.addMethodAnnotationMetadata(metadataRemove);
169:                }
170:
171:                // flag method as a remove method
172:                metadataRemove.setRemove(new JRemove());
173:                metadataRemove.setBusinessMethod(true);
174:
175:                // Add isIdentical on EJBObject and EJBLocalObject
176:                bean.addMethodAnnotationMetadata(new MethodAnnotationMetadata(
177:                        ISIDENTICAL_METHOD, bean));
178:                bean.addMethodAnnotationMetadata(new MethodAnnotationMetadata(
179:                        ISIDENTICAL_LOCAL_METHOD, bean));
180:
181:                // GetHandle
182:                bean.addMethodAnnotationMetadata(new MethodAnnotationMetadata(
183:                        GETHANDLE_METHOD, bean));
184:
185:                // GetPrimaryKey
186:                bean.addMethodAnnotationMetadata(new MethodAnnotationMetadata(
187:                        GETPRIMARYKEY_METHOD, bean));
188:
189:            }
190:
191:            /**
192:             * Found interfaces specified on return type of the createXXX() method and
193:             * add them in the given list.
194:             * @param home the name of the class to analyze.
195:             * @param interfacesList the given list where to add interfaces found
196:             * @param ejbJarAnnotationMetadata the metatada where to get metadata
197:             */
198:            private static void getInterfacesFromHome(final String home,
199:                    final List<String> interfacesList,
200:                    final EjbJarAnnotationMetadata ejbJarAnnotationMetadata) {
201:
202:                String encodedname = home.replace(".", "/");
203:
204:                // Get metadata of the given home interface
205:                ClassAnnotationMetadata homeMetadata = ejbJarAnnotationMetadata
206:                        .getClassAnnotationMetadata(encodedname);
207:                if (homeMetadata == null) {
208:                    throw new IllegalStateException("Cannot find the class '"
209:                            + home
210:                            + "' referenced as an home/localhome interface");
211:                }
212:
213:                // Get methods
214:                for (MethodAnnotationMetadata method : homeMetadata
215:                        .getMethodAnnotationMetadataCollection()) {
216:                    // if method name begins with "create", it's matching
217:                    if (method.getMethodName().startsWith("create")) {
218:                        // Get return type
219:                        JMethod jMethod = method.getJMethod();
220:                        Type returnType = Type.getReturnType(jMethod
221:                                .getDescriptor());
222:                        String returnTypeClassname = returnType.getClassName();
223:                        // Not yet present in the list ? add it
224:                        if (!interfacesList.contains(returnTypeClassname)) {
225:                            interfacesList.add(returnTypeClassname.replace(".",
226:                                    "/"));
227:                        }
228:                    }
229:                }
230:
231:                // Parent is not EJBHome or EJBLocalHome then loop again on the super
232:                // name
233:                String[] interfaces = homeMetadata.getInterfaces();
234:                if (interfaces != null) {
235:                    for (String itf : interfaces) {
236:                        if (!"javax/ejb/EJBHome".equals(itf)
237:                                && !"javax/ejb/EJBLocalHome".equals(itf)) {
238:                            getInterfacesFromHome(itf, interfacesList,
239:                                    ejbJarAnnotationMetadata);
240:                        }
241:                    }
242:                }
243:            }
244:        }
w__w_w___._j__a__va_2__s_.__co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.