Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 /*
  * Created on : 04.2003
  * Created by : s3595
  */
 
 package at.spardat.xma.boot;
 
 import java.io.File;
 
 
The BootRuntime holds information about the client/machine environment for the boot runtime.

Author(s):
s3595 Chris Sch�fer (CGS)
Version:
$Id: BootRuntime.java 9782 2012-08-15 20:11:35Z hoenninger $
 
 public class BootRuntime {

   
this is a singleton
 
    private static BootRuntime instance_;

    
Boot Runtime Installation Directory
 
     private File installDirectory;

    
directory for cache, logging and other temporary data
 
     private File dataDirectory;

    
debug mode
 
     private Boolean debug;

    
file cache
 
     private FileCache fc;

    
app manager
 
     private AppManager appm_;

    
logger
 
     private Logger bootLogger;

    
configuration
 
     private Properties props;

    
handler for cleanup daemon tasks
 
     private Cleaner cleaner;
    

    
The BootRuntime constructor is private, because it is a singleton got only via initialize. the constructor initializes the process properties and the basic directories. the initialization of modules is seperated into 'initializeModules'.

Parameters:
baseDir xma base dir.
logger an existing logger [optional ].
 
     private BootRuntimeFile baseDirLogger l ) throws IOException {
                       
         setInstallDirectorybaseDir );   
 
          = readBootCfgProperties(baseDir,l);        
 
         /*
          * check data directory path information
          */
         String strDataDirectory = .getProperty. );
         //if the prop CFG_PROP_DATAPATH is marked with CFG_PROP_DATAPATH_USER_HOME_VALUE then "user.home" is used
         if(strDataDirectory !=null && strDataDirectory.startsWith(.)){
            strDataDirectory = System.getProperty"user.home" ) + strDataDirectory.substring(..length());
            .put.strDataDirectory);
            l.log."Datapath Property set to " + . + ", using: {0}"strDataDirectory );
        }
        //if the prop CFG_PROP_DATAPATH has no value then "user.dir" is used
        if(strDataDirectory==null || strDataDirectory.length() == 0 ){
            strDataDirectory = System.getProperty"user.dir" );
            .put.strDataDirectory);
            l.log."Datapath Property not found defaults to user.dir: {0}"strDataDirectory );
        }
         = new FilestrDataDirectory );
        if(!.exists()) {
            .mkdirs();
        }
        if(!.isDirectory()) {
            throw new RuntimeException("datapath '"+.getAbsolutePath()+"' is not a directory");
        }
        .setProperty.strDataDirectory );
        LogManager.getLogManager().setConfiguration();
        XMA_URI.setProperties();
        ifl != null )
            this. = l;
        else
            this. = Logger.getLogger("bootrt.bootRuntime"); //$NON-NLS-1$
        // tell apache.commons.logging to use the logger of XMABootRuntime
        LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",XmaBrtLogger.class.getName());
       String strDebug = (String).get. ); //$NON-NLS-1$
       LogLevel level = LogLevel.getLogLevelNamed(strDebug);
       // extended output to files and other tracing information only on high log levels
       if..equals(level) || ..equals(level)) {
           setDebug. );
           debugJavaParameter();
       } else {
           setDebug. );
       }
       // read caching properties from registry
       String useRegistry = .getProperty(.,"true");
       if(Boolean.valueOf(useRegistry).booleanValue()) {
           getProxySettings );
       }
    }
    
    
Read the BootCfg properties. First the default properties are read from a property file in the class path. In a second step these properties are overloaded from the bootruntime configuration file located in the base directory.

Parameters:
baseDir
l
Returns:
Throws:
java.io.IOException
    static Properties readBootCfgProperties(File baseDirLogger lthrows IOException {
        
        Properties props = new Properties();        
        
        /* load default properties from classpath */        
        InputStream is = BootRuntime.class.getClassLoader().getResourceAsStream("at/spardat/xma/boot/bootcfg.properties");
        props.load(is); //$NON-NLS-1$
        is.close();    
        
        /* load additional properties from runtime directory, if exist.
         * can replace default properties.
         */
        File configFile = new FilebaseDir. + "/" + . ); //$NON-NLS-1$
        ifconfigFile.exists()) {
            l.log."Using Configuration File: {0}"configFile.toString() );
            InputStream cfis = new FileInputStreamconfigFile );
            props.load(cfis);
            cfis.close();
        }        
        
        return props;        
    }    

    
initialize all modules for the boot runtime.

    private void initializeModules() throws IOException {
       HTTPTransport.init();
        = FileCache.initializethis );
        = AppManager.initialize );
       /*
        * create and start cleaner
        * !! Cleaner requires an initialized filecache !!
        */
           = new Cleaner(this);
          .startCleanup();
    }

    
debug java environment parameters.
    public void debugJavaParameter() {
        .log(."java system properties are:");
        Properties p = System.getProperties();
        Enumeration enumer = p.keys();
        while (enumer.hasMoreElements()) {
            String element = (String)enumer.nextElement();
            .log(."{0} : {1}"new Object[] {element,p.getProperty(element)} );
        }
    }

    

Returns:
the root working-directory for this machine
    public File getInstallDirectory() {
        return ;
    }

    

Returns:
AppManager the application manager instance
    public AppManager getAppManager() {
        return ;
    }

    

Parameters:
file the root working-directory for this machine
    private void setInstallDirectory(File fileBaseDir) {
        if( !fileBaseDir.exists())
          throw new IllegalArgumentException"Installation-Directory does not exist"); //$NON-NLS-1$
       this. = fileBaseDir;
    }

    

Returns:
BootRuntime runtimce instance
    public static BootRuntime getInstance() {
      if( == null)
        throw new IllegalStateException"runtime not initialized"); //$NON-NLS-1$
      else
        return ;
    }

    
initialize before usage

Parameters:
fileBaseDir base directory
Throws:
java.lang.IllegalArgumentException if file does not exist.
    public static synchronized BootRuntime initializeFile fileBaseDirLogger l )
      throws IOException {
         if( == null )
            = new BootRuntimefileBaseDirl );
           .initializeModules();
       return  ;
    }

    

Returns:
boolean true for debug mode
    public Boolean getDebug() {
        return ;
    }

    

Parameters:
debug true for debug
    private void setDebug(Boolean debugIn) {
        ifdebugIn == null)
           = .;
        else
           = debugIn;
    }

    

Returns:
configuration properties
    public Properties getConfigProperties() {
        return ;
    }

    

Parameters:
properties configuration information
    public void setConfigProperties(Properties properties) {
         = properties;
    }

    

Returns:
File data directory
    public File getDataDirectory() {
        return ;
    }
//    private void getProxySettings( Properties props ) {
//        try {
//
//        String strkey          = "HKEY_CURRENT_USER";
//        String strSub          = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
//        String strProxyServer  = "ProxyServer";
//        String strProxyEnable  = "ProxyEnable";
//
//        Natives natives = new Natives();
//
//        String strProxyValue = natives.getRegistryKey( strkey, strSub, strProxyServer );
//        if( strProxyValue != null ) {
//            int pos = strProxyValue.indexOf(':');
//            if( pos != -1 && pos < strProxyValue.length()) {
//                String valProxy = strProxyValue.substring(0, pos);
//                String valPort  = strProxyValue.substring(pos+1, strProxyValue.length() );
//
//                props.put( Statics.CFG_PROP_PROXYSERVER, valProxy );
//                props.put( Statics.CFG_PROP_PROXYPORT, valPort );
//            }
//        }
//        } catch( Exception e) {
//            System.out.println( "error on loading proxy values ");
//        }
//    }

    
Returns OS dependent proxy settings - only Windows is implemented yet.
    private void getProxySettingsProperties propsLogger l ) {
        String os = System.getProperty("os.name");
        if(os.trim().toLowerCase().indexOf("windows")==0){
            getWindowsProxySettings(propsl);
        }
    }

    
Format des Registy-Eintrags ProxyServer: wenn f�r alle Protokolle der selbe proxy: <host>[:port>] port ist optional z.b.: proxy-sd.s-mxs.net:8080 sonst: <protocol>=<host>[:<port>][;<protocoll>=<host>[:<port>][;...]] z.b.: ftp=proxy-sd.s-mxs.net:8080;gopher=proxy-sd.s-mxs.net:8080;http=proxy-sd.s-mxs.net:8080;https=proxy-sd.s-mxs.net:8080 wenn nur http proxy ausgef�llt ist und nicht f�r alle Protokolle der selbe proxy: http=proxy-sd.s-mxs.net:8080
    private void getWindowsProxySettingsProperties propsLogger l ) {
        String strkey          = "HKEY_CURRENT_USER";
        String strSub          = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
        String strProxyEnable  = "ProxyEnable";
        String strProxyServer  = "ProxyServer";
        String strProxyOverride"ProxyOverride";
        String strProxyScript  = "AutoConfigURL";
        props.remove(.);
        props.remove(.);
        props.remove(.);
        props.remove(.);
        try {
            Natives natives = new Natives();
            String strProxyEnableValue = natives.getRegistryKey(strkey,strSub,strProxyEnable);
            if(strProxyEnableValue!=null) {
                // String der L�nge 1 mit bin�rer 1 f�r true
                // String der L�nge 0 f�r false
                if(strProxyEnableValue.length()==1) {
                    int value = strProxyEnableValue.charAt(0);
                    props.put(., Boolean.toString(value!=0));
                } else {
                    props.put(., Boolean.toString(false));
                }
            }
            String strProxyValue = natives.getRegistryKeystrkeystrSubstrProxyServer );
            if(strProxyValue!=null && strProxyValue.trim().length() > 0) {
                int pos = strProxyValue.indexOf("=");
                if(pos<0) { // one entry for all protocols
                    StringTokenizer tok = new StringTokenizer(strProxyValue,":");
                    String valProxy = tok.nextToken();
                    props.put.valProxy );
                    props.put.valProxy );
                    if(tok.hasMoreTokens()) {
                        String valPort = tok.nextToken();
                        props.put.valPort );
                        props.put.valPort );
                    } else { // default port is 80 for http and https proxies
                        props.put."80" );
                        props.put."80" );
                    }
                } else { // different entrys per protocol
                    for(StringTokenizer ptok = new StringTokenizer(strProxyValue,";");ptok.hasMoreTokens();) {
                        String strProtocolProxyValue = ptok.nextToken();
                        StringTokenizer tok = new StringTokenizer(strProtocolProxyValue,"=:");
                        String valProtocol = tok.nextToken();
                        if("http".equals(valProtocol)) {
                            String valProxy = tok.nextToken();
                            props.put.valProxy );
                            if(tok.hasMoreTokens()) {
                                String valPort = tok.nextToken();
                                props.put.valPort );
                            } else { // default port is 80 for http proxy
                                props.put."80" );
                            }
                        } else if("https".equals(valProtocol)) {
                            String valProxy = tok.nextToken();
                            props.put.valProxy );
                            if(tok.hasMoreTokens()) {
                                String valPort = tok.nextToken();
                                props.put.valPort );
                            } else { // default port is 80 for https proxy
                                props.put."80" );
                            }
                        }
                    }
                }
            }
            String strProxyOverrideValue = natives.getRegistryKeystrkeystrSubstrProxyOverride );
            if(strProxyOverrideValue!=null) {
                props.put(.,strProxyOverrideValue);
            }
            String strProxyScriptValue = natives.getRegistryKey(strkeystrSubstrProxyScript);
            if(strProxyScriptValue!=null&&strProxyScriptValue.length()>0) {
                l.log(."automatic proxy script '"+strProxyScriptValue+"' not supported");
            }
        } catchException e) {
            l.log(.,"error loading proxy values: ",e);
        } catch (UnsatisfiedLinkError err) {
            l.log(.,"error loading proxy values: ",err);
        }
    }
New to GrepCode? Check out our FAQ X