FileDocCategorySizeDatePackage
DASLauncherInfo.javaAPI DocGlassfish v2 API11188Fri May 04 22:24:30 BST 2007com.sun.enterprise.admin.servermgmt.launch

DASLauncherInfo

public class DASLauncherInfo extends Object
author
bnevins

Fields Summary
public boolean
verbose
public boolean
debug
public File
domainsDir
public File
domainDir
public String
domainName
public File
installDir
public File
configDir
public String
instanceName
public String
xmlProcessName
private String[]
args
private File
domainsDirParent
private boolean
valid
public static final String
SCRIPT_PATH
public static final String
INSTALL_DIR
public static final String
DOMAIN_DIR
Constructors Summary
public DASLauncherInfo()

    
public DASLauncherInfo(String Args)

        args = Args;
        processArgs();
    
Methods Summary
private voidextractInfoFromDomainDir()

        if(!safeIsDir(domainDir))
            return;
        
        domainsDir = safeGetCanonicalFile(domainDir.getParentFile());

        if(!safeIsDir(domainsDir))
            return;

        domainName = domainDir.getName();
        domainsDirParent = safeGetCanonicalFile(domainsDir.getParentFile());
    
public static voidmain(java.lang.String[] Args)

    ///////////////////////////////////////////////////////////////////////////
    
        
    
        new DASLauncherInfo(Args);
    
private static booleanok(java.lang.String s)

        return s != null && s.length() > 0;
    
private static booleanok(java.io.File f)

        return f != null && f.exists();
    
private voidparseDomainDir()

        // example path: c:/ee/domains/domain1
        // we need to pick out:
        // (1) c:/ee/domains
        // (2) domain1

        for(String s : args)
        {
            if(!s.startsWith(DOMAIN_DIR))
                continue;
            
            String path = s.substring(DOMAIN_DIR.length());
            domainDir = safeGetCanonicalFile(new File(path));
            extractInfoFromDomainDir();
        }
    
private voidparseInstallDir()

        // first look for an explicit argument...
        
        for(String s : args)
        {
            if(!s.startsWith(INSTALL_DIR))
                continue;

            String path = s.substring(INSTALL_DIR.length());
            
            if(!ok(path))
                break;
            
            installDir = safeGetCanonicalFile(new File(path));
            
            if(!safeIsDir(installDir))
                break;
        }
        
        if(installDir != null)
            return;
        
        // In desperation, figure it out from the script path
        if(domainsDirParent != null)
            installDir = domainsDirParent;
    
private voidparseOtherStuff()

        for(String s : args)
        {
            String arg = s.toLowerCase();
            
            if(arg.equals("verbose"))
                verbose = true;
            
            if(arg.equals("debug"))
                debug = true;
        }
    
private voidparseScriptPath()

        // example path: c:/ee/domains/domain1/bin/startdas.bat
        // we need to pick out:
        // (1) c:/ee/domains
        // (2) domain1

        for(String s : args)
        {
            if(!s.startsWith(SCRIPT_PATH))
                continue;
            
            String path = s.substring(SCRIPT_PATH.length());
            
            if(!ok(path))
                break;
            
            File script = new File(path);
            
            if(!ok(script))
                break;
            
            File bindir = script.getParentFile();
            
            if(!safeIsDir(bindir))
                break;
            
            domainDir = safeGetCanonicalFile(bindir.getParentFile());
            extractInfoFromDomainDir();
        }
    
private voidprocessArgs()

        parseScriptPath();
        parseDomainDir();
        parseInstallDir();
        parseOtherStuff();
    
private static java.io.FilesafeGetCanonicalFile(java.io.File f)

        if(f == null || !f.exists())
            return null;
        
        try
        {
            return f.getCanonicalFile();
        }
        catch(IOException ioe)
        {
            return f.getAbsoluteFile();
        }
    
private static booleansafeIsDir(java.io.File f)

        return f != null && f.exists() && f.isDirectory();
    
voidsetSystemProps()

        if(!valid)
            throw new ASLauncherException("Internal state is invalid");
        
        System.setProperty(SystemPropertyConstants.CONFIG_ROOT_PROPERTY,     configDir.getPath());
        System.setProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY,    installDir.getPath());
        System.setProperty(SystemPropertyConstants.SERVER_NAME,              instanceName);
        System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,   domainDir.getPath());
        System.setProperty(LaunchConstants.PROCESS_NAME_PROP,                xmlProcessName);
        System.setProperty("domain.name",                                    domainName);
    
public java.lang.StringtoString()

        StringBuilder sb = new StringBuilder();
        sb.append("verbose=" + verbose + '\n");
        sb.append("debug=" + debug + '\n");
        sb.append("domainsDir=" + domainsDir + '\n");
        sb.append("domainName=" + domainName + '\n");
        sb.append("installDir=" + installDir + '\n");
        sb.append("domainDir=" + domainDir + '\n");
        sb.append("configDir=" + configDir + '\n");
        sb.append("instanceName=" + instanceName + '\n");
        sb.append("xmlProcessName=" + xmlProcessName + '\n");
        return sb.toString();
    
public voidvalidate()

        String message = "";
        
        installDir  = safeGetCanonicalFile(installDir);
        domainsDir = safeGetCanonicalFile(domainsDir);       
        domainDir = safeGetCanonicalFile(domainDir);       
        configDir = safeGetCanonicalFile(configDir);       

        if(!safeIsDir(installDir))
            message += "Bad install dir: " + installDir  + "\n";
        
        if(!safeIsDir(domainsDir))
            message += "Bad domains dir: " + domainsDir + "\n";
        
        if(!safeIsDir(configDir) && safeIsDir(installDir))
        {
            // guess
            configDir = safeGetCanonicalFile(new File(installDir, "config"));
        }

        if(!safeIsDir(configDir))
            message += "Bad config dir: " + configDir + "\n";
        
        if(!safeIsDir(domainDir) && safeIsDir(domainsDir) && ok(domainName))
        {
            // calculate it...
            domainDir = safeGetCanonicalFile(new File(domainsDir, domainName));
        }

        if(!safeIsDir(domainDir))
            message += "Bad domain dir: " + domainDir + "\n";
        
        if(!ok(domainName))
            message += "Missing domain name\n";

        if(!ok(instanceName))
            message += "No instance name\n";
        
        if(!safeIsDir(domainDir))
            message += "Bad domain dir: " + domainDir + "\n";
        
        if(!ok(xmlProcessName))
            message += "Bad process name: " + xmlProcessName + "\n";
        
        if(message.length() > 0)
            throw new ASLauncherException(message);
        
        valid = true;