KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > cmp2 > CmpFieldTest


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 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2;
26
27 import java.util.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.deployment.EjbCMPEntityDescriptor;
30 import com.sun.enterprise.tools.verifier.Result;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33
34 /**
35  * Container-managed persistent fields related tests superclass
36  *
37  * @author Jerome Dochez
38  * @version
39  */

40 abstract public class CmpFieldTest extends CMPTest {
41
42
43     /**
44      * run an individual verifier test of a declated cmp field of the class
45      *
46      * @param entity the descriptor for the entity bean containing the cmp-field
47      * @param f the descriptor for the declared cmp field
48      * @param c the class owning the cmp field
49      * @parma r the result object to use to put the test results in
50      *
51      * @return true if the test passed
52      */

53     protected abstract boolean runIndividualCmpFieldTest(Descriptor entity, Descriptor f, Class JavaDoc c, Result r);
54     
55     /**
56      *
57      * Container-managed persistent fields test, iterates over all declared
58      * cmp fields and invoke the runIndividualCmpFieldTest nethod
59      *
60      * @param descriptor the Enterprise Java Bean deployment descriptor
61      *
62      * @return <code>Result</code> the results for this assertion
63      */

64     public Result check(EjbCMPEntityDescriptor descriptor) {
65
66     Result result = getInitializedResult();
67     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
68
69         Class JavaDoc c = loadEjbClass(descriptor, result);
70         if (c!=null) {
71             Descriptor persistentField;
72         boolean oneFailed = false;
73             
74             Set persistentFields = descriptor.getPersistenceDescriptor().getCMPFields();
75             Iterator iterator = persistentFields.iterator();
76         if (iterator.hasNext()) {
77         while (iterator.hasNext()) {
78             persistentField = (Descriptor)iterator.next();
79             boolean status = runIndividualCmpFieldTest(descriptor, persistentField, c, result);
80             if (!status)
81             oneFailed=true;
82             
83         }
84         if (oneFailed) {
85             result.setStatus(Result.FAILED);
86         } else {
87             result.setStatus(Result.PASSED);
88         }
89         }
90         else {
91         result.addNaDetails(smh.getLocalString
92                        ("tests.componentNameConstructor",
93                     "For [ {0} ]",
94                     new Object JavaDoc[] {compName.toString()}));
95         result.notApplicable(smh.getLocalString
96                      ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmpFieldTest.notApplicable",
97                       "Not Applicable : The EJB has no CMP fields declared",
98                       new Object JavaDoc[] {}));
99         }
100     }
101         return result;
102     }
103 }
104
Popular Tags