FileDocCategorySizeDatePackage
StaticTest.javaAPI DocGlassfish v2 API8916Thu Jul 26 22:17:42 BST 2007com.sun.enterprise.config.serverbeans.validation.tests

StaticTest

public class StaticTest extends Object
PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms. Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All rights reserved.

Fields Summary
public static final String
ADD
public static final String
DELETE
public static final String
UPDATE
public static final String
SET
public static final String
VALIDATE
public static boolean
fileCheck
public static boolean
classPathCheck
public static boolean
javaHomeCheck
private static Pattern
token_pattern
public static final String
DAS_CONFIG_NAME
Name of config reserved for DAS server
public static final String
CONFIG_TEMPLATE_NAME
Name of config used as a template
Constructors Summary
public StaticTest()

    
      
    
Methods Summary
private static booleanallAscii(java.lang.String s)

        //s is already checked for nullness.
       // leveraging the JDK 1.6 java.net.IDN.isASCII(String)
       boolean isASCII = true;
       for (int i = 0; i < s.length(); i++) {
           int c = s.charAt(i);
           if (c > 0x7F) {
               isASCII = false;
               break;
           }
       }
       return isASCII;
    
public static voidcheckIPAddress(java.lang.String addr)
Check the IP address syntax of the given address. If its invalid throw UnknownHostException. Ignore the address if its a token

        if (valueContainsTokenExpression (addr) || validSymbolicAddress(addr)) {
            return;
        /* Several problems because of DNS lookup. It's generally not a good idea
           to validate this. Hence, I am commenting the else clause out, km@dev.java.net, 07/25/2007
        /*} else {
            InetAddress.getByName(addr);            
        */}
        if (!allAscii(addr)) {
            throw new IllegalArgumentException("dummy message");
        }
    
public static com.sun.enterprise.config.serverbeans.ConfiggetConfig(com.sun.enterprise.config.ConfigContext context)

        Config mConfig=null;
        try {
            mConfig = ServerBeansFactory.getConfigBean(context);
        } catch(Exception e) {
        }
        return mConfig;
    
public static booleanisClassPathValid(java.lang.String path)

        boolean flag = true;
        StringTokenizer token = new StringTokenizer(path, File.pathSeparator);
        while(token.hasMoreTokens()) {
            File f = new File(token.nextToken());
            // User requires to validate the file path check for existence, else blank check
            if(classPathCheck) {
                if(!f.exists()) {
                    flag = false;
                    break;
                }
            }
        }
        return flag;
    
public static booleanisIdInList(java.lang.String list, java.lang.String poolId)

        return null != poolId && tokens(list+"").contains(poolId);
    
public static booleanisJavaHomeValid(java.lang.String path)
Verifies that the given path is a valid java-home path.

param
path The java-home path to be validated.
return
boolean true if valid false if invalid

        boolean flag = true;
        if(javaHomeCheck) {
            String jdkPath = path + File.separator + "bin" + File.separatorChar;
            if(System.getProperty("os.name").startsWith("Win")) {
                jdkPath = jdkPath + "java.exe";
            } else {
                jdkPath = jdkPath + "java";
            }
            StringTokenizer token = new StringTokenizer(path, File.pathSeparator);
            while(token.hasMoreTokens()) {
                File f = new File(token.nextToken());
                // User requires to validate the file path check for existence, else blank check
                if(!f.exists()) {
                    flag = false;
                    break;
                }
            }        
        }
        return flag;
    
public static booleanisOptionsValid(java.lang.String options)

        boolean flag = true;
        StringTokenizer token = new StringTokenizer(options," ");
        while(token.hasMoreTokens())  {
              if(!token.nextToken().startsWith("-")) {
                    flag = false;
                    break;
              }
        }
        return flag;
    
static voidsetJavaHomeCheck(boolean check)

        javaHomeCheck = true;
    
public static java.util.Vectortokens(java.lang.String value)

        StringTokenizer token = new StringTokenizer(value,",");
        Vector test = new Vector();
        while(token.hasMoreTokens()) 
                  test.add(token.nextToken().trim());
        return test;
    
private static booleanvalidSymbolicAddress(java.lang.String address)
Indicate if the given address is a symbolic address. i.e. is "any", "inaddr_any" or "localhost", in any case.

        return address.equalsIgnoreCase("ANY") ||
        address.equalsIgnoreCase("INADDR_ANY") || 
        address.equalsIgnoreCase("localhost");
    
public static booleanvalueContainsTokenExpression(java.lang.Object value)

        return null != value && value instanceof String && token_pattern.matcher((String) value).lookingAt();