OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [classpath/] [SystemProperties.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* SystemProperties.java -- Manage the System properties.
2
   Copyright (C) 2004, 2005 Free Software Foundation
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.classpath;
40
 
41
import java.util.Properties;
42
 
43
/**
44
 * The class manages the System properties. This class is only available to
45
 * privileged code (i.e. code loaded by the bootstrap class loader) and
46
 * therefore doesn't do any security checks.
47
 * This class is separated out from java.lang.System to simplify bootstrap
48
 * dependencies and to allow trusted code a simple and efficient mechanism
49
 * to access the system properties.
50
 */
51
public class SystemProperties
52
{
53
  /**
54
   * Stores the current system properties. This can be modified by
55
   * {@link #setProperties(Properties)}, but will never be null, because
56
   * setProperties(null) sucks in the default properties.
57
   */
58
  private static Properties properties;
59
 
60
  /**
61
   * The default properties. Once the default is stabilized,
62
   * it should not be modified;
63
   * instead it is cloned when calling <code>setProperties(null)</code>.
64
   */
65
  private static final Properties defaultProperties = new Properties();
66
 
67
  static
68
  {
69
    VMSystemProperties.preInit(defaultProperties);
70
 
71
    defaultProperties.put("gnu.classpath.home", Configuration.CLASSPATH_HOME);
72
    defaultProperties.put("gnu.classpath.version",
73
                          Configuration.CLASSPATH_VERSION);
74
 
75
    // Set base URL if not already set.
76
    if (defaultProperties.get("gnu.classpath.home.url") == null)
77
      defaultProperties.put("gnu.classpath.home.url",
78
                            "file://"
79
                            + Configuration.CLASSPATH_HOME
80
                            + "/lib");
81
 
82
    // Set short name if not already set.
83
    if (defaultProperties.get("gnu.classpath.vm.shortname") == null)
84
      {
85
        String value = defaultProperties.getProperty("java.vm.name");
86
        int index = value.lastIndexOf(' ');
87
        if (index != -1)
88
          value = value.substring(index + 1);
89
        defaultProperties.put("gnu.classpath.vm.shortname", value);
90
      }
91
 
92
    // Network properties
93
    if (defaultProperties.get("http.agent") == null)
94
      {
95
        String userAgent = ("gnu-classpath/"
96
                            + defaultProperties.getProperty("gnu.classpath.version")
97
                            + " ("
98
                            + defaultProperties.getProperty("gnu.classpath.vm.shortname")
99
                            + "/"
100
                            + defaultProperties.getProperty("java.vm.version")
101
                            + ")");
102
         defaultProperties.put("http.agent", userAgent);
103
      }
104
 
105
    // 8859_1 is a safe default encoding to use when not explicitly set
106
    if (defaultProperties.get("file.encoding") == null)
107
      defaultProperties.put("file.encoding", "8859_1");
108
 
109
    // XXX FIXME - Temp hack for old systems that set the wrong property
110
    if (defaultProperties.get("java.io.tmpdir") == null)
111
      defaultProperties.put("java.io.tmpdir",
112
                            defaultProperties.get("java.tmpdir"));
113
 
114
    // FIXME: we need a better way to handle this.
115
    // For instance, having a single VM class for each OS might help.
116
    if (defaultProperties.get("gnu.classpath.mime.types.file") == null
117
        && "Linux".equals(defaultProperties.get("os.name")))
118
      defaultProperties.put("gnu.classpath.mime.types.file",
119
                            "/etc/mime.types");
120
 
121
    VMSystemProperties.postInit(defaultProperties);
122
 
123
    // Note that we use clone here and not new.  Some programs assume
124
    // that the system properties do not have a parent.
125
    properties = (Properties) defaultProperties.clone();
126
  }
127
 
128
  public static String getProperty(String name)
129
  {
130
    return properties.getProperty(name);
131
  }
132
 
133
  public static String getProperty(String name, String defaultValue)
134
  {
135
    return properties.getProperty(name, defaultValue);
136
  }
137
 
138
  public static String setProperty(String name, String value)
139
  {
140
    return (String) properties.setProperty(name, value);
141
  }
142
 
143
  public static Properties getProperties()
144
  {
145
    return properties;
146
  }
147
 
148
  public static void setProperties(Properties properties)
149
  {
150
    if (properties == null)
151
      {
152
        // Note that we use clone here and not new.  Some programs
153
        // assume that the system properties do not have a parent.
154
        properties = (Properties)defaultProperties.clone();
155
      }
156
 
157
    SystemProperties.properties = properties;
158
  }
159
 
160
  /**
161
   * Removes the supplied system property and its current value.
162
   * If the specified property does not exist, nothing happens.
163
   *
164
   * @throws NullPointerException if the property name is null.
165
   * @return the value of the removed property, or null if no
166
   *         such property exists.
167
   */
168
  public static String remove(String name)
169
  {
170
    return (String) properties.remove(name);
171
  }
172
 
173
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.