KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ejb30 > EJBCreatePostConstruct


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier.tests.ejb.ejb30;
24
25 import com.sun.enterprise.tools.verifier.Result;
26 import com.sun.enterprise.deployment.EjbSessionDescriptor;
27 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
28
29 import java.lang.reflect.Method JavaDoc;
30
31 /**
32  * If the stateless session bean instance has an ejbCreate method, the container
33  * treats the ejbCreate method as the instance’s PostConstruct method, and, in
34  * this case, the PostConstruct annotation (or deployment descriptor metadata)
35  * can only be applied to the bean’s ejbCreate method.
36  *
37  * @author Vikas Awasthi
38  */

39 public class EJBCreatePostConstruct extends SessionBeanTest {
40
41     public Result check(EjbSessionDescriptor descriptor) {
42
43         if(descriptor.isStateless() &&
44                 descriptor.hasPostConstructMethod() &&
45                 hasEJBCreateMethod(descriptor.getEjbClassName())) {
46             for (LifecycleCallbackDescriptor callbackDesc :
47                     descriptor.getPostConstructDescriptors()) {
48                 String JavaDoc cmName = callbackDesc.getLifecycleCallbackMethod();
49                 if(!cmName.contains("ejbCreate")) {
50                     addErrorDetails(result, compName);
51                     result.failed(smh.getLocalString
52                             (getClass().getName()+".failed",
53                                     "Wrong postconstruct method [ {0} ]",
54                                     new Object JavaDoc[] {cmName}));
55                 }
56             }
57         }
58         
59         if(result.getStatus() != Result.FAILED) {
60             addGoodDetails(result, compName);
61             result.passed(smh.getLocalString
62                             (getClass().getName()+".passed",
63                             "Valid postcontruct method(s) in Bean"));
64         }
65         
66         return result;
67     }
68     
69     private boolean hasEJBCreateMethod(String JavaDoc beanClassName) {
70         try {
71             ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
72             Class JavaDoc bean = Class.forName(beanClassName, false, jcl);
73             Method JavaDoc[] methods = bean.getMethods();
74             for (Method JavaDoc method : methods)
75                 if(method.getName().contains("ejbCreate"))
76                     return true;
77         } catch (ClassNotFoundException JavaDoc e) {}// will be caught in other tests
78
return false;
79     }
80 }
81
Popular Tags