KickJava   Java API By Example, From Geeks To Geeks.

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


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

31
32 package com.sun.enterprise.admin.verifier.tests;
33
34 /* Test case to check the validity of Lifecycle module fields
35  * Author : srini@sun.com
36  */

37
38 import java.net.*;
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.ConfigException;
48 import com.sun.enterprise.config.serverbeans.*;
49 import com.sun.enterprise.config.ConfigContextEvent;
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
59 public class LifecycleModuleTest extends ServerXmlTest implements ServerCheck {
60     // Logging
61
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
62     
63     public LifecycleModuleTest() {
64     }
65  
66     // check method invoked by the command line verifier
67
public Result check(ConfigContext context) {
68                 Result result;
69                 result = super.getInitializedResult();
70                 // 8.0 XML Verifier
71
/*try {
72                     Server server = (Server)context.getRootConfigBean();
73                     Applications app = server.getApplications();
74                     LifecycleModule[] life = app.getLifecycleModule();
75                     String loadOrder=null;
76                     for(int i=0;i<life.length;i++){
77                         try {
78                            loadOrder=life[i].getLoadOrder();
79                            if(loadOrder!=null) {
80                                 // Bug 4711204
81                                 if(Integer.parseInt(loadOrder) < 0)
82                                     result.failed("Load Order Must be positive number");
83                            }
84                         }
85                         catch(NumberFormatException e) {
86                            result.failed("Load Order " + loadOrder + " for LifeCycleModule " + life[i].getName() + " : must be integer value : Failed" );
87                         }
88                     }
89                     result.passed("Test Passed : ");
90                 }
91                 catch(Exception ex){
92                     //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
93                     //result.failed("Test Failed **** ");
94                     _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
95                     result.failed("Exception : " + ex.getMessage());
96                     //</addition>
97                 }*/

98                 return result;
99     }
100     
101     // check method called from the admin GUI and iasadmin
102
public Result check(ConfigContextEvent ccce) {
103                 Object JavaDoc value = ccce.getObject();
104                 Result result = new Result();
105                 String JavaDoc beanName = ccce.getBeanName();
106                 if(beanName!=null) {
107                     String JavaDoc name = ccce.getName();
108                     return testSave(name,(String JavaDoc)value);
109                 }
110                 LifecycleModule life = (LifecycleModule)value;
111                 
112                 // check if Lifecycle Module name is valid object name Bug : 4698687 : start
113
String JavaDoc id = life.getName();
114                 if(StaticTest.checkObjectName(id, result))
115                     result.passed("Valid Object Name");
116                 else {
117                     result.failed("LifeCycle Module Name Invalid ");
118                     return result;
119                 }
120                 // End Bug : 4698687
121

122                 String JavaDoc loadOrder = life.getLoadOrder();
123                 
124                 try {
125                     //load-order is optional.
126
// If loadOrder is null, load-order does not exist. so we are okay.
127
if(loadOrder!=null) {
128                         // Bug : 4711204
129
if(Integer.parseInt(loadOrder) < 0) {
130                             result.failed("Load Order Must be positive number");
131                             return result;
132                         }
133                     }
134                     result.passed("Test passed ******");
135                 }
136                 catch(NumberFormatException JavaDoc e) {
137                     result.failed("Load Order for LifeCycleModule must be integer value");
138                 }
139                 return result;
140     }
141     
142     public Result testSave(String JavaDoc name, String JavaDoc value) {
143         Result result = new Result();
144             result.passed(" ***");
145         if(name.equals("load-order")){
146                 try {
147                     if(value!=null) {
148                         // Bug : 4711204
149
if(Integer.parseInt(value) < 0) {
150                             result.failed("Load Order Must be positive number");
151                             return result;
152                         }
153                     }
154                     result.passed("Test passed ******");
155                 }catch(NumberFormatException JavaDoc e) {
156                     result.failed("Load Order for LifeCycleModule must be integer value");
157                 }
158         }
159             return result;
160     }
161 }
162
Popular Tags