/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.osgi.spi.util;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * Priviledged actions for the package
 * 
 * @author Scott.Stark@jboss.org
 */
@SuppressWarnings("rawtypes")
public class SysPropertyActions {

    interface SysProps {

        SysProps NON_PRIVILEDGED = new SysProps() {

            public String getProperty(final String name, final String defaultValue) {
                return System.getProperty(name, defaultValue);
            }
        };
        SysProps PRIVILEDGED = new SysProps() {

            @SuppressWarnings("unchecked")
            public String getProperty(final String name, final String defaultValue) {
                PrivilegedAction action = new PrivilegedAction() {

                    public Object run() {
                        return System.getProperty(name, defaultValue);
                    }
                };
                return (String) AccessController.doPrivileged(action);
            }
        };

        String getProperty(String name, String defaultValue);
    }

    public static String getProperty(String name, String defaultValue) {
        String prop;
        if (System.getSecurityManager() == null)
            prop = SysProps.NON_PRIVILEDGED.getProperty(name, defaultValue);
        else
            prop = SysProps.PRIVILEDGED.getProperty(name, defaultValue);
        return prop;
    }
}

@@ -1118,16 +1118,45 @@
 dAction;
+%0Aimport java.util.Properties;
 %0A%0A/**%0A *
@@ -1235,39 +1235,37 @@
 g%0A *
-/%0A@SuppressWarnings(%22rawtypes%22)
+ @author David Bosschaert%0A */
 %0Apub
@@ -1366,33 +1366,32 @@
 ew SysProps() %7B%0A
-%0A
             publ
@@ -1528,32 +1528,142 @@
 );%0A            %7D
+%0A%0A            public Properties getProperties() %7B%0A                return System.getProperties();%0A            %7D
 %0A        %7D;%0A    
@@ -1650,32 +1650,33 @@
    %7D%0A        %7D;%0A
+%0A
         SysProps
@@ -1710,52 +1710,8 @@
 () %7B
-%0A%0A            @SuppressWarnings(%22unchecked%22)
 %0A   
@@ -1825,16 +1825,24 @@
 edAction
+%3CString%3E
  action 
@@ -1863,16 +1863,24 @@
 edAction
+%3CString%3E
 () %7B%0A%0A  
@@ -1908,14 +1908,14 @@
 lic 
-Object
+String
  run
@@ -2058,16 +2058,395 @@
 urn 
-(String)
+AccessController.doPrivileged(action);%0A            %7D%0A%0A            public Properties getProperties() %7B%0A                PrivilegedAction%3CProperties%3E action = new PrivilegedAction%3CProperties%3E() %7B%0A                    @Override%0A                    public Properties run() %7B%0A                        return System.getProperties();%0A                    %7D%0A                %7D;%0A                return
  Acc
@@ -2564,24 +2564,61 @@
 faultValue);
+%0A%0A        Properties getProperties();
 %0A    %7D%0A%0A    
@@ -2945,11 +2945,245 @@
 p;%0A    %7D
+%0A%0A    public static Properties getProperties() %7B%0A        if (System.getSecurityManager() == null)%0A            return SysProps.NON_PRIVILEDGED.getProperties();%0A        else%0A            return SysProps.PRIVILEDGED.getProperties();%0A    %7D
 %0A%7D%0A

Enhance SysPropertyActions to allow System.getProperties()