KickJava   Java API By Example, From Geeks To Geeks.

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


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.config.serverbeans.validation.tests;
25
26 import java.util.Locale JavaDoc;
27 import java.util.logging.Level JavaDoc;
28
29 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
30 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
31 import com.sun.enterprise.config.serverbeans.validation.Result;
32 import com.sun.enterprise.config.serverbeans.Domain;
33 import com.sun.enterprise.config.serverbeans.Configs;
34 import com.sun.enterprise.config.serverbeans.Config;
35 import com.sun.enterprise.config.serverbeans.Servers;
36 import com.sun.enterprise.config.serverbeans.Server;
37 import com.sun.enterprise.config.serverbeans.ServerTags;
38 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest;
39
40 import com.sun.enterprise.config.ConfigBean;
41 import com.sun.enterprise.config.ConfigContextEvent;
42 import com.sun.enterprise.config.ConfigException;
43
44 /**
45     Custom Test for Domain Test which calls the Generic Validation before performing custom tests
46
47     @author Srinivas Krishnan
48     @version 2.0
49 */

50
51 public class DomainTest extends GenericValidator {
52     
53     public DomainTest(ValidationDescriptor desc) {
54         super(desc);
55     }
56     
57     public Result validate(ConfigContextEvent cce) {
58         Result result = super.validate(cce); // Before doing custom validation do basic validation
59

60         if(cce.getChoice().equals(StaticTest.ADD) || cce.getChoice().equals(StaticTest.VALIDATE)) {
61              Domain domain = (Domain)cce.getObject();
62 /*
63              String locale = domain.getLocale();
64              validateAttribute(ServerTags.LOCALE, locale, result);
65  */

66              // check for existence of elements groups, node-controllers, lb-configurations, load-balancers
67
// if(domain.getClusters() != null)
68
// result.failed(smh.getLocalString(getClass().getName() + ".invalidGroupsElement",
69
// "Clusters in domain not allowed in PE"));
70

71 // if(domain.getLbConfigs() != null)
72
// result.failed(smh.getLocalString(getClass().getName() + ".invalidLoadbalancersElement",
73
// "Loadbalancers in domain not allowed in PE"));
74
}
75         
76         if(cce.getChoice().equals(StaticTest.UPDATE))
77             validateAttribute(cce.getName(), (String JavaDoc)cce.getObject(), result);
78         
79         return result;
80     }
81     
82     public void validateAttribute(String JavaDoc name, String JavaDoc value, Result result) {
83
84         boolean checked = false;
85         if(value == null || value.equals(""))
86             return;
87         // commented because of performance problem - JDK problem Filed a bug 4908648
88
/*if(name.equals(ServerTags.LOCALE)) {
89             try {
90                 Locale[] mLocale = Locale.getAvailableLocales();
91                 for(int i=0;i<mLocale.length;i++) {
92                     if(value.equals(mLocale[i].toString())) {
93                         checked = true;
94                         break;
95                     }
96                 }
97             } catch(Exception e) {
98                 _logger.log(Level.FINE, "domainxmlverifier.error_getting_locale", e);
99             }
100
101             if(!checked)
102                 result.failed(smh.getLocalString(getClass().getName() + ".invalidLocale",
103                 "Attribute(locale= {0}) Invalid Locale : {0}", new Object[]{value}));
104         }*/

105         
106     }
107 }
108
Popular Tags