KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 /** ejb [0,n]
33  * bean-cache ?
34  * max-cache-size ? [String]
35  * resize-quantity ? [String]
36  * is-cache-overflow-allowed ? [String]
37  * cache-idle-timout-in-seconds ? [String]
38  * removal-timeout-in-seconds ? [String]
39  * victim-selection-policy ? [String]
40  *
41  * The max-cache-size specifies the maximum number of beans in the cache.
42  * Valid values are between 1 and MAX_INT
43  */

44
45 public class ASEjbBCResizeQuantity extends ASEjbBeanCache
46 {
47     
48     public Result check(EjbDescriptor descriptor)
49     {
50         Result result = getInitializedResult();
51         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52         String JavaDoc beanCache = null;
53         String JavaDoc resizeQty = null;
54         String JavaDoc maxCacheSize = null;
55         try{
56             beanCache = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache");
57             if(beanCache!=null)
58             {
59                 try
60                 {
61                     resizeQty = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache/resize-quantity");
62                     if (resizeQty!=null)
63                     {
64                         resizeQty = resizeQty.trim();
65                         if (resizeQty.length()==0)
66                         {
67                             addErrorDetails(result, compName);
68                             result.failed(smh.getLocalString(getClass().getName()+".failed",
69                                 "FAILED [AS-EJB bean-cache] : resize-quantity cannot be empty"));
70
71                         }else
72                         {
73                             int resizeQtyVal = Integer.valueOf(resizeQty).intValue();
74                             if (resizeQtyVal < 1 || resizeQtyVal > Integer.MAX_VALUE)
75                             {
76                               addErrorDetails(result, compName);
77                               result.failed(smh.getLocalString(getClass().getName()+".failed1",
78                                     "FAILED [AS-EJB bean-cache] : resize-quantity cannot be less than 1 or greater than {0}", new Object JavaDoc[]{new Integer JavaDoc(Integer.MAX_VALUE)}));
79                             }else
80                             {
81                                 int cacheSizeVal=0;
82                                 maxCacheSize = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache/max-cache-size");
83                                 if (maxCacheSize!=null)
84                                 {
85                                     try{
86                                         cacheSizeVal = Integer.valueOf(maxCacheSize).intValue();
87
88                                     }catch(NumberFormatException JavaDoc nfe){
89                                         addErrorDetails(result, compName);
90                                         result.failed(smh.getLocalString(getClass().getName()+".failed2",
91                                             "FAILED [AS-EJB bean-cache] : The value [ {0} ] for max-cache-size is not a valid Integer number",
92                                             new Object JavaDoc[]{maxCacheSize}));
93                                         return result;
94                                     }
95                                     if (cacheSizeVal >= 1 && cacheSizeVal <= Integer.MAX_VALUE)
96                                     {
97                                         if (resizeQtyVal <= cacheSizeVal)
98                                         {
99                                             addGoodDetails(result, compName);
100                                             result.passed(smh.getLocalString(getClass().getName()+".passed",
101                                                 "PASSED [AS-EJB bean-cache] : resize-quantity is {0} and is less than max-cache-size {1}",
102                                                  new Object JavaDoc[]{(new Integer JavaDoc(resizeQty)),new Integer JavaDoc(maxCacheSize)}));
103                                         }
104                                         else
105                                         {
106                                             addErrorDetails(result, compName);
107                                             result.failed(smh.getLocalString(getClass().getName()+".failed3",
108                                                     "FAILED[AS-EJB bean-cache] : resize-quantity {0} should be less than max-cache-size {1}",
109                                                     new Object JavaDoc[]{new Integer JavaDoc(resizeQty), new Integer JavaDoc(maxCacheSize)}));
110                                         }
111                                     }else
112                                     {
113                                         addErrorDetails(result, compName);
114                                         result.failed(smh.getLocalString(getClass().getName()+".failed4",
115                                                 "FAILED [AS-EJB" +"bean-cache] : resize-quantity should be less than max-cache-size and max-cache-size is not a valid integer"));
116
117                                     }
118                                 }else
119                                 {
120                                     addGoodDetails(result, compName);
121                                     result.passed(smh.getLocalString(getClass().getName()+".passed1",
122                                         "PASSED [AS-EJB bean-cache] : resize-quantity is {0}",
123                                          new Object JavaDoc[]{(new Integer JavaDoc(resizeQty))}));
124                                 }
125                             }
126                         }
127
128                     }else // resize-quantity not defined
129
{
130                         addNaDetails(result, compName);
131                         result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
132                           "NOT APPLICABLE [AS-EJB bean-cache] : resize-quantity element is not defined"));
133
134                     }
135                 }catch(NumberFormatException JavaDoc nfex)
136                 {
137                     Verifier.debug(nfex);
138                     addErrorDetails(result, compName);
139                     result.failed(smh.getLocalString(getClass().getName()+".failed5",
140                             "FAILED [AS-EJB bean-cache] : The value [ {0} ] for resize-quantity is not a valid Integer number",
141                             new Object JavaDoc[]{resizeQty}));
142
143
144                 }
145             }else //bean-cache element not defined
146
{
147                 addNaDetails(result, compName);
148                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
149                     "NOT APPLICABLE [AS-EJB] : bean-cache element not defined"));
150
151             }
152     }catch(Exception JavaDoc ex)
153     {
154         addErrorDetails(result, compName);
155         result.addErrorDetails(smh.getLocalString
156                 (getClass().getName() + ".notRun",
157                         "NOT RUN [AS-EJB] : Could not create the descriptor object"));
158     }
159         return result;
160     }
161 }
162
Popular Tags