KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ias > ASCacheHelperClass


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 package com.sun.enterprise.tools.verifier.tests.web.ias;
26
27
28 import java.util.*;
29 import com.sun.enterprise.deployment.*;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
33 import com.sun.enterprise.deployment.WebBundleDescriptor;
34 import com.sun.enterprise.tools.verifier.tests.web.*;
35 import com.sun.enterprise.tools.common.dd.webapp.*;
36
37 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
38
/* Changed the result messages to reflect consistency between the result messages generated
39  * for the EJB test cases for SunONE specific deployment descriptors*/

40 //</addition>
41

42
43 public class ASCacheHelperClass extends ASCache implements WebCheck {
44
45
46     
47     public Result check(WebBundleDescriptor descriptor) {
48
49
50     Result result = getInitializedResult();
51     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
52
53         boolean oneFailed = false;
54         boolean notApp = false;
55         boolean oneWarning=false;
56         boolean presentHelper=false;
57
58         Cache cache = getCache(descriptor);
59
60         CacheHelper[] helperClasses=null;
61         CacheHelper helperClass=null;
62         
63
64         WebProperty[] webProps;
65         String JavaDoc name=null;
66         String JavaDoc classname=null;
67         String JavaDoc[] names=null;
68         
69         //to-do vkv# check for class-name attribute.
70
if (cache != null )
71           helperClasses=cache.getCacheHelper();
72           
73         if (cache != null && helperClasses !=null && helperClasses.length >0) {
74               names=new String JavaDoc[helperClasses.length];
75                
76               for(int rep=0;rep < helperClasses.length;rep++){
77                     helperClass=helperClasses[rep];
78                     if(helperClass==null)
79                         continue;
80             name = helperClass.getAttributeValue("name");
81                     classname= helperClass.getAttributeValue("class-name");
82                     Class JavaDoc hClass=null;
83                     names[rep]=name;
84
85                     if (name!=null || name.length() != 0 ||classname!=null || classname.length() != 0){
86                         //check if the name already exist
87
boolean isDuplicate=false;
88                         for(int rep1=0;rep1<rep;rep1++)
89                         {
90                             if(name.equals(names[rep1])){
91                                 isDuplicate=true;
92                                 break;
93                             }
94
95                         }
96                         
97                      
98                         if(isDuplicate){
99                             oneFailed = true;
100                             result.failed(smh.getLocalString
101                                       (getClass().getName() + ".failed",
102                                       "FAILED [AS-WEB cache-helper] name attribute [ {0} ], must be unique in the entire list of cache-helper.",
103                                       new Object JavaDoc[] {name}));
104                         } else {
105                         
106                             hClass = loadClass(result,classname);
107                        
108                             /*if(hClass !=null) {
109                                if(com.sun.appserv.web.CacheHelper.class.isAssignableFrom(hClass))
110                                          presentHelper=true ;
111                                else
112                                          presentHelper=false ;
113                             }*/

114                             if(hClass !=null)
115                                 presentHelper=true ;
116                             else
117                                 presentHelper=false ;
118                           
119                             if(!presentHelper) {
120                           result.warning(smh.getLocalString(
121                                       getClass().getName() + ".error",
122                                       "WARNING [AS-WEB cache-helper] name [ {0} ], class not present in the war file.",
123                                       new Object JavaDoc[] {name}));
124                                   oneFailed = true;
125                             } else {
126                                 result.passed(smh.getLocalString
127                       (getClass().getName() + ".passed",
128                        "PASSED [AS-WEB cache-helper] name [ {0} ], helper class is valid.",
129                        new Object JavaDoc[] {name}));
130                             }
131                             
132                         }
133
134                     } else {
135                 result.failed(smh.getLocalString
136                                       (getClass().getName() + ".failed1",
137                                       "FAILED [AS-WEB cache-helper] name [ {0} ], either empty or null.",
138                                       new Object JavaDoc[] {name}));
139                 oneFailed = true;
140                    
141                     }
142
143                   webProps=helperClass.getWebProperty();
144
145                   if(ASWebProperty.checkWebProperties(webProps,result ,descriptor, this )){
146                   oneFailed=true;
147                   result.failed(smh.getLocalString
148                                 (getClass().getName() + ".failed2",
149                                 "FAILED [AS-WEB cache-helper] Atleast one name/value pair is not valid in helper-class of [ {0} ].",
150                                 new Object JavaDoc[] {descriptor.getName()}));
151                   }
152                   
153                   
154              }//end of for
155

156
157         } else {
158            
159             notApp = true;
160         result.notApplicable(smh.getLocalString
161                                  (getClass().getName() + ".notApplicable",
162                                   "NOT APPLICABLE [AS-WEB cache-helper] There is no cache-helper element for the web application",
163                                   new Object JavaDoc[] {descriptor.getName()}));
164         }
165         
166         
167         if (oneFailed) {
168             result.setStatus(Result.FAILED);
169         } else if(oneWarning){
170             result.setStatus(Result.WARNING);
171         } else if(notApp) {
172             result.setStatus(Result.NOT_APPLICABLE);
173         }else {
174             result.setStatus(Result.PASSED);
175         }
176     return result;
177     }
178     
179
180 }
181
Popular Tags