Java Code Examples for sun.misc.SharedSecrets#getJavaAWTAccess()

The following examples show how to use sun.misc.SharedSecrets#getJavaAWTAccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeZone.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the default TimeZone in an AppContext if any AppContext
 * has ever used. null is returned if any AppContext hasn't been
 * used or if the AppContext doesn't have the default TimeZone.
 * null is also returned if allowSetDefault is false.
 *
 * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
 * been loaded. If so, it implies that AWTSecurityManager is not our
 * SecurityManager and we can use a local static variable.
 * This works around a build time issue.
 */
private static TimeZone getDefaultInAppContext() {
    if (allowSetDefault) {
        // JavaAWTAccess provides access implementation-private methods without using reflection.
        JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
        if (System.getSecurityManager() == null || javaAWTAccess == null) {
            return mainAppContextDefault;
        } else if (javaAWTAccess.isDisposed()) {
            return null;
        } else {
            TimeZone tz = (TimeZone) javaAWTAccess.get(TimeZone.class);
            if (tz == null && javaAWTAccess.isMainAppContext()) {
                return mainAppContextDefault;
            } else {
                return tz;
            }
        }
    }
    return null;
}
 
Example 2
Source File: LogManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 3
Source File: LogManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 4
Source File: TimeZone.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the default TimeZone in the AppContext to the given tz if
 * allowSetDefault is true. null is handled special: do nothing if any
 * AppContext hasn't been used, remove the default TimeZone in the
 * AppContext otherwise.
 *
 * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
 * been loaded. If so, it implies that AWTSecurityManager is not our
 * SecurityManager and we can use a local static variable.
 * This works around a build time issue.
 */
private static void setDefaultInAppContext(TimeZone tz) {
    if (allowSetDefault) {
        // JavaAWTAccess provides access implementation-private methods without using reflection.
        JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
        if (System.getSecurityManager() == null || javaAWTAccess == null) {
            mainAppContextDefault = tz;
        } else if (!javaAWTAccess.isDisposed()) {
            javaAWTAccess.put(TimeZone.class, tz);
            if (javaAWTAccess.isMainAppContext()) {
                mainAppContextDefault = null;
            }
        }
    }
}
 
Example 5
Source File: LogManager.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        synchronized (javaAwtAccess) {
            // find the AppContext of the applet code
            // will be null if we are in the main app context.
            final Object ecx = javaAwtAccess.getAppletContext();
            if (ecx != null) {
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    // The new logger context has its requiresDefaultLoggers
                    // flag set to true - so that these loggers will be
                    // lazily added when the context is firt accessed.
                    context = new LoggerContext(true);
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 6
Source File: LogManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 7
Source File: LogManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 8
Source File: LogManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        synchronized (javaAwtAccess) {
            // find the AppContext of the applet code
            // will be null if we are in the main app context.
            final Object ecx = javaAwtAccess.getAppletContext();
            if (ecx != null) {
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 9
Source File: LogManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        synchronized (javaAwtAccess) {
            // find the AppContext of the applet code
            // will be null if we are in the main app context.
            final Object ecx = javaAwtAccess.getAppletContext();
            if (ecx != null) {
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 10
Source File: LogManager.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 11
Source File: LogManager.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 12
Source File: LogManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 13
Source File: LogManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 14
Source File: LogManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 15
Source File: LogManager.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 16
Source File: LogManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 17
Source File: LogManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}
 
Example 18
Source File: LogManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private LoggerContext getUserContext() {
    LoggerContext context = null;

    SecurityManager sm = System.getSecurityManager();
    JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess();
    if (sm != null && javaAwtAccess != null) {
        // for each applet, it has its own LoggerContext isolated from others
        final Object ecx = javaAwtAccess.getAppletContext();
        if (ecx != null) {
            synchronized (javaAwtAccess) {
                // find the AppContext of the applet code
                // will be null if we are in the main app context.
                if (contextsMap == null) {
                    contextsMap = new WeakHashMap<>();
                }
                context = contextsMap.get(ecx);
                if (context == null) {
                    // Create a new LoggerContext for the applet.
                    context = new LoggerContext();
                    contextsMap.put(ecx, context);
                }
            }
        }
    }
    // for standalone app, return userContext
    return context != null ? context : userContext;
}