KickJava   Java API By Example, From Geeks To Geeks.

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


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.tests.*;
30
31 /**
32  * Container managed relationship type field must be :
33  * a reference to a local interface of a entity bean
34  * a collection interface for oneToMany or manyToMany relationships
35  *
36  * @author Jerome Dochez
37  * @author Sheetal Vartak
38  * @version
39  */

40 public class CmrFields 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 role, Class JavaDoc c, Result result) {
53      
54     boolean foundIt = false;
55     CMRFieldInfo info = null;
56     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
57
58     try {
59         info = role.getCMRFieldInfo();
60         }catch (Exception JavaDoc e) {
61         addErrorDetails(result, compName);
62         result.addErrorDetails(smh.getLocalString
63            (getClass().getName() + ".failed1",
64             "Error: No Local interfaces defined for EJB [ {0} ]",
65                 new Object JavaDoc[] {descriptor.getName()}));
66         return false;
67         
68     }
69         if (role.getPartner().getIsMany()) {
70             // must be one the collection interface
71
if (info.type.getName().equals("java.util.Collection") ||
72                 info.type.getName().equals("java.util.Set")) {
73                 foundIt = true;
74             }
75         } else {
76         EjbBundleDescriptor bundle = ((EjbDescriptor) descriptor).getEjbBundleDescriptor();
77         if(((EjbDescriptor) descriptor).getLocalClassName() != null &&
78            !"".equals(((EjbDescriptor) descriptor).getLocalClassName())) {
79         if (isValidInterface(info.type, bundle.getEjbs())) {
80             foundIt = true;
81         }
82         }
83         else {
84         if ((role.getRelationshipDescriptor()).getIsBidirectional()) {
85             result.addErrorDetails(smh.getLocalString
86                (getClass().getName() + ".failed",
87                 "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]",
88                 new Object JavaDoc[] {info.name , descriptor.getName()}));
89             return false;
90         }
91         else foundIt = true;
92         }
93         }
94         if (foundIt) {
95          result.addGoodDetails(smh.getLocalString
96                        ("tests.componentNameConstructor",
97                     "For [ {0} ]",
98                     new Object JavaDoc[] {compName.toString()}));
99             result.addGoodDetails(smh.getLocalString
100                (getClass().getName() + ".passed",
101             "Valid type assigned for container managed relationship [ {0} ] in bean [ {1} ]",
102                         new Object JavaDoc[] {info.name , descriptor.getName()}));
103         } else {
104             result.addErrorDetails(smh.getLocalString
105            (getClass().getName() + ".failed",
106             "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]",
107                 new Object JavaDoc[] {info.name , descriptor.getName()}));
108         }
109         return foundIt;
110   
111     }
112     
113     private boolean isValidInterface(Class JavaDoc fieldType, Set entities) {
114         String JavaDoc component = "";
115         if (entities==null)
116             return false;
117     // only local interface can be a valid interface
118
Iterator iterator = entities.iterator();
119         while (iterator.hasNext()) {
120             EjbAbstractDescriptor entity = (EjbAbstractDescriptor) iterator.next();
121         if (fieldType.getName().equals(entity.getLocalClassName()))
122         return true;
123     }
124         return false;
125     }
126    
127 }
128
Popular Tags