KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > runtime > ASEjbCMP


1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime;
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the License). You may not use this file except in
7  * compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
11  * glassfish/bootstrap/legal/CDDLv1.0.txt.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * Header Notice in each file and include the License file
17  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
18  * If applicable, add the following below the CDDL Header,
19  * with the fields enclosed by brackets [] replaced by
20  * you own identifying information:
21  * "Portions Copyrighted [year] [name of copyright owner]"
22  *
23  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24  */

25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import java.util.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 import java.io.*;
35 import java.util.jar.*;
36 import java.util.zip.*;
37
38 import com.sun.enterprise.deployment.runtime.IASEjbCMPFinder;
39
40 /** ejb [0,n]
41  * cmp ?
42  * mapping-properties ? [String]
43  * is-one-one-cmp ? [String]
44  * one-one-finders ?
45  * finder [1,n]
46  * method-name [String]
47  * query-params ? [String]
48  * query-filter ? [String]
49  * query-variables ? [String]
50  * query-ordering ? [String]
51  *
52  * The cmp element describes the runtime information for a CMP enitity bean.
53  * mapping-properties - The vendor specific O/R mapping file
54  * is-one-one-cmp - boolean field used to identify CMP 1.1 descriptors
55  * one-one-finders - The finders for CMP 1.1
56  *
57  * @author Irfan Ahmed
58  */

59 public class ASEjbCMP extends EjbTest implements EjbCheck {
60
61     public boolean oneFailed = false;
62     public boolean oneWarning = false;
63     public Result check(EjbDescriptor descriptor) {
64
65         Result result = getInitializedResult();
66         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
67         try {
68         if (descriptor instanceof IASEjbCMPEntityDescriptor){
69             
70             IASEjbCMPEntityDescriptor cmpBean = (IASEjbCMPEntityDescriptor)descriptor;
71
72             if(cmpBean != null){
73                 String JavaDoc mappingProps = cmpBean.getMappingProperties();
74                 if(mappingProps == null){
75                     oneWarning = true;
76                     addWarningDetails(result, compName);
77                     result.warning(smh.getLocalString(getClass().getName()+".warning",
78                         "WARNING [AS-EJB cmp] : mapping-properties Element is not defined"));
79                 }else{
80                     if(mappingProps.length()==0) {
81                         oneFailed = true;
82                         addErrorDetails(result, compName);
83                         result.failed(smh.getLocalString(getClass().getName()+".failed",
84                             "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value"));
85                     }
86                     else{ //4690436
87
// File f = Verifier.getArchiveFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
88
JarFile jarFile = null;
89                         ZipEntry deploymentEntry=null;
90 // try {
91
// jarFile = new JarFile(f);
92
if(jarFile!=null)
93                                   deploymentEntry = jarFile.getEntry(mappingProps);
94 // }catch(IOException e){}
95
// finally{
96
// try{ if(jarFile!=null) jarFile.close();}
97
// catch(IOException e){}
98
// }
99

100                         if(deploymentEntry !=null){
101                         addGoodDetails(result, compName);
102                         result.passed(smh.getLocalString(getClass().getName()+".passed",
103                             "PASSED [AS-EJB cmp] : mapping-properties file is {0}",
104                             new Object JavaDoc[]{mappingProps}));
105                         }else{
106                             addErrorDetails(result, compName);
107                             //invalid entry
108
result.failed(smh.getLocalString(getClass().getName()+".failed",
109                                 "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value"));
110                         }
111                     }
112                 }
113                 
114                 try{
115                     boolean oneoneCmp = cmpBean.getCMPVersion()==EjbCMPEntityDescriptor.CMP_1_1;
116                     addGoodDetails(result, compName);
117                     result.passed(smh.getLocalString(getClass().getName()+".passed1",
118                         "PASSED [AS-EJB cmp] : is-one-one-cmp is {0}",
119                         new Object JavaDoc[]{new Boolean JavaDoc(oneoneCmp)}));
120                 }catch(Exception JavaDoc ex){
121                     oneWarning = true;
122                     addWarningDetails(result, compName);
123                     result.warning(smh.getLocalString(getClass().getName()+".warning1",
124                         "WARNING [AS-EJB cmp] : is-one-one-cmp Element is not defined"));
125                 }
126                 
127                 try{
128 //EXCEPTION is thrown here as getOneOneFinders() internally uses queryPArser which is null. Exception as:
129
//Apr 4, 2003 11:18:22 AM com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor getOneOneFinder
130
Map finders = cmpBean.getOneOneFinders();
131                     if(finders!=null){
132                         testFinders(finders,result);
133                     }else{
134                         oneWarning = true;
135                         addWarningDetails(result, compName);
136                         result.warning(smh.getLocalString(getClass().getName()+".warning2",
137                             "WARNING [AS-EJB cmp] : one-one-finders Element is not defined"));
138                     }
139                 }catch(Exception JavaDoc ex){
140                     oneFailed = true;
141                     addErrorDetails(result, compName);
142                     result.failed(smh.getLocalString(getClass().getName()+".failed1",
143                         "FAILED [AS-EJB cmp] : getOneOneFinders Failed.",
144                         new Object JavaDoc[]{cmpBean}));
145                 }
146                 
147                 if(oneFailed){
148                     result.setStatus(Result.FAILED);}
149                 else{ if(oneWarning)
150                     result.setStatus(Result.WARNING);}
151                 
152             }else{
153                 addNaDetails(result, compName);
154                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
155                     "NOT APPLICABLE [AS-EJB cmp] : {0} is not a CMP Entity Bean.",
156                     new Object JavaDoc[] {descriptor.getName()}));
157             }
158         }else{
159                 addNaDetails(result, compName);
160                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
161                     "NOT APPLICABLE [AS-EJB cmp] : {0} is not a CMP Entity Bean.",
162                     new Object JavaDoc[] {descriptor.getName()}));
163         }
164         }catch(Exception JavaDoc ex){
165             oneFailed = true;
166             addErrorDetails(result, compName);
167             result.failed(smh.getLocalString(getClass().getName()+".notRun",
168                 "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
169         }
170         return result;
171     }
172     
173
174     public void testFinders(Map finders, Result result) {
175         try{
176         Set keySet = finders.keySet();
177         Iterator it = keySet.iterator();
178         while (it.hasNext()){
179             Object JavaDoc obj = it.next();
180             IASEjbCMPFinder finder = (IASEjbCMPFinder)finders.get(obj);
181             
182             //method-name
183
String JavaDoc methodName = finder.getMethodName();
184             if(methodName.length()==0){
185                 oneFailed = true;
186                 result.failed(smh.getLocalString(getClass().getName()+".failed2",
187                     "FAILED [AS-EJB finder] : method-name cannot be an empty string."));
188             }else{
189                 result.passed(smh.getLocalString(getClass().getName()+".passed2",
190                     "PASSED [AS-EJB finder] : method-name is {0}",
191                     new Object JavaDoc[]{methodName}));
192             }
193
194             //query-params
195
String JavaDoc value = finder.getQueryParameterDeclaration();
196             testQuery(value,result,"finder","query-params");
197
198             //query-filter
199
value = finder.getQueryFilter();
200             testQuery(value,result,"finder","query-filter");
201
202             //query-variables
203
value = finder.getQueryVariables();
204             testQuery(value,result,"finder","query-variables");
205
206             //query-ordering
207
value = finder.getQueryOrdering();
208             testQuery(value,result,"finder","query-ordering");
209         }
210         }catch(Exception JavaDoc ex){
211             oneFailed = true;
212             result.failed(smh.getLocalString(getClass().getName()+".notRun",
213                 "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
214         }
215     }
216
217     public void testQuery(String JavaDoc value, Result result,String JavaDoc parent, String JavaDoc child){
218         if(value == null){
219             oneWarning = true;
220             result.warning(smh.getLocalString(getClass().getName()+".warning3",
221                 "WARNING [AS-EJB {0}] : {1} Element is not defined",
222                 new Object JavaDoc[]{parent,child}));
223         }else{
224             if(value.length()==0){
225                 oneFailed = true;
226                 result.failed(smh.getLocalString(getClass().getName()+".failed3",
227                     "FAILED [AS-EJB {0}] : {1} cannot be an empty string",
228                     new Object JavaDoc[]{parent,child}));
229             }else{
230                 result.passed(smh.getLocalString(getClass().getName()+".passed3",
231                     "PASSED [AS-EJB {0}] : {1} is/are {2}",
232                     new Object JavaDoc[]{parent, child, value}));
233             }
234         }
235     }
236 }
237
Popular Tags