KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > ejbql > EjbQLFromCmpEntityDescriptor


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.ejbql;
25
26 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException;
27 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
32 import com.sun.enterprise.tools.verifier.tests.*;
33 import com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator;
34 import java.util.Collection JavaDoc;
35 import java.util.Iterator JavaDoc;
36
37
38
39 /**
40  * This test verifies whether EJB QLs specified under <entity>
41  * element have any syntax or semantic errors.
42  *
43  * @author Qingqing Ouyang
44  * @version
45  */

46 public class EjbQLFromCmpEntityDescriptor extends EjbTest implements EjbCheck {
47
48     /**
49      * Implements the check on EJB QL's syntax and semantics.
50      *
51      * @param descriptor the Enterprise Java Bean deployment descriptor
52      * @return <code>Result</code> the results for this assertion
53      */

54     public Result check(EjbDescriptor descriptor) {
55         
56     Result result = getInitializedResult();
57     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
58     try {
59
60         if (descriptor instanceof IASEjbCMPEntityDescriptor) {
61             Collection JavaDoc col = null;
62             if(getVerifierContext().getJDOException()!=null){
63                 result.addErrorDetails(smh.getLocalString
64                             ("tests.componentNameConstructor",
65                                     "For [ {0} ]",
66                                     new Object JavaDoc[] {compName.toString()}));
67                 result.failed (smh.getLocalString(getClass().getName() + ".failed1",
68                             "Error: Exception [ {0} ] while initialising JDO code generator.",
69                             new Object JavaDoc[] {getVerifierContext().getJDOException().getMessage()}));
70
71                 return result;
72             }else{
73                 try{
74                     JDOCodeGenerator jdc= getVerifierContext().getJDOCodeGenerator();
75                     col = jdc.validate((IASEjbCMPEntityDescriptor)descriptor);
76                 }catch(Exception JavaDoc ex){
77                     result.addErrorDetails(smh.getLocalString
78                             ("tests.componentNameConstructor",
79                                     "For [ {0} ]",
80                                     new Object JavaDoc[] {compName.toString()}));
81                     result.failed (smh.getLocalString(getClass().getName() + ".failed",
82                             "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().",
83                             new Object JavaDoc[] {ex.getMessage()}));
84                     return result;
85                 }
86             }
87             if (col.isEmpty()){
88               result.addGoodDetails(smh.getLocalString
89                                        ("tests.componentNameConstructor",
90                                         "For [ {0} ]",
91                                         new Object JavaDoc[] {compName.toString()}));
92               result.passed(smh.getLocalString(getClass().getName() + ".passed",
93                             "Syntax and Semantics of EJBQL Queries (if any) are correct."));
94
95             }else{
96                // collect all the EJBQL errors
97
String JavaDoc allErrors = null;
98                Iterator JavaDoc it = col.iterator();
99                while (it.hasNext()) {
100                   Exception JavaDoc e = (Exception JavaDoc)it.next();
101                   if (e instanceof EJBQLException) {
102                      allErrors = e.getMessage() + "\n\n";
103                   }
104                }
105
106                if (allErrors != null) {
107                  result.addErrorDetails(smh.getLocalString
108                                        ("tests.componentNameConstructor",
109                                         "For [ {0} ]",
110                                         new Object JavaDoc[] {compName.toString()}));
111                  result.failed(smh.getLocalString(getClass().getName() + ".parseError",
112                             "Error: Entity bean [ {0} ] has the following EJBQL error(s) [ {1} ]."
113                             , new Object JavaDoc[] {descriptor.getEjbClassName(), "\n" + allErrors} ));
114
115                }
116                else {
117                  result.addGoodDetails(smh.getLocalString
118                                        ("tests.componentNameConstructor",
119                                         "For [ {0} ]",
120                                         new Object JavaDoc[] {compName.toString()}));
121                  result.passed(smh.getLocalString(getClass().getName() + ".passed",
122                             "Syntax and Semantics of EJBQL Queries (if any) are correct."));
123                }
124             }
125
126     } else {
127         result.addNaDetails(smh.getLocalString
128                        ("tests.componentNameConstructor",
129                     "For [ {0} ]",
130                     new Object JavaDoc[] {compName.toString()}));
131         result.notApplicable(
132                     smh.getLocalString(getClass().getName() + ".notApplicable",
133                             "Not applicable: Test only applies to container managed EJBs"));
134     }
135     } catch(Exception JavaDoc e) {
136       result.addErrorDetails(smh.getLocalString
137                                        ("tests.componentNameConstructor",
138                                         "For [ {0} ]",
139                                         new Object JavaDoc[] {compName.toString()}));
140       result.failed (smh.getLocalString(getClass().getName() + ".failed",
141                             "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().",
142                             new Object JavaDoc[] {e.getMessage()}));
143     }
144       return result;
145     }
146 }
147
Popular Tags