1 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 ; 35 import java.util.logging.Level ; 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 []{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); boolean flag = false; 72 String 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 ) 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 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 []{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 []{StaticTest.CONFIG_TEMPLATE_NAME})); 107 108 } 109 } 110 111 } 112 113 114 | Popular Tags |