KickJava   Java API By Example, From Geeks To Geeks.

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


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.EJBQLC;
27 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException;
28
29 import com.sun.enterprise.deployment.PersistenceDescriptor;
30 import com.sun.enterprise.deployment.EjbDescriptor;
31 import com.sun.enterprise.deployment.EjbCMPEntityDescriptor;
32 import com.sun.enterprise.deployment.QueryDescriptor;
33 import com.sun.enterprise.deployment.MethodDescriptor;
34 import com.sun.enterprise.tools.verifier.Result;
35 import com.sun.enterprise.tools.verifier.StringManagerHelper;
36 import com.sun.enterprise.util.LocalStringManagerImpl;
37 import java.lang.reflect.Method JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import com.sun.enterprise.tools.verifier.tests.*;
40
41
42 /**
43  * This class contains tests for EJB QLs that are shared
44  * by tests for entity beans and for depenent objects.
45  *
46  * @author Qingqing Ouyang
47  * @version
48  */

49 public class EjbQLChecker {
50     
51     /**
52      * <p>
53      * helper property to get to the localized strings
54      * </p>
55      */

56     protected static final LocalStringManagerImpl smh =
57         StringManagerHelper.getLocalStringsManager();
58     
59     /**
60      * Check the syntax and semantics of the targetted
61      * queries.
62      *
63      * @param desc An PersistenceDescriptor object.
64      * @param ejbqlDriver An EjbQlDriver created using the
65      * targetted ejb bundle.
66      * @param result The test results.
67      * @param ownerClassName Name of the class initiated the test.
68      * @return whether any error has occurred.
69      */

70     public static boolean checkSyntax (EjbDescriptor ejbDesc,
71             EJBQLC ejbqlDriver, Result result, String JavaDoc ownerClassName) {
72         
73         boolean hasError = false;
74         String JavaDoc query = null;
75         PersistenceDescriptor desc = ((EjbCMPEntityDescriptor)ejbDesc).getPersistenceDescriptor();
76         
77         for (Iterator JavaDoc it = desc.getQueriedMethods().iterator(); it.hasNext();) {
78             MethodDescriptor method = (MethodDescriptor) it.next();
79             try {
80                 QueryDescriptor qDesc = desc.getQueryFor(method);
81                 query = qDesc.getQuery();
82                 
83                 if (qDesc.getIsEjbQl()) {
84                     Method JavaDoc m = method.getMethod(ejbDesc);
85
86                     int retypeMapping = mapRetType(qDesc.getReturnTypeMapping());
87         
88                     boolean finder = false;
89
90                     if ((method.getName()).startsWith("find")) {
91                        finder = true;
92                        retypeMapping = 2; /*QueryDescriptor.NO_RETURN_TYPE_MAPPING;*/
93                     }
94
95                     ejbqlDriver.compile(query, m, retypeMapping, finder, ejbDesc.getName());
96                 }
97             } catch (EJBQLException ex) {
98                 ex.printStackTrace();
99                 if (!hasError) {
100                     hasError = true;
101                 }
102     
103                 result.addErrorDetails
104                     (smh.getLocalString(ownerClassName + ".parseError",
105                             "Error: [ {0} ] has parsing error(s)",
106                             new Object JavaDoc[] {query}));
107         result.addErrorDetails
108             (smh.getLocalString(ownerClassName + ".SAXParseException",
109                             "Exception occured : [{0}]",
110                             new Object JavaDoc[] {ex.toString()}));
111             }
112
113         }
114     if (hasError == false) {
115         result.addGoodDetails
116             (smh.getLocalString(ownerClassName + ".passed",
117                             " Syntax and Semantics of the Queries are correct",
118                 new Object JavaDoc[] {}));
119     }
120         return hasError;
121     }
122
123  private static int mapRetType(int rettype) {
124
125     switch(rettype) {
126
127     case 0 : return 2;
128     case 1 : return 0;
129     case 2 : return 1;
130     default: return 2;
131          
132     }
133
134  }
135
136 }
137
Popular Tags