Example usage for org.springframework.core.env ReadOnlySystemAttributesMap ReadOnlySystemAttributesMap

List of usage examples for org.springframework.core.env ReadOnlySystemAttributesMap ReadOnlySystemAttributesMap

Introduction

In this page you can find the example usage for org.springframework.core.env ReadOnlySystemAttributesMap ReadOnlySystemAttributesMap.

Prototype

ReadOnlySystemAttributesMap

Source Link

Usage

From source file:org.springframework.core.env.AbstractEnvironment.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> getSystemEnvironment() {
    if (suppressGetenvAccess()) {
        return Collections.emptyMap();
    }//w  ww .j  a  v  a2s .c o  m
    try {
        return (Map) System.getenv();
    } catch (AccessControlException ex) {
        return (Map) new ReadOnlySystemAttributesMap() {
            @Override
            @Nullable
            protected String getSystemAttribute(String attributeName) {
                try {
                    return System.getenv(attributeName);
                } catch (AccessControlException ex) {
                    if (logger.isInfoEnabled()) {
                        logger.info("Caught AccessControlException when accessing system environment variable '"
                                + attributeName + "'; its value will be returned [null]. Reason: "
                                + ex.getMessage());
                    }
                    return null;
                }
            }
        };
    }
}

From source file:org.springframework.core.env.AbstractEnvironment.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> getSystemProperties() {
    try {//from   w w w  .ja  v  a2s.co m
        return (Map) System.getProperties();
    } catch (AccessControlException ex) {
        return (Map) new ReadOnlySystemAttributesMap() {
            @Override
            @Nullable
            protected String getSystemAttribute(String attributeName) {
                try {
                    return System.getProperty(attributeName);
                } catch (AccessControlException ex) {
                    if (logger.isInfoEnabled()) {
                        logger.info(
                                "Caught AccessControlException when accessing system property '" + attributeName
                                        + "'; its value will be returned [null]. Reason: " + ex.getMessage());
                    }
                    return null;
                }
            }
        };
    }
}