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

JvmOptionsTest

public class JvmOptionsTest extends Object

Fields Summary
private static com.sun.enterprise.util.LocalStringManagerImpl
smh
private static final JvmOptionsTest
instance
Constructors Summary
private JvmOptionsTest()


      
    
Methods Summary
private voidcheckBeginWithDash(java.util.Set options)

        List invalidOptions = new ArrayList();
        Iterator it = options.iterator();
        while (it.hasNext()) {
            String option = it.next().toString();
            if (!option.startsWith("-") &&
                !(option.startsWith("\"-") && option.endsWith("\""))  ) 
            {
                invalidOptions.add(option);
            }
        }
        if (invalidOptions.size() > 0) {
            throw new InvalidJvmOptionsException(
                getInvalidJvmOptionMsg(invalidOptions.toString()));
        }
    
private voidcheckForNullOptions(java.lang.String[] options)

        if (null == options) {
            throw new InvalidJvmOptionsException(getNullJvmOptionMsg());
        }
        for (int i = 0; i < options.length; i++) {
            if (null == options[i]) {
                throw new InvalidJvmOptionsException(getNullJvmOptionMsg());
            }
        }
    
private voidcheckQuotes(java.util.Set options)

        List invalidOptions = new ArrayList();
        final Iterator it = options.iterator();
        while (it.hasNext()) {
            String option = it.next().toString();
            if (!checkQuotes(option)) {
                invalidOptions.add(option);
            }
        }
        if (invalidOptions.size() > 0) {
            throw new InvalidJvmOptionsException(
                getIncorrectQuotesMsg(invalidOptions.toString()));
        }
    
private booleancheckQuotes(java.lang.String option)

        int length      = option.length();
        int numQuotes   = 0;
        int index       = 0;

        while (index < length && 
                (index = option.indexOf('\"", index)) != -1)
        {
            numQuotes++;
            index++;
        }
        return ((numQuotes % 2) == 0);
    
private java.lang.StringgetIncorrectQuotesMsg(java.lang.String invalidOptions)

        return smh.getLocalString(getClass().getName() + ".incorrectQuotesInJvmOption", 
            "{0} - Invalid Jvm option. Check quotes", 
            new Object[] {invalidOptions});
    
private java.lang.StringgetInvalidJvmOptionMsg(java.lang.String invalidOptions)

        return smh.getLocalString(getClass().getName() + ".invalidJvmOption", 
            "{0} - Invalid Jvm option. Option must begin with -", 
            new Object[] {invalidOptions});
    
private java.lang.StringgetNullJvmOptionMsg()

        return smh.getLocalString(getClass().getName() + ".nullJvmOption", 
            "Null Jvm option", new Object[0]);
    
private java.util.SettokenizeJvmOptions(java.lang.String[] options)

        final Set optionsSet = new LinkedHashSet();
        final String DELIM = " \t";
        for (int i = 0; i < options.length; i++) {
            QuotedStringTokenizer strTok = new QuotedStringTokenizer(
                                                options[i], DELIM);
            while (strTok.hasMoreTokens()) {
                optionsSet.add(strTok.nextToken());
            }
        }
        return Collections.unmodifiableSet(optionsSet);
    
public static voidvalidateJvmOptions(java.lang.String[] jvmOptions, com.sun.enterprise.config.serverbeans.validation.Result result)

        try {
            instance.checkForNullOptions(jvmOptions);
            Set optionsSet = instance.tokenizeJvmOptions(jvmOptions);
            instance.checkBeginWithDash(optionsSet);
            instance.checkQuotes(optionsSet);
        }
        catch (Exception e) {
            result.failed(e.getMessage());
        }