FileDocCategorySizeDatePackage
VirtualServerTest.javaAPI DocGlassfish v2 API8640Wed Jul 25 23:56:22 BST 2007com.sun.enterprise.config.serverbeans.validation.tests

VirtualServerTest

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

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

        super(desc);
    
Methods Summary
private final voidcheckAllRelatedHttpListenersAreDisabled(com.sun.enterprise.config.serverbeans.VirtualServer vs, com.sun.enterprise.config.serverbeans.validation.Result result)

        for (final Iterator it = getReferers(vs).iterator(); it.hasNext(); ){
            final HttpListener l = (HttpListener) it.next();
            if (l.isEnabled()){
                result.failed(smh.getLocalString(getClass().getName()+".listenerEnabled",
                                                "Cannot disable the virtual server \"{0}\" because this is the default virtual server for the http listener \"{1}\".",
                                                new Object[]{vs.getId(), l.getId()}));
            }
        }
    
private java.util.SetgetPeerListeners(com.sun.enterprise.config.serverbeans.VirtualServer vs)

        final HttpService hs = (HttpService) vs.parent();
        if (null == hs) { return Collections.EMPTY_SET; }

        final Set result = new HashSet();
        result.addAll(Arrays.asList(hs.getHttpListener()));
        return result;
    
private java.util.SetgetReferers(com.sun.enterprise.config.serverbeans.VirtualServer vs)

        final Set listeners = getPeerListeners(vs);
        if (listeners.isEmpty()) { return Collections.EMPTY_SET; }

        final Set result = new HashSet();
        for (final Iterator it = listeners.iterator(); it.hasNext(); ){
            final HttpListener l = (HttpListener) it.next();
            if (l.getDefaultVirtualServer().equals(vs.getId())){
                result.add(l);
            }
        }
        return result;
    
private final com.sun.enterprise.config.serverbeans.VirtualServergetVirtualServer(com.sun.enterprise.config.ConfigContextEvent cce)

        return (VirtualServer) cce.getValidationTarget();
    
public java.util.Vectortokens(java.lang.String value)

        StringTokenizer token = new StringTokenizer(value,",");
        Vector test = new Vector();
        while(token.hasMoreTokens())
            test.add(token.nextToken());
        return test;
    
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
        try{
            if(cce.getChoice().equals(StaticTest.ADD) || cce.getChoice().equals(StaticTest.VALIDATE)) {
                ConfigContext context = cce.getConfigContext();
                VirtualServer virtual =  (VirtualServer) cce.getValidationTarget();
           
                    // For an ADD operation the virtual server is being
                    // added to an http-service, which is the
                    // configcontextevents class object. Therefore the config is
                    // the parent of the class object:
                final Config config = (Config) ((HttpService) cce.getClassObject()).parent();
                validateAttribute(ServerTags.HTTP_LISTENERS,virtual.getHttpListeners(),config, result);
                //validateAttribute(ServerTags.HOSTS,virtual.getHosts(),config, result);
            } else if(cce.getChoice().equals("UPDATE")) {
                    // For an UPDATE operation the class object is the
                    // virtual server whose attributes are being
                    // updated. Therefore the config is the parent of the
                    // parent of this object:
                final VirtualServer vs = (VirtualServer) cce.getClassObject();
                final Config config = (Config) vs.parent().parent();
                String name = cce.getName();
                String value = (String) cce.getObject();
                validateAttribute(name,value,config, result);
                    // IF the state is being turned off then this can only
                    // occur if there's no http-listener which has this
                    // virtual server as a default and which is enabled.
                if (name.equals(ServerTags.STATE) && !value.equals("on")){
                    checkAllRelatedHttpListenersAreDisabled(vs, result);
                }
            }
        }
        
        catch (final ConfigException ce){
            _logger.log(Level.WARNING, "domainxmlverifier.exception", ce);
        }


        return result;
    
public voidvalidateAttribute(java.lang.String name, java.lang.String value, com.sun.enterprise.config.serverbeans.Config config, com.sun.enterprise.config.serverbeans.validation.Result result)

        
        if(value== null || value.equals(""))
            return;
                  
        if(name.equals(ServerTags.HOSTS)) {
            Vector address = tokens(value);
            for(int i=0;i<address.size();i++) {
                try {
                    StaticTest.checkIPAddress((String) address.get(i));
                } catch(IllegalArgumentException e) {
                    result.failed(smh.getLocalString(getClass().getName() + ".addressNotAscii",
                                                             "Attribute({0}={1}) :  Invalid address syntax - {1}",
                                                             new Object[]{name, (String)address.get(i)}));
                } catch(Exception u) {
                    result.failed(smh.getLocalString(getClass().getName() + ".invalidHostsAddress",
                          "Invalid value for virtual server's ''{0}'' attribute. ''{1}'' is incorrect network address. ", 
                          new Object[]{name,(String)address.get(i)}));
                }
            }
        }