FileDocCategorySizeDatePackage
DomainConfigValidator.javaAPI DocGlassfish v2 API7723Fri May 04 22:24:30 BST 2007com.sun.enterprise.admin.servermgmt

DomainConfigValidator

public abstract class DomainConfigValidator extends Validator
This class validates the domain config Map object. It does this by invoking the validator of each required entry. Subclasses must specify the required set of DomainConfigEntryInfo objects.

Fields Summary
private static final com.sun.enterprise.util.i18n.StringManager
strMgr
i18n strings manager object
private DomainConfigEntryInfo[]
entries
An array of DomainConfigEntryInfo objects that must be initialized by subclasses.
Constructors Summary
protected DomainConfigValidator(DomainConfigEntryInfo[] entries)
Constructs a new DomainConfigValidator object.

param
entries An array of required DomainConfigEntryInfo objects. Must be supplied by subclasses.

        super(strMgr.getString("domainConfig"), DomainConfig.class);
        this.entries = entries;
    
protected DomainConfigValidator(String name, Class type, DomainConfigEntryInfo[] entries)

        super(name, type);
        this.entries = entries;
    
Methods Summary
private com.sun.enterprise.admin.servermgmt.DomainConfigValidator$DomainConfigEntryInfoget(java.lang.Object key)

return
Returns the DomainConfigEntryInfo corresponding to the key. Returns null if no DomainConfigEntryInfo exists in the entries for the given key.

        for (int i = 0; i < entries.length; i++)
        {
            if (entries[i].key.equals(key)) { return entries[i]; }
        }
        return null;
    
public java.lang.StringgetDataType(java.lang.Object key)

return
Returns the accepted datatype for the key. The returned value is the fully qualified class name of the datatype. If the key is invalid or doesnot belong to the valid domain config key set, "" is returned.

        final DomainConfigEntryInfo info = get(key);
        if (info != null)
        {
            return info.dataType;
        }
        return "";
    
public booleanisKeyAllowed(java.lang.Object key)

param
key
return
Returns true if the key is valid and required.

        return (get(key) != null);
    
protected abstract booleanisValidate(java.lang.String name, java.lang.Object domainConfig)
This method allows subclasses to say if an entry should be validated at all. This is an attempt to add some flexibility to the otherwise static validation. (Eg:- If we donot want to validate the ports during domain creation)

public booleanisValueValid(java.lang.Object key, java.lang.Object value)

param
key
param
value
return
Returns true if the key is valid and required and the value for that key is valid.

        boolean isValid = false;
        final DomainConfigEntryInfo info = get(key);
        if (info != null)
        {
            if (info.hasValidator())
            {
                try
                {
                    info.validator.validate(value);
                }
                catch (InvalidConfigException idce)
                {
                    isValid = false;
                }
            }
            else
            {
                isValid = true;
            }
        }
        return isValid;
    
public voidvalidate(java.lang.Object domainConfig)
Validates the domainConfig. For each required domain config entry in the entries, gets the value from the domainConfig object and invokes the validator of that entry. Skips the validation of an entry if no validator is specified for that entry.

param
domainConfig The domainConfig object that needs to be validated. A domainConfig object is valid if it
    is of type DomainConfig contains the required set of DomainConfig keys the value for each required key is valid.
throws
InvalidConfigException If invalid domainConfig is supplied.

        super.validate(domainConfig);
        for (int i = 0; i < entries.length; i++)
        {
            if (isValidate(entries[i].key, domainConfig))
            {
                final Object value = ((HashMap)domainConfig).get(entries[i].key);
                if (entries[i].hasValidator())
                {
                    entries[i].validator.validate(value);
                }
            }
        }