KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > runtime > 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 package com.sun.enterprise.tools.verifier.tests.web.runtime;
25
26 import com.sun.enterprise.deployment.WebBundleDescriptor;
27 import com.sun.enterprise.deployment.runtime.web.Cache;
28 import com.sun.enterprise.deployment.runtime.web.CacheHelper;
29 import com.sun.enterprise.deployment.runtime.web.WebProperty;
30 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
31 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
32 import com.sun.enterprise.tools.verifier.Result;
33
34 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
35
/* Changed the result messages to reflect consistency between the result messages generated
36  * for the EJB test cases for SunONE specific deployment descriptors*/

37 //</addition>
38

39
40
41
42 public class ASCacheHelperClass extends ASCache implements WebCheck {
43     public Result check(WebBundleDescriptor descriptor) {
44         Result result = getInitializedResult();
45     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
46         boolean oneFailed = false;
47         boolean notApp = false;
48         boolean oneWarning=false;
49         boolean presentHelper=false;
50
51         try{
52             Cache cache = (descriptor.getSunDescriptor()).getCache();
53             CacheHelper[] helperClasses=null;
54             CacheHelper helperClass=null;
55             WebProperty[] webProps;
56             String JavaDoc name=null;
57             String JavaDoc classname=null;
58             String JavaDoc[] names=null;
59             //to-do vkv# check for class-name attribute.
60
if (cache != null )
61                 helperClasses=cache.getCacheHelper();
62             if (cache != null && helperClasses !=null && helperClasses.length > 0)
63             {
64                 names=new String JavaDoc[helperClasses.length];
65                 for(int rep=0;rep < helperClasses.length;rep++)
66                 {
67                     helperClass=helperClasses[rep];
68                     if(helperClass==null)
69                         continue;
70                     int i = rep+1;
71                     name = getXPathValue("sun-web-app/cache/cache-helper["+i+"]/@name");
72                     classname = getXPathValue("sun-web-app/cache/cache-helper["+i+"]/@class-name");
73                     Class JavaDoc hClass=null;
74                     names[rep]=name;
75
76                     if (name != null && name.length() != 0) {
77                         //check if the name already exist
78
boolean isDuplicate=false;
79                         for(int rep1=0;rep1<rep;rep1++)
80                         {
81                             if(name.equals(names[rep1]))
82                             {
83                                 isDuplicate=true;
84                                 break;
85                             }
86
87                         }
88                         if(isDuplicate)
89                         {
90                             oneFailed = true;
91                             addErrorDetails(result, compName);
92                             result.failed(smh.getLocalString
93                                       (getClass().getName() + ".failed",
94                                       "FAILED [AS-WEB cache-helper] name attribute [ {0} ], must be unique in the entire list of cache-helper.",
95                                       new Object JavaDoc[] {name}));
96                         }
97                         else
98                         {
99                             if(classname!=null && classname.length()!=0) {
100                                 hClass = loadClass(result,classname);
101                             }
102                             if(hClass !=null)
103                                 presentHelper=true ;
104                             else
105                                 presentHelper=false ;
106                           
107                             if(!presentHelper)
108                             {
109                                 addWarningDetails(result, compName);
110                                 result.warning(smh.getLocalString(
111                                                     getClass().getName() + ".error",
112                                                     "WARNING [AS-WEB cache-helper] " +
113                                                     "name [ {0} ], class not present in the war file.",
114                                                     new Object JavaDoc[] {name}));
115                                 oneWarning = true;
116                             }
117                             else
118                             {
119                                 addGoodDetails(result, compName);
120                                 result.passed(smh.getLocalString
121                       (getClass().getName() + ".passed",
122                        "PASSED [AS-WEB cache-helper] name [ {0} ], helper class is valid.",
123                        new Object JavaDoc[] {name}));
124                             }
125                             
126                         }
127                     } else {
128                         addErrorDetails(result, compName);
129                         result.failed(smh.getLocalString
130                                       (getClass().getName() + ".failed1",
131                                       "FAILED [AS-WEB cache-helper] name [ {0} ], either empty or null.",
132                                       new Object JavaDoc[] {name}));
133                 oneFailed = true;
134                    
135                     }
136                     webProps=helperClass.getWebProperty();
137                     if(ASWebProperty.checkWebProperties(webProps,result ,descriptor, this )){
138                         oneFailed=true;
139                         addErrorDetails(result, compName);
140                         result.failed(smh.getLocalString
141                                 (getClass().getName() + ".failed2",
142                                 "FAILED [AS-WEB cache-helper] Atleast one name/value pair is not valid in helper-class of [ {0} ].",
143                                 new Object JavaDoc[] {descriptor.getName()}));
144                     }
145                 }//end of for
146
}else
147             {
148                 notApp = true;
149                 addNaDetails(result, compName);
150                 result.notApplicable(smh.getLocalString
151                 (getClass().getName() + ".notApplicable",
152                     "NOT APPLICABLE [AS-WEB cache-helper] There is no cache-helper element for the web application",
153                         new Object JavaDoc[] {descriptor.getName()}));
154             }
155             if (oneFailed) {
156             result.setStatus(Result.FAILED);
157         } else if(oneWarning){
158             result.setStatus(Result.WARNING);
159         } else if(notApp) {
160             result.setStatus(Result.NOT_APPLICABLE);
161         }else {
162             result.setStatus(Result.PASSED);
163         }
164     
165     }catch(Exception JavaDoc ex){
166     oneFailed = true;
167     addErrorDetails(result, compName);
168     result.failed(smh.getLocalString
169                 (getClass().getName() + ".failed3",
170                     "FAILED [AS-WEB cache-helper] could not create the cache object"));
171     }
172         return result;
173     }
174 }
175
Popular Tags