KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime;
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the License). You may not use this file except in
7  * compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
11  * glassfish/bootstrap/legal/CDDLv1.0.txt.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * Header Notice in each file and include the License file
17  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
18  * If applicable, add the following below the CDDL Header,
19  * with the fields enclosed by brackets [] replaced by
20  * you own identifying information:
21  * "Portions Copyrighted [year] [name of copyright owner]"
22  *
23  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24  */

25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import java.util.*;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 import com.sun.enterprise.deployment.EjbEntityDescriptor;
36 import com.sun.enterprise.deployment.runtime.IASEjbExtraDescriptors;
37
38 /** ejb [0,n]
39  * refresh-period-in-seconds ? [String]
40  *
41  * The refresh-period-in-seconds denotes the rate at which a read-only-bean
42  * is refreshed.
43  * Is applicable only if it is a ROB.
44  * The value should be between 0 and MAX_INT
45  * @author
46  */

47 public class ASEjbRefreshPeriod extends EjbTest implements EjbCheck {
48
49     public Result check(EjbDescriptor descriptor)
50     {
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54         boolean oneWarning = false;
55         boolean oneFailed = false;
56         boolean isReadOnly = false;
57         String JavaDoc refreshPeriod = null;
58         try{
59             String JavaDoc s1 = ("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/refresh-period-in-seconds");
60             refreshPeriod = getXPathValue(s1);
61             
62             IASEjbExtraDescriptors iasEjbExtraDesc = descriptor.getIASEjbExtraDescriptors();
63             isReadOnly = iasEjbExtraDesc.isIsReadOnlyBean();
64             
65             if(refreshPeriod!=null)
66             {
67                 refreshPeriod=refreshPeriod.trim();
68                 if(refreshPeriod.length()==0)
69                 {
70                     oneFailed = true;
71                     result.addErrorDetails(smh.getLocalString
72                    ("tests.componentNameConstructor",
73                     "For [ {0} ]",
74                     new Object JavaDoc[] {compName.toString()}));
75                     result.failed(smh.getLocalString(getClass().getName()+".failed",
76                         "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and " + Integer.MAX_VALUE));
77                 }else{
78                     if(!(descriptor instanceof EjbEntityDescriptor
79                     && isReadOnly))
80                     {
81                             oneWarning = true;
82                             result.addWarningDetails(smh.getLocalString
83                                        ("tests.componentNameConstructor",
84                                         "For [ {0} ]",
85                                         new Object JavaDoc[] {compName.toString()}));
86                             result.warning(smh.getLocalString(getClass().getName()+".warning",
87                             "WARNING [AS-EJB ejb] : refresh-period-in-seconds should be defined for Read Only Beans."));
88                         return result;
89                     }
90                     try{
91                         int refValue = Integer.parseInt(refreshPeriod);
92                         if(refValue<0 || refValue>Integer.MAX_VALUE)
93                         {
94                             oneFailed = true;
95                             result.addErrorDetails(smh.getLocalString
96                    ("tests.componentNameConstructor",
97                     "For [ {0} ]",
98                     new Object JavaDoc[] {compName.toString()}));
99                             result.failed(smh.getLocalString(getClass().getName()+".failed1",
100                                 "FAILED [AS-EJB ejb] : refresh-period-in-seconds cannot be greater than " + Integer.MAX_VALUE + " or less than 0"));
101                         }
102                         else
103                             result.addGoodDetails(smh.getLocalString
104                                 ("tests.componentNameConstructor",
105                                 "For [ {0} ]",
106                                 new Object JavaDoc[] {compName.toString()}));
107                             result.passed(smh.getLocalString(getClass().getName()+".passed",
108                                 "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}",new Object JavaDoc[]{new Integer JavaDoc(refValue)}));
109                     }catch(NumberFormatException JavaDoc nfex){
110                         oneFailed = true;
111                         Verifier.debug(nfex);
112                         result.addErrorDetails(smh.getLocalString
113                    ("tests.componentNameConstructor",
114                     "For [ {0} ]",
115                     new Object JavaDoc[] {compName.toString()}));
116                         result.failed(smh.getLocalString(getClass().getName()+".failed",
117                             "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and " + Integer.MAX_VALUE ));
118                     }
119                 }
120             }else {
121                 if((descriptor instanceof EjbEntityDescriptor)
122                         && (isReadOnly))
123                 {
124                     oneWarning = true;
125                     result.addWarningDetails(smh.getLocalString
126                                        ("tests.componentNameConstructor",
127                                         "For [ {0} ]",
128                                         new Object JavaDoc[] {compName.toString()}));
129                     result.warning(smh.getLocalString(getClass().getName()+".warning",
130                     "WARNING [AS-EJB ejb] : refresh-period-in-seconds should be defined for Read Only Beans"));
131                 }
132                 else
133                 {
134                     result.addNaDetails(smh.getLocalString
135                 ("tests.componentNameConstructor",
136                  "For [ {0} ]",
137                  new Object JavaDoc[] {compName.toString()}));
138                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
139                         "NOT APPLICABLE [AS-EJB ejb] : refresh-period-in-seconds is not defined"));
140                 }
141             }
142             if(oneWarning)
143                 result.setStatus(Result.WARNING);
144             if(oneFailed)
145                 result.setStatus(Result.FAILED);
146         }catch(Exception JavaDoc ex){
147             result.addErrorDetails(smh.getLocalString
148                    ("tests.componentNameConstructor",
149                     "For [ {0} ]",
150                     new Object JavaDoc[] {compName.toString()}));
151             result.failed(smh.getLocalString(getClass().getName()+".notRun",
152                 "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
153         }
154         return result;
155     }
156     }
157
Popular Tags