Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/util/SystemProperties.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.util;
19  
20  import java.util.Properties;
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  /**
25   * Helper class for accessing System properties
26   *
27   * @version $Revision: 1.1.1.1 $
28   */
29  public class SystemProperties {
30      private static final Log log = LogFactory.getLog(SystemProperties.class);
31      private static final boolean canAccessSystemProperties;
32      private static final Properties defaultProperties = new Properties();
33      
34      
35      static {
36          SecurityManager securityManager = System.getSecurityManager();
37          boolean haveAccess = false;
38          if ( securityManager != null ){
39              try{
40                  securityManager.checkPropertiesAccess();
41                  haveAccess = true;
42              }catch(Throwable e){
43                  haveAccess = false;
44                  log.warn("Do not have access to System properties",e);
45              }
46          }
47          canAccessSystemProperties = haveAccess;
48      }
49          
50     /**
51      * @return System properties
52      */
53     public static Properties getSystemProperties(){
54         return canAccessSystemProperties ? System.getProperties() : defaultProperties;
55     }
56     
57     /**
58      * @return the default user name
59      */
60     public static String getUserName(){
61         return canAccessSystemProperties ? System.getProperty("user.name") : "defaultUser";
62     }
63  }