/[classpath]/classpath/gnu/classpath/SystemProperties.java
ViewVC logotype

Diff of /classpath/gnu/classpath/SystemProperties.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by smarothy, Tue Apr 19 19:55:23 2005 UTC revision 1.7 by mkoch, Fri Apr 22 07:33:15 2005 UTC
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    
39  package gnu.classpath;  package gnu.classpath;
40    
41  import java.util.Properties;  import java.util.Properties;
# Line 49  import java.util.Properties; Line 50  import java.util.Properties;
50   */   */
51  public class SystemProperties  public class SystemProperties
52  {  {
53      /**    /**
54       * Stores the current system properties. This can be modified by     * Stores the current system properties. This can be modified by
55       * {@link #setProperties(Properties)}, but will never be null, because     * {@link #setProperties(Properties)}, but will never be null, because
56       * setProperties(null) sucks in the default properties.     * setProperties(null) sucks in the default properties.
57       */     */
58      private static Properties properties;    private static Properties properties;
59    
60      /**    /**
61       * The default properties. Once the default is stabilized,     * The default properties. Once the default is stabilized,
62       * it should not be modified;     * it should not be modified;
63       * instead it is cloned when calling <code>setProperties(null)</code>.     * instead it is cloned when calling <code>setProperties(null)</code>.
64       */     */
65      private static final Properties defaultProperties = new Properties();    private static final Properties defaultProperties = new Properties();
66    
67      static    static
68      {    {
69          VMSystemProperties.preInit(defaultProperties);      VMSystemProperties.preInit(defaultProperties);
70    
71          defaultProperties.put("gnu.classpath.home",      defaultProperties.put("gnu.classpath.home", Configuration.CLASSPATH_HOME);
72              Configuration.CLASSPATH_HOME);      defaultProperties.put("gnu.classpath.version",
73          defaultProperties.put("gnu.classpath.version",                            Configuration.CLASSPATH_VERSION);
74              Configuration.CLASSPATH_VERSION);  
75        // Set base URL if not already set.
76          // Set base URL if not already set.      if (defaultProperties.get("gnu.classpath.home.url") == null)
77          if (defaultProperties.get("gnu.classpath.home.url") == null)        defaultProperties.put("gnu.classpath.home.url",
78              defaultProperties.put("gnu.classpath.home.url",                              "file://"
79                  "file://" + Configuration.CLASSPATH_HOME + "/lib");                              + Configuration.CLASSPATH_HOME
80                                + "/lib");
81          // Set short name if not already set.  
82          if (defaultProperties.get("gnu.classpath.vm.shortname") == null)      // Set short name if not already set.
83          {      if (defaultProperties.get("gnu.classpath.vm.shortname") == null)
84              String value = defaultProperties.getProperty("java.vm.name");        {
85              int index = value.lastIndexOf(' ');          String value = defaultProperties.getProperty("java.vm.name");
86              if (index != -1)          int index = value.lastIndexOf(' ');
87                  value = value.substring(index + 1);          if (index != -1)
88              defaultProperties.put("gnu.classpath.vm.shortname", value);            value = value.substring(index + 1);
89          }          defaultProperties.put("gnu.classpath.vm.shortname", value);
90          }
91          // Network properties  
92          if (defaultProperties.get("http.agent") == null)      // Network properties
93          {      if (defaultProperties.get("http.agent") == null)
94              String userAgent        {
95                  = ("gnu-classpath/"          String userAgent = ("gnu-classpath/"
96                  + defaultProperties.getProperty("gnu.classpath.version")                              + defaultProperties.getProperty("gnu.classpath.version")
97                  + " ("                              + " ("
98                  + defaultProperties.getProperty("gnu.classpath.vm.shortname")                              + defaultProperties.getProperty("gnu.classpath.vm.shortname")
99                  + "/"                              + "/"
100                  + defaultProperties.getProperty("java.vm.version")                              + defaultProperties.getProperty("java.vm.version")
101                  + ")");                              + ")");
102              defaultProperties.put("http.agent", userAgent);           defaultProperties.put("http.agent", userAgent);
103          }        }
104    
105          // 8859_1 is a safe default encoding to use when not explicitly set      // 8859_1 is a safe default encoding to use when not explicitly set
106          if (defaultProperties.get("file.encoding") == null)      if (defaultProperties.get("file.encoding") == null)
107              defaultProperties.put("file.encoding", "8859_1");        defaultProperties.put("file.encoding", "8859_1");
108    
109          // XXX FIXME - Temp hack for old systems that set the wrong property      // XXX FIXME - Temp hack for old systems that set the wrong property
110          if (defaultProperties.get("java.io.tmpdir") == null)      if (defaultProperties.get("java.io.tmpdir") == null)
111              defaultProperties.put("java.io.tmpdir",        defaultProperties.put("java.io.tmpdir",
112                  defaultProperties.get("java.tmpdir"));                              defaultProperties.get("java.tmpdir"));
113    
114          VMSystemProperties.postInit(defaultProperties);      VMSystemProperties.postInit(defaultProperties);
115    
116          // Note that we use clone here and not new.  Some programs assume      // Note that we use clone here and not new.  Some programs assume
117          // that the system properties do not have a parent.      // that the system properties do not have a parent.
118        properties = (Properties) defaultProperties.clone();
119      }
120    
121      public static String getProperty(String name)
122      {
123        return properties.getProperty(name);
124      }
125    
126      public static String getProperty(String name, String defaultValue)
127      {
128        return properties.getProperty(name, defaultValue);
129      }
130    
131      public static String setProperty(String name, String value)
132      {
133        return (String) properties.setProperty(name, value);
134      }
135    
136      public static Properties getProperties()
137      {
138        return properties;
139      }
140    
141      public static void setProperties(Properties properties)
142      {
143        if (properties == null)
144          {
145            // Note that we use clone here and not new.  Some programs
146            // assume that the system properties do not have a parent.
147          properties = (Properties)defaultProperties.clone();          properties = (Properties)defaultProperties.clone();
148      }        }
   
     public static String getProperty(String name)  
     {  
         return properties.getProperty(name);  
     }  
   
     public static String getProperty(String name, String defaultValue)  
     {  
         return properties.getProperty(name, defaultValue);  
     }  
   
     public static String setProperty(String name, String value)  
     {  
         return (String)properties.setProperty(name, value);  
     }  
   
     public static Properties getProperties()  
     {  
         return properties;  
     }  
   
     public static void setProperties(Properties properties)  
     {  
         if (properties == null)  
           {  
             // Note that we use clone here and not new.  Some programs  
             // assume that the system properties do not have a parent.  
             properties = (Properties)defaultProperties.clone();  
           }  
149    
150          SystemProperties.properties = properties;      SystemProperties.properties = properties;
151      }    }
152  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26