KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.lang.reflect.Constructor JavaDoc;
27 import java.lang.reflect.Modifier JavaDoc;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 /**
34  * Enterprise Java Bean class constuctor test.
35  * The class must have a public constructor that takes no parameters.
36  */

37 public class EjbClassConstructor extends EjbTest {
38
39
40     /**
41      * Enterprise Java Bean class constuctor test.
42      * The class must have a public constructor that takes no parameters.
43      *
44      * @param descriptor the Enterprise Java Bean deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(EjbDescriptor descriptor) {
49
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52
53         Class JavaDoc c = loadEjbClass(descriptor, result);
54         if (c!=null) {
55
56             boolean foundOne = false;
57             Constructor JavaDoc [] constructors = c.getConstructors();
58             for (int i = 0; i < constructors.length; i++) {
59                 int modifiers = constructors[i].getModifiers();
60                 if (Modifier.isPublic(modifiers)) {
61                     Class JavaDoc [] constructorParameterTypes;
62                     constructorParameterTypes = constructors[i].getParameterTypes();
63                     if (constructorParameterTypes.length > 0) {
64                         continue;
65                     } else {
66                         foundOne = true;
67                         break;
68                     }
69                 }
70             }
71
72             if (foundOne) {
73         result.addGoodDetails(smh.getLocalString
74                       ("tests.componentNameConstructor",
75                        "For [ {0} ]",
76                        new Object JavaDoc[] {compName.toString()}));
77         result.passed(smh.getLocalString
78                   (getClass().getName() + ".passed",
79                    "Valid: This bean [ {0} ] has a public constructor method with no "
80                    + " \n parameters. Enterprise beans must have a public constructor "
81                    + " \n method with no parameters.",
82                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
83             } else {
84         result.addErrorDetails(smh.getLocalString
85                        ("tests.componentNameConstructor",
86                     "For [ {0} ]",
87                     new Object JavaDoc[] {compName.toString()}));
88                 result.failed(smh.getLocalString
89                     (getClass().getName() + ".failed",
90                     "Error: There is no public constructor method with no parameters"
91                     + "\n defined within bean [ {0} ]. Enterprise beans must have a "
92                     + "\n public constructor methods with no parameters.",
93                     new Object JavaDoc[] {descriptor.getEjbClassName()}));
94             }
95         }
96         return result;
97
98     }
99 }
100
Popular Tags