KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > runtime > beanpool > ASEjbBPPoolResizeQty


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.beanpool;
25
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.tools.verifier.Verifier;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30
31 /** ejb [0,n]
32  * bean-pool ?
33  * steady-pool-size ? [String]
34  * resize-quantity ? [String]
35  * max-pool-size ? [String]
36  * pool-idle-timeout-in-seconds ? [String]
37  * max-wait-time-in-millis ? [String]
38  *
39  * The resize-quantity specifies the number of beans to be created if the
40  * pool is empty
41  *
42  * valid values are o tp MAX_INT
43  *
44  *
45  * @author Irfan Ahmed
46  */

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