KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > tests > ManagementRuleTest


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 package com.sun.enterprise.config.serverbeans.validation.tests;
23
24 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
25 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
26 import com.sun.enterprise.config.serverbeans.validation.ValidationContext;
27 import com.sun.enterprise.config.serverbeans.validation.AttrType;
28 import com.sun.enterprise.config.serverbeans.validation.AttrString;
29 import com.sun.enterprise.config.serverbeans.validation.Result;
30
31 import com.sun.enterprise.config.serverbeans.J2eeApplication;
32
33 import com.sun.enterprise.config.ConfigBean;
34 import com.sun.enterprise.config.ConfigContext;
35 import com.sun.enterprise.config.ConfigContextEvent;
36 import com.sun.enterprise.config.ConfigException;
37 import com.sun.enterprise.config.serverbeans.ManagementRule;
38 import com.sun.enterprise.config.serverbeans.Event;
39 import java.util.logging.Level JavaDoc;
40 import java.util.Arrays JavaDoc;
41 import java.util.List JavaDoc;
42
43 public class ManagementRuleTest extends GenericValidator {
44     
45     public ManagementRuleTest(ValidationDescriptor desc) {
46         super(desc);
47     }
48     
49     final static List JavaDoc EVENT_TYPES=
50          Arrays.asList("log","timer","trace","monitor","cluster", "lifecycle","notification");
51     final static List JavaDoc LOG_LEVELS=
52          Arrays.asList("FINEST","FINER","FINE","CONFIG","INFO","WARNING","SEVERE","OFF");
53     
54     public void validateElement(ValidationContext valCtx)
55     {
56          super.validateElement(valCtx);
57          
58          // this is temporaty code which should be removed after
59
// "deep" childs validation will be implemented for add/set operations
60
if( (valCtx.isADD() || valCtx.isSET()) &&
61              valCtx.value instanceof ManagementRule)
62          {
63              try {
64                 Event event = ((ManagementRule)valCtx.value).getEvent();
65                 //eventtypes
66
if(!EVENT_TYPES.contains(event.getType()))
67                     valCtx.result.failed(smh.getLocalString(getClass().getName(),
68                             valCtx.smh.getLocalString(getClass().getName() + ".wrongEventType",
69                 "Value {0} is not allowed for Event type", new Object JavaDoc[] {event.getType()})));
70                 //log-levels
71
if(!LOG_LEVELS.contains(event.getLevel()))
72                     valCtx.result.failed(smh.getLocalString(getClass().getName(),
73                             valCtx.smh.getLocalString(getClass().getName() + ".wrongEventLevel",
74                 "Value {0} is not allowed for Event log level", new Object JavaDoc[] {event.getLevel()})));
75              } catch (Exception JavaDoc e) {}
76              
77          }
78     }
79     
80
81 }
82
Popular Tags