FileDocCategorySizeDatePackage
ServerTest.javaAPI DocGlassfish v2 API9751Fri May 04 22:24:38 BST 2007com.sun.enterprise.config.serverbeans.validation.tests

ServerTest

public class ServerTest extends com.sun.enterprise.config.serverbeans.validation.GenericValidator
Custom Test for Server Element which calls the Generic Validation before performing custom tests
author
Srinivas Krishnan
version
2.0

Fields Summary
Constructors Summary
public ServerTest(com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor desc)

        super(desc);
    
Methods Summary
private final voidcheckConfigRefValidity(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        checkConfigRefValidity(getServer(cce).getConfigRef(), result);
    
private voidcheckConfigRefValidity(java.lang.String config_ref, com.sun.enterprise.config.serverbeans.validation.Result result)

        if (config_ref.equals(StaticTest.DAS_CONFIG_NAME)){
            result.failed(smh.getLocalString(getClass().getName()+".cannotHaveDASasConfig",
                                             "The configuration of the Domain Administration Server (named {0}) cannot be referenced by a server",
                                             new Object[]{StaticTest.DAS_CONFIG_NAME}));
        } else if (config_ref.equals(StaticTest.CONFIG_TEMPLATE_NAME)){
            result.failed(smh.getLocalString(getClass().getName()+".cannotHaveTemplateConfig",
                                             "The default configuration template (named {0}) cannot be referenced by a server",
                                             new Object[]{StaticTest.CONFIG_TEMPLATE_NAME}));

        }
    
private voidcheckNameNotAgent(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        final Server s = getServer(cce);
        if ("agent".equals(s.getName())){
            result.failed(smh.getLocalString(getClass().getName() + ".illegalServerName", 
                                             "Illegal Server Name {0}", new Object[]{s.getName()}));
        }
    
protected final java.lang.StringgetName(com.sun.enterprise.config.ConfigContextEvent cce)

        return getServer(cce).getName();

    
protected final java.util.SetgetReferers(com.sun.enterprise.config.ConfigContextEvent cce)

        return ServerBeansFactory.getReferers(getServer(cce), cce.getConfigContext());
    
private com.sun.enterprise.config.serverbeans.ServergetServer(com.sun.enterprise.config.ConfigContextEvent cce)

       return (Server) cce.getValidationTarget();
   
protected final booleanisReferenced(com.sun.enterprise.config.ConfigContextEvent cce)

        return ServerBeansFactory.isReferenced(getServer(cce), cce.getConfigContext());
    
private voidpreventChangeToConfigRef(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        if (cce.getName().equals(ServerTags.CONFIG_REF)){
            result.failed(smh.getLocalString(getClass().getName()+".noChangeToConfigRefInCluster",
                                             "Cannot change a config-ref when the instance is part of a cluster"));
        }
    
private voidpreventChangeToNodeAgentRef(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        if (cce.getName().equals(ServerTags.NODE_AGENT_REF)){
            result.failed(smh.getLocalString(getClass().getName()+".noChangeToNodeAgentRef",
                                             "Cannot change a node agent ref"));
        }
    
private final voidpreventInvalidConfigRef(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        if (cce.getName().equals(ServerTags.CONFIG_REF)){
            checkConfigRefValidity((String) cce.getObject(), result);
        }
    
public com.sun.enterprise.config.serverbeans.validation.Resultvalidate(com.sun.enterprise.config.ConfigContextEvent cce)

        Result result = super.validate(cce); // Before doing custom validation do basic validation
        boolean flag = false;
        String choice = cce.getChoice();
        try {
            if (choice.equals(StaticTest.SET)){
                validateSet(cce, result);
            } else if (choice.equals(StaticTest.UPDATE)){
                validateUpdate(cce, result);
            } else if (choice.equals(StaticTest.ADD)){
                validateAdd(cce, result);
            } else if(choice.equals(StaticTest.VALIDATE)) {
                Domain domain = (Domain)cce.getConfigContext().getRootConfigBean();
                Servers servers = domain.getServers();
                Server[] server = servers.getServer();
                    String svrName = server[0].getName();
                    if(!server[0].getName().equals("server")) 
                        result.failed(smh.getLocalString(getClass().getName() + ".invalidserverName", 
                                                         "Invalid Server Name {0}: Required 'server'", new Object[]{svrName}));
            }
            
            
            } catch(Exception e) {
                _logger.log(Level.FINE, "domainxmlverifier.exception", e);
            }
            return result;            
    
voidvalidateAdd(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        checkNameNotAgent(cce, result);
        checkConfigRefValidity(cce, result);
    
private voidvalidateAttributeChange(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        checkNameNotAgent(cce, result);
        preventChangeToNodeAgentRef(cce, result);
        if (this.isReferenced(cce)){
            preventChangeToConfigRef(cce, result);
        } else {
            preventInvalidConfigRef(cce, result);
        }
    
private voidvalidateSet(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        validateAttributeChange(cce, result);
    
voidvalidateUpdate(com.sun.enterprise.config.ConfigContextEvent cce, com.sun.enterprise.config.serverbeans.validation.Result result)

        validateAttributeChange(cce, result);