KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > verifier > tests > OrbTest


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.admin.verifier.tests;
25
26 /**
27  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
28  *
29  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
30  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
31  * All rights reserved.
32  */

33
34 import java.net.*;
35
36 /**
37  * Test Case to check the validity of Orb fields
38  */

39
40 // 8.0 XML Verifier
41
//import com.sun.enterprise.tools.verifier.Result;
42
import com.sun.enterprise.config.serverbeans.Server;
43 import com.sun.enterprise.config.serverbeans.*;
44 import com.sun.enterprise.config.serverbeans.Resources;
45 import com.sun.enterprise.config.serverbeans.Applications;
46 import com.sun.enterprise.config.ConfigContext;
47 import com.sun.enterprise.config.ConfigContextEvent;
48 import com.sun.enterprise.config.ConfigException;
49 import com.sun.enterprise.config.serverbeans.*;
50
51 import com.sun.enterprise.admin.verifier.*;
52 // Logging
53
import java.util.logging.Logger JavaDoc;
54 import java.util.logging.Level JavaDoc;
55 import com.sun.logging.LogDomains;
56
57
58 public class OrbTest extends ServerXmlTest implements ServerCheck {
59     // Logging
60
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
61     
62     public static final String JavaDoc ERROR_MSG = "Message Fragment Size can be only 1024, 2048, 4096, 8192, 16284 or 32568";
63     
64     public OrbTest() {
65     }
66
67     // check method called by command line verifier
68
public Result check(ConfigContext context)
69     {
70         Result result;
71         String JavaDoc msgFragmentSize = null;
72         
73         result = super.getInitializedResult();
74         // 8.0 XML Verifier
75
/*try {
76             Server server = (Server)context.getRootConfigBean();
77             IiopService service = server.getIiopService();
78             Orb orb = service.getOrb();
79             msgFragmentSize = orb.getMessageFragmentSize();
80             
81             int size = Integer.parseInt(msgFragmentSize);
82             
83             int kSize = size/1024;
84             int remainder = size%1024;
85             
86             if (remainder != 0) {
87                 result.failed(ERROR_MSG);
88             }
89             else if (!((kSize == 1) || (kSize == 2) || (kSize == 4) || (kSize == 8) || (kSize == 16) || (kSize == 32))) {
90                 result.failed(ERROR_MSG);
91             } else result.passed("Valid Message Fragment Size");
92             //Bug 4713369 <addition>
93             String steadyPool = orb.getSteadyThreadPoolSize();
94             try {
95                 if(Integer.parseInt(steadyPool) < 0)
96                     result.failed(smh.getLocalString(getClass().getName()+".steadyThreadNegative","Steady Thread Pool Size cannot be negative number"));
97             } catch(NumberFormatException e) {
98                     result.failed(smh.getLocalString(getClass().getName()+".steadyThreadInvalid","Steady Thread Pool Size : invalid number"));
99             }
100             String maxPool = orb.getMaxThreadPoolSize();
101             try {
102                 if(Integer.parseInt(maxPool) < 0)
103                     result.failed(smh.getLocalString(getClass().getName()+".maxPoolNegative","Max Thread Pool Size cannot be negative number"));
104             } catch(NumberFormatException e) {
105                 result.failed(smh.getLocalString(getClass().getName()+".maxPoolInvalid","Max Thread Pool Size : invalid number"));
106             }
107             String idleTimeout = orb.getIdleThreadTimeoutInSeconds();
108             try {
109                 if(Integer.parseInt(idleTimeout) < 0)
110                     result.failed(smh.getLocalString(getClass().getName()+".idleTimeoutNegative","Idle Thread Timeout cannot be negative number"));
111             } catch(NumberFormatException e) {
112                 result.failed(smh.getLocalString(getClass().getName()+".idleTimeoutInvalid","Idle Thread Timeout : invalid number"));
113             }
114             String conn = orb.getMaxConnections();
115             try {
116                 if(Integer.parseInt(conn) < 0)
117                     result.failed(smh.getLocalString(getClass().getName()+".maxConnNegative","Max Connections cannot be negative number"));
118             } catch(NumberFormatException e) {
119                 result.failed(smh.getLocalString(getClass().getName()+".maxConnInvalid","Max Connections : invalid number"));
120             }
121             //Bug 4713369 </addition>
122             
123         }
124         catch (NumberFormatException nfe) {
125             result.failed("Message Fragment Size - " + msgFragmentSize + " : Invalid");
126         }
127         catch(Exception ex) {
128             //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
129             /*ex.printStackTrace();
130             result.failed("Exception : " + ex.getMessage());*/

131             /*_logger.log(Level.FINE, "serverxmlverifier.exception", ex);
132             result.failed("Exception : " + ex.getMessage());
133             //</addition>
134         }*/

135         return result;
136     }
137     
138     // check method called by adminGUI and iasadmin
139
public Result check(ConfigContextEvent ccce) {
140         Result result = new Result();
141         result.passed("Passed **");
142         
143         Object JavaDoc value = ccce.getObject();
144         String JavaDoc choice = ccce.getChoice();
145         ConfigContext context = ccce.getConfigContext();
146         String JavaDoc beanName = ccce.getBeanName();
147         String JavaDoc msgFragmentSize = null;
148         
149         if(beanName!=null)
150                 return validateAttribute(ccce.getName(), ccce.getObject());
151         
152         return result;
153     }
154     
155     public Result validateAttribute(String JavaDoc name, Object JavaDoc value) {
156         Result result = new Result();
157         result.passed("Passed **");
158         String JavaDoc msgFragmentSize = null;
159         
160         if(name.equals(ServerTags.MESSAGE_FRAGMENT_SIZE)) {
161             try {
162                 msgFragmentSize = (String JavaDoc) value;
163                 int size = Integer.parseInt(msgFragmentSize);
164
165                 int kSize = size/1024;
166                 int remainder = size%1024;
167
168                 if (remainder != 0) {
169                     result.failed(ERROR_MSG);
170                 }
171                 else if (!((kSize == 1) || (kSize == 2) || (kSize == 4) || (kSize == 8) || (kSize == 16) || (kSize == 32))) {
172                     result.failed(ERROR_MSG);
173                 } else result.passed("Vaild Message Fragment Size");
174             } catch (NumberFormatException JavaDoc nfe) {
175                 result.failed("Message Fragment Size - " + msgFragmentSize + " : Invalid");
176             }
177         }
178         if(name.equals(ServerTags.MAX_CONNECTIONS)) {
179             try {
180                 if(value != null) {
181                     String JavaDoc conn = (String JavaDoc) value;
182                     if(Integer.parseInt(conn) < 0) {
183                         result.failed(smh.getLocalString(getClass().getName()+".maxConnNegative","Max Connections cannot be negative number"));
184                     }
185                     else
186                         result.passed("Passed ***");
187
188                 }
189             } catch(NumberFormatException JavaDoc e) {
190                 result.failed(smh.getLocalString(getClass().getName()+".maxConnInvalid","Max Connections : invalid number"));
191             }
192         }
193         // Bug 4713369 <addition>
194
return result;
195     }
196 }
197
Popular Tags