FileDocCategorySizeDatePackage
JvmOptionsHelper.javaAPI DocGlassfish v2 API13473Fri May 04 22:25:58 BST 2007com.sun.enterprise.admin.util

JvmOptionsHelper

public final class JvmOptionsHelper extends Object
A helper class to facilitate the add/delete/get jvm options.

Fields Summary
private final JvmOptionsElement
head
First in the chain of responsibility
Constructors Summary
public JvmOptionsHelper(String[] options)

       if (null == options) {
            throw new IllegalArgumentException();
        }
        if(options.length == 0) {
            head = new JvmOptionsElement("");
        } else {
            head = new JvmOptionsElement(options[0]);
        }
        JvmOptionsElement current = head;
        for (int i = 1; i < options.length; i++) {
            JvmOptionsElement next = new JvmOptionsElement(options[i]);
            current.setNext(next);
            current = next;
        }
    
Methods Summary
public java.lang.String[]addJvmOptions(java.lang.String[] options)
Adds the options to its current set. Omits options that already exist. Note :- This method depends on the exact String comparision of the options. Hence an option "a=b c=d" will be added even if individual options already exist.

param
options
return
Returns an array of options that could not be added. The array will be atleast of 0 length. An array of length > 0 indicates that some options haven't been added successfully.
throws
InvalidJvmOptionException If any option is invalid. For example, an option that does not start with '-'.
throws
IllegalArgumentException If options param is null.

       if (null == options)
       {
           throw new IllegalArgumentException();
       }
       final Set alreadyExist = new HashSet();
       JvmOptionsElement last = last();
       for (int i = 0; i < options.length; i++)
       {
           if (!head.hasOption(options[i]))
           {
               JvmOptionsElement x = new JvmOptionsElement(options[i]);
               last.setNext(x);
               last = x;
           }
           else
           {
               alreadyExist.add(options[i]);
           }
       }
       return toStringArray(alreadyExist);
    
public java.lang.String[]deleteJvmOptions(java.lang.String[] options)
Deletes the options from its current set.

param
options
return
Returns an array of options that could not be deleted. The array will be atleast of 0 length. An array of length > 0 indicates that some options haven't been deleted successfully.
throws
IllegalArgumentException If options param is null.

       if (null == options)
       {
           throw new IllegalArgumentException();
       }
       //The following tokenizes the options.
//       options = tokenize(options);
       final Set donotExist = new HashSet();
       for (int i = 0; i < options.length; i++)
       {
           if (!head.deleteJvmOption(options[i]))
           {
               donotExist.add(options[i]);
           }
       }
       return toStringArray(donotExist);
    
public java.lang.String[]getJvmOptions()
Returns the current set of Jvm options.

        Set s = new LinkedHashSet();
        JvmOptionsElement current = head;
        while (!JvmOptionsElement.isLast(current))
        {
            ArrayList options = current.getJvmOptions();
            if ((options != null) && (options.size() > 0))
            {
                s.addAll(options);
            }
            current = current.next();
        }
        return toStringArray(s);
    
public java.lang.String[]getJvmOptionsAsStoredInXml()
Returns the current set of Jvm options.

        Set s = new LinkedHashSet();
        JvmOptionsElement current = head;
        while (!JvmOptionsElement.isLast(current))
        {
            String options = current.getJvmOptionsAsStoredInXml();
            if ((options != null) && (options.length() > 0))
            {
                s.add(options);
            }
            current = current.next();
        }
        return toStringArray(s);
    
public com.sun.enterprise.admin.util.JvmOptionsElementlast()
Returns the last JvmOptionsElement in the chain of responsibility.

        JvmOptionsElement current = head;
        while (current.hasNext())
        {
            current = current.next();
        }
        return current;
    
public static java.lang.String[]toStringArray(java.util.Collection c)

        final String[] s = new String[c.size()];
        final Iterator it = c.iterator();
        int i = 0;
        while (it.hasNext())
        {
            s[i] = (String)it.next();
            i++;
        }
        return s;
    
private static java.lang.String[]tokenize(java.lang.String[] options)

        Set s = new LinkedHashSet();
        //4923404
        for (int i = 0; i < options.length; i++)
        {
            QuotedStringTokenizer strTok = new QuotedStringTokenizer(
                                                options[i], " \t");
            while (strTok.hasMoreTokens())
            {
                s.add(strTok.nextToken());
            }
        }
        //4923404
        return toStringArray(s);