KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.deployment.RelationRoleDescriptor;
28 import com.sun.enterprise.deployment.CMRFieldInfo;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * Container managed relationship type field must use of the collection
34  * interface for on-to-many or many-to-many relationships and specify it in
35  * the Deployment Descriptor
36  *
37  * @author Jerome Dochez
38  * @version
39  */

40 public class CmrUseCorrectCollectionInterface extends CmrFieldTest {
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 boolean runIndividualCmrTest(Descriptor descriptor, RelationRoleDescriptor rrd, Class JavaDoc c, Result result) {
53         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54         if (rrd.getPartner().getIsMany()) {
55             // must be one the collection interface
56
if (rrd.getCMRFieldType()==null) {
57                 addErrorDetails(result, compName);
58               result.addErrorDetails(smh.getLocalString
59             (getClass().getName() + ".failed2",
60                     "Error : CMR field [ {0} ] cmr-field-type must be defined for one-to-many or many-to-many relationships and the value of the cmr-field-type element must be either: java.util.Collection or java.util.Set",
61                 new Object JavaDoc[] {rrd.getCMRField()}));
62                 return false;
63             } else {
64                 CMRFieldInfo info = rrd.getCMRFieldInfo();
65                 if (rrd.getCMRFieldType().equals(info.type.getName())) {
66                     result.addGoodDetails(smh.getLocalString
67                 (getClass().getName() + ".passed",
68                         "CMR field [ {0} ] is the same type as declared in the deployment descriptors [ {1} ]",
69                         new Object JavaDoc[] {info.name, info.role.getCMRFieldType()}));
70                     return true;
71                 } else {
72                     addErrorDetails(result, compName);
73                     result.addErrorDetails(smh.getLocalString
74                 (getClass().getName() + ".failed",
75                         "Error : CMR field [ {0} ] is not the same type as declared in the deployment descriptors [ {1} ]",
76                     new Object JavaDoc[] {info.name, info.role.getCMRFieldType()}));
77                     return false;
78                 }
79             }
80         }
81        return true;
82     }
83 }
84
Popular Tags