KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > cmp > CmpEjbNoInvalidCreateMethod


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
24 /*
25  * CmpEjbNoInvalidCreateMethod.java
26  *
27  * Created on November 13, 2001, 9:36 AM
28  */

29
30 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp;
31
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
33 import java.lang.reflect.*;
34 import com.sun.enterprise.deployment.*;
35 import com.sun.enterprise.tools.verifier.Result;
36 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
37 /**
38  * Per Ejb 2.0 spec, $14.1.8 create<METHOD> are not supported by
39  * CMP 1.1. EJBs.
40  *
41  * @author Jerome Dochez
42  * @version
43  */

44 public class CmpEjbNoInvalidCreateMethod extends EjbTest implements EjbCheck {
45
46
47     /**
48      * Entity beans with CMP 1.1 must not define create<METHOD>
49      *
50      * @param descriptor the Enterprise Java Bean deployment descriptor
51      *
52      * @return <code>Result</code> the results for this assertion
53      */

54     public Result check(EjbDescriptor descriptor) {
55
56     Result result = getInitializedResult();
57         try {
58
59     if (descriptor instanceof EjbCMPEntityDescriptor) {
60         String JavaDoc persistence =
61         ((EjbEntityDescriptor)descriptor).getPersistenceType();
62         if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence) &&
63                    ((EjbCMPEntityDescriptor)descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_1_1) {
64
65                 try {
66             Class JavaDoc c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
67             Method [] methods = c.getDeclaredMethods();
68                     boolean oneFailed = false;
69                     for (int i=0;i<methods.length;i++) {
70                         Method aMethod = methods[i];
71                         if (aMethod.getName().startsWith("create")) {
72                             if (!aMethod.getName().endsWith("create")) {
73                     result.addErrorDetails(smh.getLocalString
74                                (getClass().getName() + ".failed",
75                                 "CMP 1.1 entity beans are not authorized to define [ {0} ] method",
76                                 new Object JavaDoc[] {aMethod.getName()}));
77                                      oneFailed = true;
78                             }
79                         }
80                     }
81                     if (oneFailed) {
82                 result.setStatus(Result.FAILED);
83                     } else {
84                         result.passed(smh.getLocalString
85                     (getClass().getName() + ".passed",
86                                         "No create<METHOD> defined for this CMP 1.1 entity bean [ {0} ] ",
87                      new Object JavaDoc[] {descriptor.getName()}));
88                     }
89                     return result;
90                 } catch(ClassNotFoundException JavaDoc cnfe) {
91             result.failed(smh.getLocalString
92                   (getClass().getName() + ".failedException",
93                    "Error: [ {0} ] class not found.",
94                    new Object JavaDoc[] {descriptor.getHomeClassName()}));
95                     return result;
96                 }
97             }
98         }
99         } catch(Exception JavaDoc e) {
100             e.printStackTrace();
101         }
102         result.notApplicable(smh.getLocalString
103                              (getClass().getName() + ".notApplicable",
104                               "[ {0} ] is not a CMP 1.1 Entity Bean.",
105                               new Object JavaDoc[] {descriptor.getName()}));
106        return result;
107     }
108 }
109
Popular Tags