KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb.runtime.beancache;
25
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.tools.verifier.Result;
28 import com.sun.enterprise.tools.verifier.Verifier;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30
31 /** ejb [0,n]
32  * bean-cache ?
33  * max-cache-size ? [String]
34  * is-cache-overflow-allowed ? [String]
35  * cache-idle-timout-in-seconds ? [String]
36  * removal-timeout-in-seconds ? [String]
37  * victim-selection-policy ? [String]
38  *
39  * The max-cache-size specifies the maximum number of beans in the cache.
40  * Valid values are between 1 and MAX_INT
41  * @author Irfan Ahmed
42  */

43
44 public class ASEjbBCMaxCacheSize extends ASEjbBeanCache
45 {
46     
47     public Result check(EjbDescriptor descriptor)
48     {
49
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52         String JavaDoc beanCache = null;
53         String JavaDoc maxCacheSize = null;
54         try
55         {
56             beanCache = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache");
57             if(beanCache!=null)
58             {
59                 maxCacheSize=getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache/max-cache-size");
60                 if(maxCacheSize!=null)
61                 {
62                     maxCacheSize=maxCacheSize.trim();
63                     if(maxCacheSize.length()==0)
64                     {
65                         addErrorDetails(result, compName);
66                         result.failed(smh.getLocalString(getClass().getName()+".failed1",
67                             "FAILED [AS-EJB bean-pool] : max-cache-size cannot be empty"));
68                     }else
69                     {
70                         try{
71                             int cacheValue=new Integer JavaDoc(maxCacheSize).intValue();
72                             if(cacheValue <= 1 || cacheValue > Integer.MAX_VALUE)
73                             {
74                                 addErrorDetails(result, compName);
75                                 result.failed(smh.getLocalString(getClass().getName()+".failed",
76                                     "FAILED [AS-EJB bean-cache] : max-cache-size should be greater than 1 and less than MAX_INT"));
77                             }
78                             else
79                             {
80                                 addGoodDetails(result, compName);
81                                 result.passed(smh.getLocalString(getClass().getName()+".passed",
82                                     "PASSED [AS-EJB bean-cache] : max-cache-size is {0}",new Object JavaDoc[]{(new Integer JavaDoc(maxCacheSize))}));
83                             }
84                         }catch(NumberFormatException JavaDoc nfex)
85                         {
86                             Verifier.debug(nfex);
87                             addErrorDetails(result, compName);
88                             result.failed(smh.getLocalString(getClass().getName()+".failed2",
89                                 "FAILED [AS-EJB bean-pool] : The value {0} for max-pool-size is not a valid Integer number",new Object JavaDoc[]{maxCacheSize}));
90
91                         }
92                     }
93                 }else //max-cache-size not defined
94
{
95                     addNaDetails(result, compName);
96                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
97                           "NOT APPLICABLE [AS-EJB bean-cache] : max-cache-size is element not defined"));
98                 
99                 }
100                 
101             }else //bean-cache element is not present
102
{
103                 addNaDetails(result, compName);
104                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
105                     "NOT APPLICABLE [AS-EJB] : bean-cache element not defined"));
106             }
107         }catch(Exception JavaDoc ex){
108             
109             addErrorDetails(result, compName);
110             result.addErrorDetails(smh.getLocalString
111                  (getClass().getName() + ".notRun",
112                   "NOT RUN [AS-EJB] : Could not create the descriptor object"));
113         }
114         return result;
115     }
116 }
117
Popular Tags