src/share/classes/java/util/TimeZone.java

Print this page




 711                 setDefaultInAppContext(null);
 712             }
 713         } else {
 714             setDefaultInAppContext(zone);
 715         }
 716     }
 717 
 718     /**
 719      * Returns the default TimeZone in an AppContext if any AppContext
 720      * has ever used. null is returned if any AppContext hasn't been
 721      * used or if the AppContext doesn't have the default TimeZone.
 722      *
 723      * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
 724      * been loaded. If so, it implies that AWTSecurityManager is not our
 725      * SecurityManager and we can use a local static variable.
 726      * This works around a build time issue.
 727      */
 728     private static TimeZone getDefaultInAppContext() {
 729         // JavaAWTAccess provides access implementation-private methods without using reflection.
 730         JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
 731         if (javaAWTAccess == null) {
 732             return mainAppContextDefault;


 733         } else {
 734             if (!javaAWTAccess.isDisposed()) {
 735                 TimeZone tz = (TimeZone)
 736                     javaAWTAccess.get(TimeZone.class);
 737                 if (tz == null && javaAWTAccess.isMainAppContext()) {
 738                     return mainAppContextDefault;
 739                 } else {
 740                     return tz;
 741                 }
 742             }
 743         }
 744         return null;
 745     }
 746 
 747     /**
 748      * Sets the default TimeZone in the AppContext to the given
 749      * tz. null is handled special: do nothing if any AppContext
 750      * hasn't been used, remove the default TimeZone in the
 751      * AppContext otherwise.
 752      *
 753      * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
 754      * been loaded. If so, it implies that AWTSecurityManager is not our
 755      * SecurityManager and we can use a local static variable.
 756      * This works around a build time issue.
 757      */
 758     private static void setDefaultInAppContext(TimeZone tz) {
 759         // JavaAWTAccess provides access implementation-private methods without using reflection.
 760         JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
 761         if (javaAWTAccess == null) {
 762             mainAppContextDefault = tz;
 763         } else {
 764             if (!javaAWTAccess.isDisposed()) {
 765                 javaAWTAccess.put(TimeZone.class, tz);
 766                 if (javaAWTAccess.isMainAppContext()) {
 767                     mainAppContextDefault = null;
 768                 }
 769             }
 770         }
 771     }
 772 
 773     /**
 774      * Returns true if this zone has the same rule and offset as another zone.
 775      * That is, if this zone differs only in ID, if at all.  Returns false
 776      * if the other zone is null.
 777      * @param other the <code>TimeZone</code> object to be compared with
 778      * @return true if the other zone is not null and is the same as this one,
 779      * with the possible exception of the ID
 780      * @since 1.2
 781      */
 782     public boolean hasSameRules(TimeZone other) {
 783         return other != null && getRawOffset() == other.getRawOffset() &&
 784             useDaylightTime() == other.useDaylightTime();
 785     }
 786 
 787     /**
 788      * Creates a copy of this <code>TimeZone</code>.
 789      *
 790      * @return a clone of this <code>TimeZone</code>




 711                 setDefaultInAppContext(null);
 712             }
 713         } else {
 714             setDefaultInAppContext(zone);
 715         }
 716     }
 717 
 718     /**
 719      * Returns the default TimeZone in an AppContext if any AppContext
 720      * has ever used. null is returned if any AppContext hasn't been
 721      * used or if the AppContext doesn't have the default TimeZone.
 722      *
 723      * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
 724      * been loaded. If so, it implies that AWTSecurityManager is not our
 725      * SecurityManager and we can use a local static variable.
 726      * This works around a build time issue.
 727      */
 728     private static TimeZone getDefaultInAppContext() {
 729         // JavaAWTAccess provides access implementation-private methods without using reflection.
 730         JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
 731         if (System.getSecurityManager() == null || javaAWTAccess == null) {
 732             return mainAppContextDefault;
 733         } else if (javaAWTAccess.isDisposed()) {
 734             return null;
 735         } else {
 736             TimeZone tz = (TimeZone) javaAWTAccess.get(TimeZone.class);


 737             if (tz == null && javaAWTAccess.isMainAppContext()) {
 738                 return mainAppContextDefault;
 739             } else {
 740                 return tz;
 741             }
 742         }
 743     }


 744 
 745     /**
 746      * Sets the default TimeZone in the AppContext to the given
 747      * tz. null is handled special: do nothing if any AppContext
 748      * hasn't been used, remove the default TimeZone in the
 749      * AppContext otherwise.
 750      *
 751      * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
 752      * been loaded. If so, it implies that AWTSecurityManager is not our
 753      * SecurityManager and we can use a local static variable.
 754      * This works around a build time issue.
 755      */
 756     private static void setDefaultInAppContext(TimeZone tz) {
 757         // JavaAWTAccess provides access implementation-private methods without using reflection.
 758         JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
 759         if (System.getSecurityManager() == null || javaAWTAccess == null) {
 760             mainAppContextDefault = tz;
 761         } else if (!javaAWTAccess.isDisposed()) {

 762             javaAWTAccess.put(TimeZone.class, tz);
 763             if (javaAWTAccess.isMainAppContext()) {
 764                 mainAppContextDefault = null;
 765             }
 766         }

 767     }
 768 
 769     /**
 770      * Returns true if this zone has the same rule and offset as another zone.
 771      * That is, if this zone differs only in ID, if at all.  Returns false
 772      * if the other zone is null.
 773      * @param other the <code>TimeZone</code> object to be compared with
 774      * @return true if the other zone is not null and is the same as this one,
 775      * with the possible exception of the ID
 776      * @since 1.2
 777      */
 778     public boolean hasSameRules(TimeZone other) {
 779         return other != null && getRawOffset() == other.getRawOffset() &&
 780             useDaylightTime() == other.useDaylightTime();
 781     }
 782 
 783     /**
 784      * Creates a copy of this <code>TimeZone</code>.
 785      *
 786      * @return a clone of this <code>TimeZone</code>