KickJava   Java API By Example, From Geeks To Geeks.

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


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  * pool-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 steady-pool-size element specifies the initial and minimum number of beans
40  * that must be maintained in the bean pool.
41  *
42  * Valid values are from 0 to MAX_INT
43  *
44  *
45  * @author Irfan Ahmed
46  */

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