KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ias > cmpmapping > ASSunCmpMappingTest


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 /*
25  * ASSunCmpMappingTest.java
26  *
27  * //test class, to integrate JDOCodeGenerator validation framework
28  */

29
30
31 package com.sun.enterprise.tools.verifier.tests.ejb.ias.cmpmapping;
32
33
34 import java.util.*;
35 import com.sun.enterprise.deployment.EjbDescriptor;
36 import com.sun.enterprise.deployment.EjbSessionDescriptor;
37 import com.sun.enterprise.tools.verifier.*;
38 import com.sun.enterprise.tools.verifier.tests.*;
39 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
40 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar;
41 import com.sun.enterprise.tools.common.dd.ejb.Ejb;
42 import com.sun.enterprise.tools.common.dd.ResourceRef;
43 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal;
44 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
45 import com.sun.enterprise.tools.verifier.tests.ejb.*;
46 import com.sun.enterprise.tools.common.dd.cmpmapping.*;
47 import com.sun.jdo.spi.persistence.support.ejb.ejbc.*;
48 import com.sun.enterprise.deployment.DescriptorConstants;
49 import com.sun.enterprise.deployment.IASEjbBundleDescriptor;
50 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor;
51 import com.sun.ejb.codegen.GeneratorException;
52 import com.sun.enterprise.util.JarClassLoader;
53 import java.io.*;
54 import java.util.jar.*;
55 import java.util.zip.*;
56 import com.sun.enterprise.deployment.*;
57 import com.sun.enterprise.deployment.*;
58
59 public class ASSunCmpMappingTest extends EjbTest implements EjbCheck {
60
61     public Result check(EjbDescriptor descriptor)
62     {
63     Result result = getInitializedResult();
64     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
65         boolean oneFailed = false;
66         boolean notApp = false;
67         boolean initFailed=false;
68       
69         if(descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName()))
70         {
71             result.setStatus(Result.NOT_RUN);
72             result.addGoodDetails(smh.getLocalString("iasEjbJar.allReadyRun",
73                 "NOT RUN [AS-EJB ias-ejb-jar] cmp-mapping is a JAR Level Test. This test has already been run once"));
74             return result;
75         }
76         descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName());
77         
78         IASEjbBundleDescriptor desc=(IASEjbBundleDescriptor)descriptor.getEjbBundleDescriptor();
79         
80         if(!mappingFileExist((EjbDescriptor)descriptor))//4703999
81
{
82             if(containsCMP(desc)){//4724249 additional check if the archive contain a cmp
83
result.warning(smh.getLocalString(getClass().getName()+".warning",
84                 "WARNING [JDO-GEN-CMP-Validation] : CMP mapping file [ {0} ] not present, in the ejb archive [ {1} ].",
85                 new Object JavaDoc[] {EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY, descriptor.getName()}));
86                 return result;
87             }else{
88                 notApp = true;
89                 result.notApplicable(smh.getLocalString
90                                  (getClass().getName() + ".notApplicable",
91                                   "NOT APPLICABLE [JDO-GEN-CMP-Validation] : There is no cmp present, within the ejb archive [ {0} ].",
92                                   new Object JavaDoc[] {descriptor.getName()}));
93                 return result;
94                 
95             }
96             
97             
98         }
99         
100         
101         ClassLoader JavaDoc loader=getVerifierContext().getClassLoader();
102         JDOCodeGenerator jdogen = new JDOCodeGenerator();
103         
104         Iterator ejbs=desc.getEjbs().iterator();
105             //For each entity
106
if(ejbs.hasNext())
107         {
108             try{
109             jdogen.init(desc, loader);
110         
111             }catch(Exception JavaDoc re){
112                 oneFailed = true;
113                 initFailed=true;
114
115                 result.failed(smh.getLocalString(getClass().getName()+".failed2",
116                             "FAILED [JDO-GEN-CMP-Validation] : Unexpected exception occured while initializing JDOCodeGenerator, for the mapping file [ {0} ], "+
117                             "of the ejb archive [ {1} ] . "+
118                             "Check stacktrace for details : \n [ {2} ]" ,
119                             new Object JavaDoc[]{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,descriptor.getName(),re.getMessage()}));
120             
121             
122             }
123             
124             while ( !initFailed && ejbs.hasNext() ) {
125             EjbDescriptor ejbdesc = (EjbDescriptor) ejbs.next();
126             
127             if ( ejbdesc instanceof IASEjbCMPEntityDescriptor ) {
128                   IASEjbCMPEntityDescriptor entd = (IASEjbCMPEntityDescriptor)ejbdesc;
129                     try {
130                          jdogen.validate(entd);
131                          result.passed(smh.getLocalString(getClass().getName()+".passed",
132                             "PASSED [JDO-GEN-CMP-Validation] : The descriptor entries, in the mapping file [ {0} ], "+
133                             "for CMP [ {1} ]"+
134                             "of the ejb archive [ {2} ] are valid. ",
135                             new Object JavaDoc[]{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,ejbdesc.getEjbClassName(),descriptor.getName()}));
136                     } catch (GeneratorException e) {
137                         oneFailed = true;
138
139                         result.failed(smh.getLocalString(getClass().getName()+".failed",
140                             "FAILED [JDO-GEN-CMP-Validation] : Atleast one entry , in the mapping file [ {0} ], "+
141                             "for CMP [ {1} ]"+
142                             "of the ejb archive [ {2} ] is not valid. "+
143                             "Check stacktrace for details : \n [ {3} ]" ,
144                             new Object JavaDoc[]{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,ejbdesc.getEjbClassName(),descriptor.getName(),e.getMessage()}));
145                      
146                     }catch (Exception JavaDoc e) {
147                         oneFailed = true;
148
149                         result.failed(smh.getLocalString(getClass().getName()+".failed1",
150                             "FAILED [JDO-GEN-CMP-Validation] : Unexpected exception occured while validating , the mapping file [ {0} ], "+
151                             "for CMP [ {1} ]"+
152                             "of the ejb archive [ {2} ] . "+
153                             "Check stacktrace for details : \n [ {3} ]" ,
154                             new Object JavaDoc[]{EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY,ejbdesc.getEjbClassName(),descriptor.getName(),e.getMessage()}));
155                      
156                         
157                     }
158
159                 }
160             }//end while loop
161

162         }
163         else{
164             
165           notApp = true;
166           result.notApplicable(smh.getLocalString
167                                  (getClass().getName() + ".notApplicable",
168                                   "NOT APPLICABLE [JDO-GEN-CMP-Validation] : There is no cmp present, within the ejb archive [ {0} ].",
169                                   new Object JavaDoc[] {descriptor.getName()}));
170         }
171         
172         
173         jdogen.cleanup();
174        
175         
176         if (oneFailed) {
177             result.setStatus(Result.FAILED);
178         } else if(notApp) {
179             result.setStatus(Result.NOT_APPLICABLE);
180         }else {
181             result.setStatus(Result.PASSED);
182         }
183         return result;
184     }
185     
186     boolean mappingFileExist(EjbDescriptor descriptor){ //4703999
187
try{
188                 if(descriptor.getEjbBundleDescriptor().getIasCmpMappings() != null)
189                     return true;
190                 else
191                     return false;
192             }catch(Exception JavaDoc e){
193                 return false;
194             }
195             /*
196             File f = Verifier.getJarFile(((EjbBundleArchivist) descriptor.getEjbBundleDescriptor().getArchivist()).getEjbJarFile().getName());
197             JarFile jarFile = null;
198             ZipEntry deploymentEntry=null;
199             try {
200                               jarFile = new JarFile(f);
201                               if(jarFile!=null)
202                               deploymentEntry = jarFile.getEntry(EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY);
203                               
204
205                   }
206             catch(IOException e){}
207             finally{
208                            try{ if(jarFile!=null) jarFile.close();}
209                            catch(IOException e){}
210              }
211
212              if(deploymentEntry!=null)
213                      return true;
214              else
215                      return false;
216         
217              */

218     }
219     
220     boolean containsCMP(IASEjbBundleDescriptor desc) //4724249
221
{
222         
223         if(desc == null || desc.getEjbs() == null )
224             return false;
225         Iterator ejbs=desc.getEjbs().iterator();
226         if(ejbs.hasNext())
227         {
228             while ( ejbs.hasNext() ) {
229                 EjbDescriptor ejbdesc = (EjbDescriptor) ejbs.next();
230                 //if IASEjbCMPEntityDescriptor then there exist a CMP in this archive
231
if ( ejbdesc instanceof IASEjbCMPEntityDescriptor )
232                     return true;
233             }
234         }
235         return false;
236         
237     }
238
239     
240 }
241
242
243
Popular Tags