KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2;
25
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.Verifier;
30 import java.lang.ClassLoader JavaDoc;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 /**
34  * Container managed relationship fields tests superclass, iterates over all
35  * declated cmr fields and delegate actual tests to subclasses
36  *
37  * @author Jerome Dochez
38  * @version
39  */

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

52     protected abstract boolean runIndividualCmrTest(Descriptor entity, RelationRoleDescriptor rrd, Class JavaDoc c, Result r);
53     
54     /**
55      *
56      * @param descriptor the Enterprise Java Bean deployment descriptor
57      *
58      * @return <code>Result</code> the results for this assertion
59      */

60     public Result check(EjbCMPEntityDescriptor descriptor) {
61
62         Result result = getInitializedResult();
63         addErrorDetails(result,
64             getVerifierContext().getComponentNameConstructor());
65
66     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
67         boolean oneFailed = false;
68     boolean found = false;
69
70         Class JavaDoc c = loadEjbClass(descriptor, result);
71
72         if (c!=null) {
73             Set cmrFields = ((EjbCMPEntityDescriptor)descriptor).getPersistenceDescriptor().getRelationships();
74             Iterator cmrIterator = cmrFields.iterator();
75
76         if (cmrIterator.hasNext()) {
77         while (cmrIterator.hasNext()) {
78             RelationshipDescriptor cmfDescriptor = (RelationshipDescriptor) cmrIterator.next();
79             {
80                 // test if this bean is the source in this relationship
81
RelationRoleDescriptor role = cmfDescriptor.getSource();
82                 if (role.getOwner().equals(descriptor) && role.getCMRField()!=null) {
83                 found = true;
84                 if (!runIndividualCmrTest(descriptor, role, c, result)) {
85                     oneFailed = true;
86                 }
87                 }
88             }
89             // we need to test for both source and sink because of self references
90
{
91                 // test if this bean is the sink in this relationship
92
RelationRoleDescriptor role = cmfDescriptor.getSink();
93                 if (role.getOwner().equals(descriptor) && role.getCMRField()!=null) {
94                 found = true;
95                 if (!runIndividualCmrTest(descriptor, role, c, result)) {
96                     oneFailed = true;
97                 }
98                 }
99             }
100         }
101         if (oneFailed)
102             result.setStatus(Result.FAILED);
103         else if (found == false) {
104              result.addNaDetails(smh.getLocalString
105                        ("tests.componentNameConstructor",
106                     "For [ {0} ]",
107                     new Object JavaDoc[] {compName.toString()}));
108             result.notApplicable(smh.getLocalString
109                  ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldTest.notApplicable",
110                   "Not Applicable : The EJB has no CMR fields declared",
111                   new Object JavaDoc[] {}));
112         }
113         else
114             result.setStatus(Result.PASSED);
115         }
116         else {
117          result.addNaDetails(smh.getLocalString
118                        ("tests.componentNameConstructor",
119                     "For [ {0} ]",
120                     new Object JavaDoc[] {compName.toString()}));
121         result.notApplicable(smh.getLocalString
122                  ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldTest.notApplicable",
123                   "Not Applicable : The EJB has no CMR fields declared",
124                   new Object JavaDoc[] {}));
125         }
126     }
127         return result;
128     }
129 }
130
Popular Tags