KickJava   Java API By Example, From Geeks To Geeks.

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


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.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-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  *
40  * The value of cache idle timeout in seconds should be between
41  * 0 and MAX_LONG
42  * @author Irfan Ahmed
43  */

44
45 public class ASEjbBCCacheIdleTimeout 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 idleTimeout = null;
54         try{
55             beanCache = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache");
56             if(beanCache!=null)
57             {
58                 try{
59                     idleTimeout = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/bean-cache/cache-idle-timeout-in-seconds");
60                     if(idleTimeout!=null)
61                     {
62                         idleTimeout = idleTimeout.trim();
63                         if (idleTimeout.length()==0)
64                         {
65                             addErrorDetails(result, compName);
66                             result.failed(smh.getLocalString(getClass().getName()+".failed",
67                                     "FAILED [AS-EJB bean-cache] : cache-idle-timeout-in-seconds cannot be empty. It should be between 0 and {0}",
68                                     new Object JavaDoc[]{new Long JavaDoc(Long.MAX_VALUE)}));
69                         }else
70                         {
71                             long value = new Integer JavaDoc(idleTimeout).longValue();
72                             if(value < 0 || value > Long.MAX_VALUE)
73                             {
74                                 addErrorDetails(result, compName);
75                                 result.failed(smh.getLocalString(getClass().getName()+".failed1",
76                                     "FAILED [AS-EJB bean-cache] : cache-idle-timeout-in-seconds cannot be {0}. It should be between 0 and {1}",
77                                     new Object JavaDoc[]{new Long JavaDoc(value),new Long JavaDoc(Long.MAX_VALUE)}));
78                             }else
79                             {
80                                 addGoodDetails(result, compName);
81                                 result.passed(smh.getLocalString(getClass().getName()+".passed",
82                                     "PASSED [AS-EJB bean-cache] : cache-idle-timeout-in-seconds is [{0}]",
83                                     new Object JavaDoc[]{new Long JavaDoc(value)}));
84                             }
85                         }
86                     }else //idle-timeout-in-seconds not defined
87
{
88                         addNaDetails(result, compName);
89                         result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
90                                 "NOT APPLICABLE [AS-EJB bean-cache] : cache-idle-timeout-in-seconds element not defined"));
91                     }
92                 }catch(NumberFormatException JavaDoc nfex)
93                 {
94                      Verifier.debug(nfex);
95                     addErrorDetails(result, compName);
96                     result.failed(smh.getLocalString(getClass().getName()+".failed2",
97                             "FAILED [AS-EJB bean-cache] : [{0}] is not a valid Long number",new Object JavaDoc[]{idleTimeout}));
98
99                 }
100             }else //bean-cache element not defined
101
{
102                 addNaDetails(result, compName);
103                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
104                    "NOT APPLICABLE [AS-EJB] : bean-cache element not defined"));
105              }
106
107     }catch(Exception JavaDoc ex){
108             addErrorDetails(result, compName);
109             result.addErrorDetails(smh.getLocalString
110                 (getClass().getName() + ".notRun",
111                     "NOT RUN [AS-EJB] : Could not create an descriptor object"));
112         }
113         return result;
114     }
115 }
116
Popular Tags