KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > beanclass > EjbClassModifiersAbstract


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.beanclass;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.reflect.Modifier JavaDoc;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * Enterprise Java Bean class modifiers test. The class must not be defined
33  * as abstract.
34  */

35 public class EjbClassModifiersAbstract extends EjbTest {
36
37
38     /**
39      * Enterprise Java Bean class modifiers test. The class must not be defined
40      * as abstract.
41      *
42      * @param descriptor the Enterprise Java Bean deployment descriptor
43      *
44      * @return <code>Result</code> the results for this assertion
45      */

46     public Result check(EjbDescriptor descriptor) {
47
48     Result result = getInitializedResult();
49         boolean shouldBeAbstract = false;
50     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
51
52         if (descriptor instanceof EjbEntityDescriptor) {
53             String JavaDoc persistentType = ((EjbEntityDescriptor)descriptor).getPersistenceType();
54             if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
55                 if (EjbCMPEntityDescriptor.CMP_1_1!=((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
56                     shouldBeAbstract = true;
57                 }
58             }
59         }
60         Class JavaDoc c = loadEjbClass(descriptor, result);
61         if (c!=null) {
62
63             boolean isAbstract = false;
64             int modifiers = c.getModifiers();
65             if (Modifier.isAbstract(modifiers)) {
66                 isAbstract = true;
67             }
68
69             if (!isAbstract && !shouldBeAbstract) {
70         result.addGoodDetails(smh.getLocalString
71                       ("tests.componentNameConstructor",
72                        "For [ {0} ]",
73                        new Object JavaDoc[] {compName.toString()}));
74                 result.passed(smh.getLocalString
75                   (getClass().getName() + ".passed",
76                    "[ {0} ] properly declares non-abstract class modifier.",
77                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
78             }
79             if (isAbstract && shouldBeAbstract) {
80         result.addGoodDetails(smh.getLocalString
81                       ("tests.componentNameConstructor",
82                        "For [ {0} ]",
83                        new Object JavaDoc[] {compName.toString()}));
84                 result.passed(smh.getLocalString
85                   (getClass().getName() + ".passed2",
86                    "[ {0} ] properly declares abstract class modifier.",
87                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
88             }
89             if (isAbstract && !shouldBeAbstract ) {
90         result.addErrorDetails(smh.getLocalString
91                        ("tests.componentNameConstructor",
92                     "For [ {0} ]",
93                     new Object JavaDoc[] {compName.toString()}));
94                 result.failed(smh.getLocalString
95                   (getClass().getName() + ".failed",
96                    "Error: Ejb Class [ {0} ] was found, but was declared as abstract. The class [ {1} ] must not be abstract.",
97                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
98             }
99             if (!isAbstract && shouldBeAbstract ) {
100         result.addErrorDetails(smh.getLocalString
101                        ("tests.componentNameConstructor",
102                     "For [ {0} ]",
103                     new Object JavaDoc[] {compName.toString()}));
104                 result.failed(smh.getLocalString
105                   (getClass().getName() + ".failed2",
106                    "Error: CMP 2.0 Entity Bean Class [ {0} ] was found, but was declared as non abstract. The class [ {1} ] must be abstract.",
107                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
108             }
109         
110         }
111         return result;
112  
113     }
114 }
115
Popular Tags