KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.config.ConfigContextEvent;
27 import com.sun.enterprise.config.ConfigException;
28 import com.sun.enterprise.config.serverbeans.Cluster;
29 import com.sun.enterprise.config.serverbeans.ServerTags;
30 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
31 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
32 import com.sun.enterprise.config.serverbeans.validation.Result;
33 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
34 import java.util.Set JavaDoc;
35 import java.util.logging.Level JavaDoc;
36
37
38 public class ClusterTest extends GenericValidator {
39     
40     public ClusterTest(ValidationDescriptor desc) {
41         super(desc);
42     }
43
44     void validateAdd(final ConfigContextEvent cce, final Result result) throws ConfigException{
45         checkNameNotDomain(cce, result);
46         checkConfigRefValidity(cce, result);
47     }
48
49     void validateUpdate(final ConfigContextEvent cce, final Result result) throws ConfigException{
50         checkNameNotDomain(cce, result);
51         preventInvalidConfigRef(cce, result);
52     }
53
54
55
56     void checkNameNotDomain(final ConfigContextEvent cce, final Result result) throws ConfigException{
57         final Cluster c = getCluster(cce);
58         if ("domain".equals(c.getName())){
59             result.failed(smh.getLocalString(getClass().getName() + ".illegalClusterName",
60                                              "Illegal Cluster Name: {0}", new Object JavaDoc[]{c.getName()}));
61         }
62     }
63     
64     private Cluster getCluster(final ConfigContextEvent cce) throws ConfigException{
65         return (Cluster) cce.getValidationTarget();
66     }
67     
68
69     public Result validate(ConfigContextEvent cce) {
70         Result result = super.validate(cce); // Before doing custom validation do basic validation
71
boolean flag = false;
72         String JavaDoc choice = cce.getChoice();
73         try {
74             if (choice.equals(StaticTest.UPDATE)){
75                 validateUpdate(cce, result);
76             } else if (choice.equals(StaticTest.ADD)){
77                 validateAdd(cce, result);
78             }
79         }
80         catch (ConfigException ce){
81             _logger.log(Level.WARNING, "domainxmlverifier.exception", ce);
82         }
83             
84         return result;
85     }
86
87     private final void preventInvalidConfigRef(final ConfigContextEvent cce, final Result result) throws ConfigException {
88         if (cce.getName().equals(ServerTags.CONFIG_REF)){
89             checkConfigRefValidity((String JavaDoc) cce.getObject(), result);
90         }
91     }
92     
93     private final void checkConfigRefValidity(final ConfigContextEvent cce, final Result result) throws ConfigException {
94         checkConfigRefValidity(getCluster(cce).getConfigRef(), result);
95     }
96     
97             
98     private void checkConfigRefValidity(final String JavaDoc config_ref, final Result result){
99         if (config_ref.equals(StaticTest.DAS_CONFIG_NAME)){
100             result.failed(smh.getLocalString(getClass().getName()+".cannotHaveDASasConfig",
101                                              "The configuration of the Domain Administration Server (named {0}) cannot be referenced by a cluster",
102                                              new Object JavaDoc[]{StaticTest.DAS_CONFIG_NAME}));
103         } else if (config_ref.equals(StaticTest.CONFIG_TEMPLATE_NAME)){
104             result.failed(smh.getLocalString(getClass().getName()+".cannotHaveTemplateConfig",
105                                              "The default configuration template (named {0}) cannot be referenced by a cluster",
106                                              new Object JavaDoc[]{StaticTest.CONFIG_TEMPLATE_NAME}));
107
108         }
109     }
110
111 }
112
113
114
Popular Tags