KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.ias;
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.EjbDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 import com.sun.enterprise.tools.common.dd.ejb.*;
36 import com.sun.enterprise.tools.common.dd.*;
37 import java.io.*;
38 import java.util.jar.*;
39 import java.util.zip.*;
40 import com.sun.enterprise.deployment.*;
41
42 /** enterprise-beans
43  * pm-descriptors ?
44  * pm-descriptor
45  * pm-identifier [String]
46  * pm-version [String]
47  * pm-config ? [String]
48  * pm-class-generator ? [String]
49  * pm-mapping-factory ? [String]
50  * pm-inuse
51  * pm-identifier [String]
52  * pm-version [String]
53  *
54  * The pm-descriptors element contains one or more pm-descriptor elements
55  * The pm-descriptor describes the properties for the persistence
56  * manager associated with the entity bean.
57  * The pm-identifier and pm-version fields are required and should not be null.
58  * the pm-config should be a valid ias-cmp-mapping descriptor
59  *
60  * The pm-inuse identifies the persistence manager in use at a particular time.
61  * The pm-identifier and pm-version should be from the pm-descriptor
62  * element.
63  * @author Irfan Ahmed
64  */

65 public class ASEntBeanPmDescriptors extends EjbTest implements EjbCheck {
66     private boolean oneFailed=false;//4698035
67
private boolean oneWarning=false;
68
69     public Result check(EjbDescriptor descriptor) {
70
71     Result result = getInitializedResult();
72     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
73
74         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
75         String JavaDoc ejbName = null;
76         
77         
78         
79         if(descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName()))
80         {
81             result.setStatus(Result.NOT_RUN);
82             result.addGoodDetails(smh.getLocalString("enterpriseBeans.allReadyRun",
83                 "NOT RUN [AS-EJB enterprise-beans] pm-descritors test is a JAR Level Test. This test has already been run once"));
84             return result;
85         }
86         descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName());
87         
88         if(ejbJar!=null)
89         {
90             PmDescriptors pmDescs = ejbJar.getEnterpriseBeans().getPmDescriptors();
91             if(pmDescs!=null)
92             {
93                 PmDescriptor[] pmDesc = pmDescs.getPmDescriptor();
94                 Map pmIdVer = new HashMap();
95                 for(int i=0;i<pmDesc.length;i++)
96                 {
97                     testPmDescriptor(pmDesc[i],result,pmIdVer,descriptor);
98                 }
99                 
100                 PmInuse pmInUse = pmDescs.getPmInuse();
101                 String JavaDoc pmIdentifier = pmInUse.getPmIdentifier();
102                 String JavaDoc pmVersion = pmInUse.getPmVersion();
103                 if(pmIdVer.containsKey(pmIdentifier))
104                 {
105                     result.passed(smh.getLocalString(getClass().getName()+".passed",
106                         "PASSED [AS-EJB pm-inuse] : pm-identifier {0} is valid"
107                         ,new Object JavaDoc[]{pmIdentifier}));
108                     String JavaDoc testVersion = (String JavaDoc)pmIdVer.get(pmIdentifier);
109                     if(testVersion.equals(pmVersion))
110                     {
111                         result.passed(smh.getLocalString(getClass().getName()+".passed1",
112                             "PASSED [AS-EJB pm-inuse] : pm-version {0} is valid",
113                             new Object JavaDoc[]{pmVersion}));
114                     }
115                     else
116                     {
117                         // <addition> srini@sun.com Bug: 4698038
118
//result.failed(smh.getLocalString(getClass().getName()+".failed",
119
// "FAILED [AS-EJB pm-inuse] : pm-version {0} for pm-identifier {0} not defined in pm-descriptors"
120
//, new Object[]{pmVersion, pmIdentifier}));
121
result.failed(smh.getLocalString(getClass().getName()+".failed",
122                           "FAILED [AS-EJB pm-inuse] : pm-version {0} for pm-identifier {1} not defined in pm-descriptors"
123                         , new Object JavaDoc[]{pmVersion, pmIdentifier}));
124                         // </addition> Bug: 4698038
125
oneFailed=true;
126                     }
127                 }
128                 else
129                 {
130                     result.failed(smh.getLocalString(getClass().getName()+".failed1",
131                         "FAILED [AS-EJB pm-inuse] : pm-identifier {0} is not defined in pm-descriptors"
132                         , new Object JavaDoc[]{pmIdentifier}));
133                         oneFailed=true;
134                 }
135                 
136                 if(oneFailed)
137                     result.setStatus(Result.FAILED);
138                 else if(oneWarning)
139                     result.setStatus(Result.WARNING);
140                 
141             }
142             else
143             {
144                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
145                     "NOT APPLICABLE [AS-EJB enterprise-beans] : pm-descriptors Element not defined"));
146             }
147         }
148         else
149         {
150             result.addErrorDetails(smh.getLocalString
151                  (getClass().getName() + ".notRun",
152                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
153         }
154         return result;
155     }
156     
157     /**
158      * @param desc
159      * @param result
160      * @param idVerMap */

161     protected void testPmDescriptor(PmDescriptor desc, Result result,Map idVerMap,EjbDescriptor descriptor)
162     {
163         //pm-identifier
164
String JavaDoc value = desc.getPmIdentifier();
165         if(value.length()==0)
166         {
167             result.failed(smh.getLocalString(getClass().getName()+".failed2",
168                 "FAILED [AS-EJB pm-descritor] : pm-identifier cannot be an empty string"));
169             oneFailed=true;
170         }
171         else
172         {
173             result.passed(smh.getLocalString(getClass().getName()+".passed2",
174                 "PASSED [AS-EJB pm-descriptor] : pm-identifier is {0}",
175                 new Object JavaDoc[]{value}));
176         }
177         
178         //pm-version
179
value = desc.getPmVersion();
180         if(value.length()==0)
181         {
182             result.failed(smh.getLocalString(getClass().getName()+".failed3",
183                 "FAILED [AS-EJB pm-descritor] : pm-version cannot be an empty string"));
184             oneFailed=true;
185         }
186         else
187             result.passed(smh.getLocalString(getClass().getName()+".passed3",
188                 "PASSED [AS-EJB pm-descriptor] : pm-version is {0}",
189                 new Object JavaDoc[]{value}));
190         idVerMap.put(desc.getPmIdentifier(),desc.getPmVersion());
191         //pm-config
192
value = desc.getPmConfig();
193         if(value==null)
194         {
195             oneWarning=true;
196             result.warning(smh.getLocalString(getClass().getName()+".warning",
197                 "WARNING [AS-EJB pm-descriptor] : pm-config value is missing"));
198         }
199         else
200         {
201             
202             /*if(value.length()==0)
203             {
204                 result.failed(smh.getLocalString(getClass().getName()+".failed4",
205                     "FAILED [AS-EJB pm-descritor] : pm-config cannot be an empty string"));
206             }
207             else
208                 result.passed(smh.getLocalString(getClass().getName()+".passed4",
209                     "PASSED [AS-EJB pm-descriptor] : pm-config is {0}",
210                     new Object[]{value}));
211              */

212             
213             ////// //4698035
214
if(value.length()==0)
215                     {
216                         oneFailed = true;
217                         result.failed(smh.getLocalString(getClass().getName()+".failed4",
218                                 "FAILED [AS-EJB pm-descritor] : pm-config cannot be an empty string"));
219                         
220                     }
221                     else
222                     { File f = Verifier.getJarFile(((EjbBundleArchivist) descriptor.getEjbBundleDescriptor().getArchivist()).getEjbJarFile().getName());
223                         JarFile jarFile = null;
224                         ZipEntry deploymentEntry=null;
225                         try {
226                               jarFile = new JarFile(f);
227                               if(jarFile!=null)
228                               deploymentEntry = jarFile.getEntry(value);
229                               
230
231                         }
232                         catch(IOException e){}
233                         finally{
234                            try{ if(jarFile!=null) jarFile.close();}
235                            catch(IOException e){}
236                         }
237
238                         if(deploymentEntry !=null){
239                             result.passed(smh.getLocalString(getClass().getName()+".passed4",
240                             "PASSED [AS-EJB pm-descriptor] : pm-config is {0}",
241                             new Object JavaDoc[]{value}));
242                         }
243                         else{
244                             oneWarning=true;
245                             result.warning(smh.getLocalString(getClass().getName()+".warning3",
246                             "WARNING [AS-EJB pm-descriptor] : config file {0} pointed in pm-config is not present in the jar file",
247                             new Object JavaDoc[]{value}));
248                         
249                         
250                         }
251                     }
252                 /////////
253

254         }
255                 
256         //pm-class-generator
257
value = desc.getPmClassGenerator();
258         if(value == null)
259         {
260             oneWarning=true;
261             result.warning(smh.getLocalString(getClass().getName()+".warning1",
262                 "WARNING [AS-EJB pm-descriptor] : pm-class-generaor value is missing"));
263         }
264         else if(value.trim().indexOf(" ") != -1) // Bug 4698042
265
{
266             oneFailed=true;
267             result.failed(smh.getLocalString(getClass().getName()+".failed7",
268                 "FAILED [AS-EJB pm-descriptor] : pm-class-generator class name is invalid"));
269         }
270         else
271         {
272             if(value.trim().length()==0)
273             {
274                 oneFailed=true;
275                 result.failed(smh.getLocalString(getClass().getName()+".failed5",
276                     "FAILED [AS-EJB pm-descritor] : pm-class-generator cannot be an empty string"));
277             }
278             else
279                 result.passed(smh.getLocalString(getClass().getName()+".passed5",
280                     "PASSED [AS-EJB pm-descriptor] : pm-class-generator is {0}",
281                     new Object JavaDoc[]{value}));
282         }
283
284         //pm-mapping-factory
285
value = desc.getPmMappingFactory();
286         if(value == null)
287         {
288             oneWarning=true;
289             result.warning(smh.getLocalString(getClass().getName()+".warning2",
290                 "WARNING [AS-EJB pm-descriptor] : pm-mapping-factory value is missing"));
291         }
292         else if(value.trim().indexOf(" ") != -1) // Bug 4698042
293
{
294             oneFailed=true;
295             result.failed(smh.getLocalString(getClass().getName()+".failed8",
296                 "FAILED [AS-EJB pm-descriptor] : pm-mapping-factory class name is invalid"));
297         }
298         else
299         {
300             if(value.trim().length()==0)
301             {
302                 oneFailed=true;
303                 result.failed(smh.getLocalString(getClass().getName()+".failed6",
304                     "FAILED [AS-EJB pm-descritor] : pm-pm-mapping-factory cannot be an empty string"));
305             }
306             else
307                 result.passed(smh.getLocalString(getClass().getName()+".passed6",
308                     "PASSED [AS-EJB pm-descriptor] : pm-mapping-factory is {0}",
309                     new Object JavaDoc[]{value}));
310         }
311     }
312 }
313
Popular Tags