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

JmsHostTest

public class JmsHostTest extends com.sun.enterprise.config.serverbeans.validation.GenericValidator
Custom Test for JMS Host Test which calls the Generic Validation before performing custom tests
author
Sreenivas Munnangi
version
1.0

Fields Summary
private static final char[]
illegalChars
Constructors Summary
public JmsHostTest(com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor desc)


        
        super(desc);
    
Methods Summary
private final com.sun.enterprise.config.serverbeans.JmsHostgetJmsHost(com.sun.enterprise.config.ConfigContextEvent cce)

        return (JmsHost) cce.getValidationTarget();
    
private booleanhasIllegalChar(char[] inputCharArr, char[] illegalCharArr)


        int inputCharArrLen = inputCharArr.length;
        int illegalCharArrLen = illegalCharArr.length;

        for (int i=0; i<illegalCharArrLen; i++) {
            for (int j=0; j<inputCharArrLen; j++) {
                if (inputCharArr[j] == illegalCharArr[i]) {
                    return true;
                }
            }
        }

        return false;
    
private final booleanisReferencedByParent(com.sun.enterprise.config.ConfigContextEvent cce)

        final JmsHost host = getJmsHost(cce);
        final JmsService parent = (JmsService) host.parent();
        return parent.getDefaultJmsHost() != null && parent.getDefaultJmsHost().equals(host.getName());
    
public com.sun.enterprise.config.serverbeans.validation.Resultvalidate(com.sun.enterprise.config.ConfigContextEvent cce)


        Result result = super.validate(cce);
        try {
            if (cce.getChoice().equals(StaticTest.DELETE)){
                if (isReferencedByParent(cce)){
                    result.failed(
                        smh.getLocalString(
                            getClass().getName() + ".cannotDeleteReferencedJmsHost",
                            "Jms host (name={0}) can not be removed. It is referenced by its parent jms-service",
                            new Object[]{getJmsHost(cce).getName()}));
                }
            } else {
                if (cce.getName().equals(ServerTags.ADMIN_USER_NAME)) {
                    validateAdminUserName((String) cce.getObject(), result);
                } else if (cce.getName().equals(ServerTags.ADMIN_PASSWORD)) {
                    validateAdminUserPassword((String) cce.getObject(), result);
                } 
            }
        } catch(Exception e) {
            _logger.log(Level.FINE, "domainxmlverifier.exception", e);
        }
        return result;
    
private voidvalidateAdminUserName(java.lang.String name, com.sun.enterprise.config.serverbeans.validation.Result result)


        if ((name == null) || (name.equals("")) || (name.length() < 1)) {
            result.failed(smh.getLocalString(getClass().getName() +
                                             ".blankOrNullString",
                                             "Attribute {0} : cannot be null or blank",
                                             new Object[] {ServerTags.ADMIN_USER_NAME}));
            return;
        }

        if (hasIllegalChar(name.toCharArray(), illegalChars)) {
            result.failed(smh.getLocalString(getClass().getName() +
                                             ".stringHasIllegalChars", 
                                             "Attribute {0} cannot have any of illegal characters {1}",
                                             new Object[] {ServerTags.ADMIN_USER_NAME, new String(illegalChars)}));
        }
    
private voidvalidateAdminUserPassword(java.lang.String name, com.sun.enterprise.config.serverbeans.validation.Result result)


        if ((name == null) || (name.equals("")) || (name.length() < 1)) {
            result.failed(smh.getLocalString(getClass().getName() +
                                             ".blankOrNullString",
                                             "Attribute {0} : cannot be null or blank",
                                             new Object[] {ServerTags.ADMIN_PASSWORD}));
            return;
        }

        if (hasIllegalChar(name.toCharArray(), illegalChars)) {
            result.failed(smh.getLocalString(getClass().getName() +
                                             ".stringHasIllegalChars", 
                                             "Attribute {0} cannot have any of illegal characters {1}",
                                             new Object[] {ServerTags.ADMIN_PASSWORD, new String(illegalChars)}));
        }