KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.ias;
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.tools.common.dd.ejb.SunEjbJar;
36 import com.sun.enterprise.tools.common.dd.ejb.Ejb;
37 import com.sun.enterprise.tools.common.dd.ResourceRef;
38 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal;
39 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
40 import com.sun.enterprise.deployment.EjbEntityDescriptor;
41
42 /** ejb [0,n]
43  * refresh-period-in-seconds ? [String]
44  *
45  * The refresh-period-in-seconds denotes the rate at which a read-only-bean
46  * is refreshed.
47  * Is applicable only if it is a ROB.
48  * The value should be between 0 and MAX_INT
49  * @author Irfan Ahmed
50  */

51 public class ASEjbRefreshPeriod extends EjbTest implements EjbCheck {
52
53     public Result check(EjbDescriptor descriptor)
54     {
55     Result result = getInitializedResult();
56     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
57
58         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
59         boolean oneWarning = false;
60         boolean oneFailed = false;
61         
62         if(ejbJar!=null)
63         {
64             Ejb testCase = getEjb(descriptor.getName(), ejbJar);
65             String JavaDoc refreshPeriod = testCase.getRefreshPeriodInSeconds();
66             
67             boolean isReadOnly = false;
68             String JavaDoc beanType = testCase.getIsReadOnlyBean();
69             if(beanType!=null && beanType.equals("true"))
70                 isReadOnly = true;
71             else
72                 isReadOnly=false;
73             
74             if(refreshPeriod!=null)
75             {
76                 if(refreshPeriod.length()==0)
77                 {
78                     oneFailed = true;
79                     result.failed(smh.getLocalString(getClass().getName()+".failed3",
80                         "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It shoud be between 0 and " + Integer.MAX_VALUE));
81                 }
82                 else
83                 {
84                     if(!(descriptor instanceof EjbEntityDescriptor
85                             && isReadOnly))
86                     {
87                         oneWarning = true;
88                         result.warning(smh.getLocalString(getClass().getName()+".warning",
89                         "WARNING [AS-EJB ejb] : refresh-period-in-seconds should be defined for Read Only Beans."));
90                     }
91                     try
92                     {
93                         int refValue = Integer.parseInt(refreshPeriod);
94                         if(refValue<0 || refValue>Integer.MAX_VALUE)
95                         {
96                             oneFailed = true;
97                             result.failed(smh.getLocalString(getClass().getName()+".failed4",
98                                 "FAILED [AS-EJB ejb] : refresh-period-in-seconds cannot be greater than " + Integer.MAX_VALUE +
99                                 " or less than 0"));
100                         }
101                         else
102                             result.passed(smh.getLocalString(getClass().getName()+".passed4",
103                                 "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}",new Object JavaDoc[]{new Integer JavaDoc(refValue)}));
104                     }
105                     catch(NumberFormatException JavaDoc nfex)
106                     {
107                         oneFailed = true;
108                         Verifier.debug(nfex);
109                         result.failed(smh.getLocalString(getClass().getName()+".failed5",
110                             "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and "+Integer.MAX_VALUE ));
111                     }
112                 }
113             }
114             else
115             {
116                 if((descriptor instanceof EjbEntityDescriptor)
117                         && (isReadOnly))
118                 {
119                     result.warning(smh.getLocalString(getClass().getName()+".warning1",
120                     "WARNING [AS-EJB ejb] : refresh-period-in-seconds should be defined for Read Only Beans"));
121                 }
122                 else
123                 {
124                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
125                         "NOT APPLICABLE [AS-EJB ejb] : refresh-period-in-seconds is not defined"));
126                 }
127             }
128             if(oneWarning)
129                 result.setStatus(Result.WARNING);
130             if(oneFailed)
131                 result.setStatus(Result.FAILED);
132         }
133         else
134         {
135             result.addErrorDetails(smh.getLocalString
136                  (getClass().getName() + ".notRun",
137                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
138         }
139         return result;
140     }
141 }
142
Popular Tags